def test_02_classification_required(self): # Check we can mark an application 'ready' with a subject classification present in_progress_application = models.Suggestion(**ApplicationFixtureFactory.make_update_request_source()) in_progress_application.set_application_status(constants.APPLICATION_STATUS_IN_PROGRESS) fc = formcontext.ApplicationFormFactory.get_form_context(role='editor', source=in_progress_application) # Make changes to the application status via the form, check it validates fc.form.application_status.data = constants.APPLICATION_STATUS_READY assert fc.validate() # Without a subject classification, we should not be able to set the status to 'ready' no_class_application = models.Suggestion(**ApplicationFixtureFactory.make_update_request_source()) del no_class_application.data['bibjson']['subject'] fc = formcontext.ApplicationFormFactory.get_form_context(role='editor', source=no_class_application) # Make changes to the application status via the form assert fc.source.bibjson().subjects() == [] fc.form.application_status.data = constants.APPLICATION_STATUS_READY assert not fc.validate() # However, we should be able to set it to a different status rather than 'ready' fc.form.application_status.data = constants.APPLICATION_STATUS_PENDING assert fc.validate()
def test_09_publisher_result_filter_unpacked(self): apsrc_admin = ApplicationFixtureFactory.make_update_request_source( )['admin'] # Not all of these properties are applicable to applications, but these test objects are not applications: # they are made-up admin sections designed solely to test whether the filter lets the right keys through. # We just use applications as a base to construct them. apsrc_admin['ticked'] = True apsrc_admin['in_doaj'] = True apsrc_admin['related_applications'] = [1, 2, 3] apsrc_admin['current_application'] = 'abcde' allowed = [ "ticked", "seal", "in_doaj", "related_applications", "current_application", "current_journal", "application_status" ] forbidden = [ 'notes', 'contact', 'editor_group', 'editor', 'related_journal' ] res = {"admin": deepcopy(apsrc_admin), "bibjson": {}} newres = query_filters.publisher_result_filter(res, unpacked=True) for allowed_k in allowed: assert allowed_k in newres['admin'], \ '{} key not found in result {}, but it is allowed and should have been left intact by the filter'.format(allowed_k, newres) for forbidden_k in forbidden: assert forbidden_k not in newres['admin'], \ '{} key was found in result {}, but it is forbidden and should have been stripped out by the filter'.format(forbidden_k, newres)
def test_06_retrieve_application_success(self): # set up all the bits we need data = ApplicationFixtureFactory.make_update_request_source() ap = models.Suggestion(**data) ap.save() time.sleep(2) account = models.Account() account.set_id(ap.owner) account.set_name("Tester") account.set_email("*****@*****.**") # call retrieve on the object a = ApplicationsCrudApi.retrieve(ap.id, account) # check that we got back the object we expected assert isinstance(a, OutgoingApplication) assert a.id == ap.id
def test_05_outgoing_application_do(self): # make a blank one oa = OutgoingApplication() # make one from an incoming application model fixture data = ApplicationFixtureFactory.make_update_request_source() ap = models.Suggestion(**data) oa = OutgoingApplication.from_model(ap) # check that it does not contain information that it shouldn't assert oa.data.get("index") is None assert oa.data.get("history") is None assert oa.data.get("admin", {}).get("notes") is None assert oa.data.get("admin", {}).get("editor_group") is None assert oa.data.get("admin", {}).get("editor") is None assert oa.data.get("admin", {}).get("seal") is None assert oa.data.get("admin", {}).get("related_journal") is None # check that it does contain admin information that it should assert oa.data.get("admin", {}).get("current_journal") is not None
def test_07_retrieve_application_fail(self): # set up all the bits we need data = ApplicationFixtureFactory.make_update_request_source() ap = models.Suggestion(**data) ap.save() time.sleep(2) # no user with self.assertRaises(Api401Error): a = ApplicationsCrudApi.retrieve(ap.id, None) # wrong user account = models.Account() account.set_id("asdklfjaioefwe") with self.assertRaises(Api404Error): a = ApplicationsCrudApi.retrieve(ap.id, account) # non-existant application account = models.Account() account.set_id(ap.id) with self.assertRaises(Api404Error): a = ApplicationsCrudApi.retrieve("ijsidfawefwefw", account)
from portality.formcontext import forms from portality.formcontext.xwalks import suggestion_form from portality import models from werkzeug.datastructures import MultiDict from copy import deepcopy from portality import lcc from doajtest.fixtures import JournalFixtureFactory, ApplicationFixtureFactory JOURNAL_FORM = JournalFixtureFactory.make_journal_form() JOURNAL_FORMINFO = JournalFixtureFactory.make_journal_form_info() JOURNAL_SOURCE = JournalFixtureFactory.make_journal_source_with_legacy_info() APPLICATION_FORM = ApplicationFixtureFactory.make_application_form() APPLICATION_FORMINFO = ApplicationFixtureFactory.make_application_form_info() APPLICATION_SOURCE = ApplicationFixtureFactory.make_update_request_source() OLD_STYLE_APP = ApplicationFixtureFactory.make_update_request_source() del OLD_STYLE_APP["bibjson"]["persistent_identifier_scheme"] del OLD_STYLE_APP["bibjson"]["deposit_policy"] del OLD_STYLE_APP["bibjson"]["author_copyright"] del OLD_STYLE_APP["bibjson"]["author_publishing_rights"] ###################################################################### # Mocks ###################################################################### def mock_lookup_code(code): if code == "H": return "Social Sciences" if code == "HB1-3840": return "Economic theory. Demography"
import re from copy import deepcopy from werkzeug.datastructures import MultiDict from portality import constants from doajtest.fixtures import JournalFixtureFactory, ApplicationFixtureFactory from doajtest.helpers import DoajTestCase from portality import models from portality.formcontext import formcontext ##################################################################### # Source objects to be used for testing ##################################################################### UPDATE_REQUEST_SOURCE = ApplicationFixtureFactory.make_update_request_source() UPDATE_REQUEST_SOURCE["admin"][ "application_status"] = constants.APPLICATION_STATUS_UPDATE_REQUEST UPDATE_REQUEST_FORM = ApplicationFixtureFactory.make_application_form( role="publisher") ###################################################### # Main test class ###################################################### class TestPublisherUpdateRequestFormContext(DoajTestCase): def setUp(self): super(TestPublisherUpdateRequestFormContext, self).setUp() def tearDown(self):
def test_01_accept_application(self, name, application_type, account_type, manual_update, provenance, raises, result_provenance, result_manual_update): ############################################### ## set up # create the application application = None if application_type == "save_fail": application = Suggestion(**ApplicationFixtureFactory.make_update_request_source()) application.save = mock_save Journal.save = mock_save elif application_type == "with_current_journal": application = Suggestion(**ApplicationFixtureFactory.make_update_request_source()) application.remove_notes() application.add_note("unique 1", "2002-01-01T00:00:00Z") application.add_note("duplicate", "2001-01-01T00:00:00Z") cj = application.current_journal journal = Journal(**JournalFixtureFactory.make_journal_source()) journal.set_id(cj) journal.remove_notes() journal.add_note("unique 2", "2003-01-01T00:00:00Z") journal.add_note("duplicate", "2001-01-01T00:00:00Z") journal.save(blocking=True) elif application_type == "no_current_journal": application = Suggestion(**ApplicationFixtureFactory.make_update_request_source()) application.remove_current_journal() acc = None if account_type == "not_allowed": acc = Account(**AccountFixtureFactory.make_publisher_source()) elif account_type == "allowed": acc = Account(**AccountFixtureFactory.make_managing_editor_source()) mu = None if manual_update in ["true", "false"]: mu = manual_update == "true" prov = None if provenance in ["true", "false"]: prov = provenance == "true" save = bool(randint(0,1)) ########################################################### # Execution svc = DOAJ.applicationService() if raises != "": with self.assertRaises(EXCEPTIONS[raises]): svc.accept_application(application, acc, mu, prov) else: journal = svc.accept_application(application, acc, mu, prov, save_journal=save, save_application=save) # we need to sleep, so the index catches up time.sleep(1) # check a few common things assert application.application_status == constants.APPLICATION_STATUS_ACCEPTED assert application.current_journal is None assert journal.current_application is None assert application.related_journal == journal.id related = journal.related_applications if application_type == "with_current_journal": assert len(related) == 3 elif application_type == "no_current_journal": assert len(related) == 1 assert related[0].get("application_id") == application.id assert related[0].get("date_accepted") is not None if result_manual_update == "yes": assert journal.last_manual_update is not None assert journal.last_manual_update != "1970-01-01T00:00:00Z" assert application.last_manual_update is not None assert application.last_manual_update != "1970-01-01T00:00:00Z" elif result_manual_update == "no": assert journal.last_manual_update is None assert application.last_manual_update is None if application_type == "with_current_journal": assert len(journal.notes) == 3 notevals = [note.get("note") for note in journal.notes] assert "duplicate" in notevals assert "unique 1" in notevals assert "unique 2" in notevals app_prov = Provenance.get_latest_by_resource_id(application.id) if result_provenance == "yes": assert app_prov is not None elif result_provenance == "no": assert app_prov is None if save: pass