-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/3672 autocheck none value #2362
base: develop
Are you sure you want to change the base?
Changes from 8 commits
0bb316c
753887c
672b3f6
a66a213
3e21830
8df206f
08018fb
e150da8
4f09e81
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
from doajtest.fixtures import ApplicationFixtureFactory | ||
from doajtest.helpers import DoajTestCase | ||
from portality import models | ||
from portality.autocheck.checkers import no_none_value | ||
from portality.autocheck.checkers.no_none_value import NoNoneValue | ||
from portality.autocheck.resource_bundle import ResourceBundle | ||
from portality.crosswalks.application_form import ApplicationFormXWalk | ||
from portality.models import JournalLikeObject | ||
|
||
|
||
def run_check(checker, form: dict, jla: JournalLikeObject, resources=None): | ||
if resources is None: | ||
resources = ResourceBundle() | ||
|
||
autochecks = models.Autocheck() | ||
checker.check(form, jla, autochecks, resources, logger=print) | ||
return autochecks | ||
|
||
|
||
def fixture_standard_application(modify_fn=None): | ||
source = ApplicationFixtureFactory.make_application_source() | ||
app = models.Application(**source) | ||
modify_fn and modify_fn(app) | ||
form = ApplicationFormXWalk.obj2form(app) | ||
return form, app | ||
|
||
|
||
class TestNoNoneValue(DoajTestCase): | ||
|
||
def test_check__pass(self): | ||
form, app = fixture_standard_application() | ||
autochecks = run_check(NoNoneValue(), form, app) | ||
assert len(autochecks.checks) == 0 | ||
|
||
def test_check__fail_all(self): | ||
def modify_fn(app): | ||
bibjson = app.bibjson() | ||
bibjson.preservation["national_library"] = ['None'] | ||
bibjson.preservation["service"] = ['None'] | ||
bibjson.deposit_policy = ['None'] | ||
bibjson.persistent_identifier_scheme = ['None'] | ||
|
||
form, app = fixture_standard_application(modify_fn) | ||
|
||
autochecks = run_check(NoNoneValue(), form, app) | ||
assert len(autochecks.checks) == 4 | ||
|
||
for check in autochecks.checks: | ||
print(check) | ||
assert check['checked_by'] == NoNoneValue.__identity__ | ||
assert check['advice'] == no_none_value.ADVICE_NONE_VALUE_FOUND | ||
|
||
def test_check__fail_library(self): | ||
def modify_fn(app): | ||
bibjson = app.bibjson() | ||
bibjson.preservation["national_library"] = ['aaa', 'None'] | ||
|
||
form, app = fixture_standard_application(modify_fn) | ||
autochecks = run_check(NoNoneValue(), form, app) | ||
assert len(autochecks.checks) == 1 | ||
assert autochecks.checks[0]['field'] == 'preservation_service_library' | ||
|
||
def test_check__fail_deposit(self): | ||
def modify_fn(app): | ||
bibjson = app.bibjson() | ||
bibjson.deposit_policy = ['None'] | ||
|
||
form, app = fixture_standard_application(modify_fn) | ||
autochecks = run_check(NoNoneValue(), form, app) | ||
assert len(autochecks.checks) == 1 | ||
assert autochecks.checks[0]['field'] == 'deposit_policy_other' | ||
assert autochecks.checks[0]['original_value'] == 'None' | ||
|
||
def test_check__pass_deposit(self): | ||
def modify_fn(app): | ||
bibjson = app.bibjson() | ||
bibjson.deposit_policy = ['aa', 'None'] | ||
|
||
form, app = fixture_standard_application(modify_fn) | ||
autochecks = run_check(NoNoneValue(), form, app) | ||
assert len(autochecks.checks) == 0 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
from typing import Callable | ||
|
||
from portality.autocheck.checker import Checker | ||
from portality.autocheck.resource_bundle import ResourceBundle | ||
from portality.models import JournalLikeObject, Autocheck | ||
|
||
ADVICE_NONE_VALUE_FOUND = 'none_value_found' | ||
|
||
|
||
class NoNoneValue(Checker): | ||
__identity__ = "no_none_value" | ||
|
||
def check(self, form: dict, jla: JournalLikeObject, autochecks: Autocheck, | ||
resources: ResourceBundle, logger: Callable): | ||
fields = [ | ||
'preservation_service_library', | ||
'preservation_service_other', | ||
'deposit_policy_other', | ||
'persistent_identifiers_other', | ||
] | ||
|
||
for field in fields: | ||
if field not in form: | ||
logger(f'Field {field} not found in form') | ||
continue | ||
|
||
value = form.get(field) | ||
|
||
if ( | ||
(isinstance(value, str) and value.strip() == 'None') or | ||
(isinstance(value, list) and any([v.strip() == 'None' for v in value])) | ||
): | ||
autochecks.add_check( | ||
field=field, | ||
original_value=value, | ||
advice=ADVICE_NONE_VALUE_FOUND, | ||
checked_by=self.__identity__, | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1318,7 +1318,16 @@ class FieldDefinitions: | |
], | ||
"attr": { | ||
"class": "input-xlarge unstyled-list" | ||
} | ||
}, | ||
"contexts": { | ||
"admin": { | ||
"widgets": [ | ||
"autocheck", # ~~^-> Autocheck:FormWidget~~ | ||
"trim_whitespace", # ~~^-> TrimWhitespace:FormWidget~~ | ||
"multiple_field", | ||
] | ||
} | ||
}, | ||
} | ||
|
||
# ~~->$ PreservationServiceOther:FormField~~ | ||
|
@@ -1337,7 +1346,15 @@ class FieldDefinitions: | |
], | ||
"widgets" : [ | ||
"trim_whitespace" # ~~^-> TrimWhitespace:FormWidget~~ | ||
] | ||
], | ||
"contexts": { | ||
"admin": { | ||
"widgets": [ | ||
"autocheck", # ~~^-> Autocheck:FormWidget~~ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comment as above |
||
"trim_whitespace", # ~~^-> TrimWhitespace:FormWidget~~ | ||
] | ||
} | ||
}, | ||
} | ||
|
||
# ~~->$ PreservationServiceURL:FormField~~ | ||
|
@@ -1434,7 +1451,15 @@ class FieldDefinitions: | |
], | ||
"widgets" : [ | ||
"trim_whitespace" # ~~^-> TrimWhitespace:FormWidget~~ | ||
] | ||
], | ||
"contexts": { | ||
"admin": { | ||
"widgets": [ | ||
"autocheck", # ~~^-> Autocheck:FormWidget~~ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comment as above |
||
"trim_whitespace", # ~~^-> TrimWhitespace:FormWidget~~ | ||
] | ||
} | ||
}, | ||
} | ||
|
||
# ~~->$ DepositPolicyURL:FormField~~ | ||
|
@@ -1539,7 +1564,15 @@ class FieldDefinitions: | |
], | ||
"widgets" : [ | ||
"trim_whitespace" # ~~^-> TrimWhitespace:FormWidget~~ | ||
] | ||
], | ||
"contexts": { | ||
"admin": { | ||
"widgets": [ | ||
"autocheck", # ~~^-> Autocheck:FormWidget~~ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comment as above |
||
"trim_whitespace", # ~~^-> TrimWhitespace:FormWidget~~ | ||
] | ||
} | ||
}, | ||
} | ||
|
||
# ~~->$ Orcids:FormField~~ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
context
fields overwrite the base fields, so in this case this would remove thetrim_whitespace
andmultiple_field
widgets, and replace them with just theautocheck
field. Instead, this should list all 3 required widgets.