def test_14_create_application_update_request_fail(self): data = ApplicationFixtureFactory.incoming_application() journal = models.Journal(**JournalFixtureFactory.make_journal_source( in_doaj=True)) journal.bibjson().remove_identifiers() journal.bibjson().add_identifier(journal.bibjson().E_ISSN, "9999-8888") journal.bibjson().add_identifier(journal.bibjson().P_ISSN, "7777-6666") journal.bibjson().title = "not changed" journal.set_id(data["admin"]["current_journal"]) journal.set_owner("test") journal.save(blocking=True) # if the account is dud with self.assertRaises(Api401Error): a = ApplicationsCrudApi.create(data, None) # if the data is bust with self.assertRaises(Api400Error): account = models.Account() account.set_id("test") account.set_name("Tester") account.set_email("*****@*****.**") data = {"some": {"junk": "data"}} a = ApplicationsCrudApi.create(data, account)
def test_03b_create_update_request_fail(self): # update request target not found with self.assertRaises(Api404Error): data = ApplicationFixtureFactory.incoming_application() publisher = models.Account( **AccountFixtureFactory.make_publisher_source()) try: a = ApplicationsCrudApi.create(data, publisher) except Api404Error as e: raise # if a formcontext exception is raised on finalise publisher = models.Account( **AccountFixtureFactory.make_publisher_source()) journal = models.Journal(**JournalFixtureFactory.make_journal_source( in_doaj=True)) journal.set_id(journal.makeid()) journal.set_owner(publisher.id) journal.save(blocking=True) formcontext.FormContext.finalise = mock_finalise_exception with self.assertRaises(Api400Error): data = ApplicationFixtureFactory.incoming_application() data["admin"]["current_journal"] = journal.id try: a = ApplicationsCrudApi.create(data, publisher) except Api400Error as e: assert str(e) == "test exception" raise formcontext.FormContext.finalise = self.old_finalise # validation fails on the formcontext publisher = models.Account( **AccountFixtureFactory.make_publisher_source()) journal = models.Journal(**JournalFixtureFactory.make_journal_source( in_doaj=True)) journal.set_id(journal.makeid()) journal.set_owner(publisher.id) journal.save(blocking=True) IncomingApplication.custom_validate = mock_custom_validate_always_pass with self.assertRaises(Api400Error): data = ApplicationFixtureFactory.incoming_application() # duff submission charges url should trip the validator data["bibjson"]["submission_charges_url"] = "not a url!" data["admin"]["current_journal"] = journal.id try: a = ApplicationsCrudApi.create(data, publisher) except Api400Error as e: raise
def test_13_create_application_update_request_success(self): # set up all the bits we need data = ApplicationFixtureFactory.incoming_application() account = models.Account() account.set_id("test") account.set_name("Tester") account.set_email("*****@*****.**") account.add_role("publisher") account.save(blocking=True) journal = models.Journal(**JournalFixtureFactory.make_journal_source( in_doaj=True)) journal.bibjson().remove_identifiers() journal.bibjson().add_identifier(journal.bibjson().E_ISSN, "9999-8888") journal.bibjson().add_identifier(journal.bibjson().P_ISSN, "7777-6666") journal.bibjson().title = "not changed" journal.set_id(data["admin"]["current_journal"]) journal.set_owner(account.id) journal.save(blocking=True) # call create on the object (which will save it to the index) a = ApplicationsCrudApi.create(data, account) # check that it got created with the right properties assert isinstance(a, models.Suggestion) assert a.id != "ignore_me" assert a.created_date != "2001-01-01T00:00:00Z" assert a.last_updated != "2001-01-01T00:00:00Z" assert a.suggester.get( "name" ) == "Tester" # The suggester should be the owner of the existing journal assert a.suggester.get("email") == "*****@*****.**" assert a.owner == "test" assert a.suggested_on is not None assert a.bibjson().issns() == [ "9999-8888", "7777-6666" ] or a.bibjson().issns() == ["7777-6666", "9999-8888"] assert a.bibjson().title == "not changed" # also, because it's a special case, check the archiving_policy archiving_policy = a.bibjson().archiving_policy assert len(archiving_policy.get("policy")) == 4 lcount = 0 scount = 0 for ap in archiving_policy.get("policy"): if isinstance(ap, list): lcount += 1 assert ap[0] in ["A national library", "Other"] assert ap[1] in ["Trinity", "A safe place"] else: scount += 1 assert lcount == 2 assert scount == 2 assert "CLOCKSS" in archiving_policy.get("policy") assert "LOCKSS" in archiving_policy.get("policy") time.sleep(2) s = models.Suggestion.pull(a.id) assert s is not None
def test_02a_create_application_success_variations(self): # set up all the bits we need data = ApplicationFixtureFactory.incoming_application() del data["admin"]["current_journal"] account = models.Account() account.set_id("test") account.set_name("Tester") account.set_email("*****@*****.**") # try with only one issn data["bibjson"]["identifier"] = [ { "type" : "pissn", "id": "1234-5678" } ] # call create on the object (which will save it to the index) a = ApplicationsCrudApi.create(data, account) # check that it got created successfully assert isinstance(a, models.Suggestion) time.sleep(2) s = models.Suggestion.pull(a.id) assert s is not None
def test_15_create_application_update_request_dryrun(self): # set up all the bits we need data = ApplicationFixtureFactory.incoming_application() account = models.Account() account.set_id("test") account.set_name("Tester") account.set_email("*****@*****.**") account.add_role("publisher") journal = models.Journal(**JournalFixtureFactory.make_journal_source(in_doaj=True)) journal.bibjson().remove_identifiers() journal.bibjson().add_identifier(journal.bibjson().E_ISSN, "9999-8888") journal.bibjson().add_identifier(journal.bibjson().P_ISSN, "7777-6666") journal.bibjson().title = "not changed" journal.set_id(data["admin"]["current_journal"]) journal.set_owner(account.id) journal.save(blocking=True) # call create on the object, with the dry_run flag set a = ApplicationsCrudApi.create(data, account, dry_run=True) time.sleep(2) # now check that the application index remains empty ss = [x for x in models.Suggestion.iterall()] assert len(ss) == 0
def test_15_create_application_update_request_dryrun(self): # set up all the bits we need data = ApplicationFixtureFactory.incoming_application() account = models.Account() account.set_id("test") account.set_name("Tester") account.set_email("*****@*****.**") account.add_role("publisher") journal = models.Journal(**JournalFixtureFactory.make_journal_source( in_doaj=True)) journal.bibjson().remove_identifiers() journal.bibjson().add_identifier(journal.bibjson().E_ISSN, "9999-8888") journal.bibjson().add_identifier(journal.bibjson().P_ISSN, "7777-6666") journal.bibjson().title = "not changed" journal.set_id(data["admin"]["current_journal"]) journal.set_owner(account.id) journal.save(blocking=True) # call create on the object, with the dry_run flag set a = ApplicationsCrudApi.create(data, account, dry_run=True) time.sleep(2) # now check that the application index remains empty ss = [x for x in models.Suggestion.iterall()] assert len(ss) == 0
def test_03b_create_update_request_fail(self): # update request target not found with self.assertRaises(Api404Error): data = ApplicationFixtureFactory.incoming_application() publisher = models.Account(**AccountFixtureFactory.make_publisher_source()) try: a = ApplicationsCrudApi.create(data, publisher) except Api404Error as e: raise # if a formcontext exception is raised on finalise publisher = models.Account(**AccountFixtureFactory.make_publisher_source()) journal = models.Journal(**JournalFixtureFactory.make_journal_source(in_doaj=True)) journal.set_id(journal.makeid()) journal.set_owner(publisher.id) journal.save(blocking=True) formcontext.FormContext.finalise = mock_finalise_exception with self.assertRaises(Api400Error): data = ApplicationFixtureFactory.incoming_application() data["admin"]["current_journal"] = journal.id try: a = ApplicationsCrudApi.create(data, publisher) except Api400Error as e: assert e.message == "test exception" raise formcontext.FormContext.finalise = self.old_finalise # validation fails on the formcontext publisher = models.Account(**AccountFixtureFactory.make_publisher_source()) journal = models.Journal(**JournalFixtureFactory.make_journal_source(in_doaj=True)) journal.set_id(journal.makeid()) journal.set_owner(publisher.id) journal.save(blocking=True) IncomingApplication.custom_validate = mock_custom_validate_always_pass with self.assertRaises(Api400Error): data = ApplicationFixtureFactory.incoming_application() # duff submission charges url should trip the validator data["bibjson"]["submission_charges_url"] = "not a url!" data["admin"]["current_journal"] = journal.id try: a = ApplicationsCrudApi.create(data, publisher) except Api400Error as e: raise
def test_13_create_application_update_request_success(self): # set up all the bits we need data = ApplicationFixtureFactory.incoming_application() account = models.Account() account.set_id("test") account.set_name("Tester") account.set_email("*****@*****.**") account.add_role("publisher") account.save(blocking=True) journal = models.Journal(**JournalFixtureFactory.make_journal_source(in_doaj=True)) journal.bibjson().remove_identifiers() journal.bibjson().add_identifier(journal.bibjson().E_ISSN, "9999-8888") journal.bibjson().add_identifier(journal.bibjson().P_ISSN, "7777-6666") journal.bibjson().title = "not changed" journal.set_id(data["admin"]["current_journal"]) journal.set_owner(account.id) journal.save(blocking=True) # call create on the object (which will save it to the index) a = ApplicationsCrudApi.create(data, account) # check that it got created with the right properties assert isinstance(a, models.Suggestion) assert a.id != "ignore_me" assert a.created_date != "2001-01-01T00:00:00Z" assert a.last_updated != "2001-01-01T00:00:00Z" assert a.suggester.get("name") == "Tester" # The suggester should be the owner of the existing journal assert a.suggester.get("email") == "*****@*****.**" assert a.owner == "test" assert a.suggested_on is not None assert a.bibjson().issns() == ["9999-8888", "7777-6666"] or a.bibjson().issns() == ["7777-6666", "9999-8888"] assert a.bibjson().title == "not changed" # also, because it's a special case, check the archiving_policy archiving_policy = a.bibjson().archiving_policy assert len(archiving_policy.get("policy")) == 4 lcount = 0 scount = 0 for ap in archiving_policy.get("policy"): if isinstance(ap, list): lcount += 1 assert ap[0] in ["A national library", "Other"] assert ap[1] in ["Trinity", "A safe place"] else: scount += 1 assert lcount == 2 assert scount == 2 assert "CLOCKSS" in archiving_policy.get("policy") assert "LOCKSS" in archiving_policy.get("policy") time.sleep(2) s = models.Suggestion.pull(a.id) assert s is not None
def create_application(): # get the data from the request try: data = json.loads(request.data) except: raise Api400Error("Supplied data was not valid JSON") # delegate to the API implementation a = ApplicationsCrudApi.create(data, current_user._get_current_object()) # respond with a suitable Created response return created(a, url_for("api_v1.retrieve_application", application_id=a.id))
def create_application(): # get the data from the request try: data = json.loads(request.data.decode("utf-8")) except: raise Api400Error("Supplied data was not valid JSON") # delegate to the API implementation a = ApplicationsCrudApi.create(data, current_user._get_current_object()) # respond with a suitable Created response return created(a, url_for("api_v1.retrieve_application", application_id=a.id))
def test_03c_update_update_request_fail(self): # update request target in disallowed status journal = models.Journal(**JournalFixtureFactory.make_journal_source(in_doaj=True)) journal.set_id(journal.makeid()) journal.save(blocking=True) with self.assertRaises(Api404Error): data = ApplicationFixtureFactory.incoming_application() data["admin"]["current_journal"] = journal.id publisher = models.Account(**AccountFixtureFactory.make_publisher_source()) try: a = ApplicationsCrudApi.create(data, publisher) except Api404Error as e: raise
def test_02_create_application_success(self): # set up all the bits we need data = ApplicationFixtureFactory.incoming_application() del data["admin"]["current_journal"] data["admin"]["application_status"] = "on_hold" data["admin"]["owner"] = "someaccount" account = models.Account() account.set_id("test") account.set_name("Tester") account.set_email("*****@*****.**") # call create on the object (which will save it to the index) a = ApplicationsCrudApi.create(data, account) # check that it got created with the right properties assert isinstance(a, models.Suggestion) assert a.id != "ignore_me" assert a.created_date != "2001-01-01T00:00:00Z" assert a.last_updated != "2001-01-01T00:00:00Z" assert a.suggester.get("name") == "Tester" assert a.suggester.get("email") == "*****@*****.**" assert a.owner == "test" assert a.suggested_on is not None assert len(a.bibjson().keywords) > 1 # check the stuff that should default assert a.application_status == "pending" assert a.owner == "test" # also, because it's a special case, check the archiving_policy archiving_policy = a.bibjson().archiving_policy assert len(archiving_policy.get("policy")) == 4 lcount = 0 scount = 0 for ap in archiving_policy.get("policy"): if isinstance(ap, list): lcount += 1 assert ap[0] in ["A national library", "Other"] assert ap[1] in ["Trinity", "A safe place"] else: scount += 1 assert lcount == 2 assert scount == 2 assert "CLOCKSS" in archiving_policy.get("policy") assert "LOCKSS" in archiving_policy.get("policy") time.sleep(2) s = models.Suggestion.pull(a.id) assert s is not None
def test_03c_update_update_request_fail(self): # update request target in disallowed status journal = models.Journal(**JournalFixtureFactory.make_journal_source( in_doaj=True)) journal.set_id(journal.makeid()) journal.save(blocking=True) with self.assertRaises(Api404Error): data = ApplicationFixtureFactory.incoming_application() data["admin"]["current_journal"] = journal.id publisher = models.Account( **AccountFixtureFactory.make_publisher_source()) try: a = ApplicationsCrudApi.create(data, publisher) except Api404Error as e: raise
def test_14_create_application_update_request_fail(self): data = ApplicationFixtureFactory.incoming_application() journal = models.Journal(**JournalFixtureFactory.make_journal_source(in_doaj=True)) journal.bibjson().remove_identifiers() journal.bibjson().add_identifier(journal.bibjson().E_ISSN, "9999-8888") journal.bibjson().add_identifier(journal.bibjson().P_ISSN, "7777-6666") journal.bibjson().title = "not changed" journal.set_id(data["admin"]["current_journal"]) journal.set_owner("test") journal.save(blocking=True) # if the account is dud with self.assertRaises(Api401Error): a = ApplicationsCrudApi.create(data, None) # if the data is bust with self.assertRaises(Api400Error): account = models.Account() account.set_id("test") account.set_name("Tester") account.set_email("*****@*****.**") data = {"some" : {"junk" : "data"}} a = ApplicationsCrudApi.create(data, account)
def test_09_update_application_fail(self): # set up all the bits we need data = ApplicationFixtureFactory.incoming_application() del data["admin"]["current_journal"] account = models.Account() account.set_id("test") account.set_name("Tester") account.set_email("*****@*****.**") # call create on the object (which will save it to the index) a = ApplicationsCrudApi.create(data, account) # let the index catch up time.sleep(2) # get a copy of the newly created version for use in assertions later created = models.Suggestion.pull(a.id) # now make an updated version of the object data = ApplicationFixtureFactory.incoming_application() del data["admin"]["current_journal"] data["bibjson"]["title"] = "An updated title" # call update on the object in various context that will fail # without an account with self.assertRaises(Api401Error): ApplicationsCrudApi.update(a.id, data, None) # with the wrong account account.set_id("other") with self.assertRaises(Api404Error): ApplicationsCrudApi.update(a.id, data, account) # on the wrong id account.set_id("test") with self.assertRaises(Api404Error): ApplicationsCrudApi.update("adfasdfhwefwef", data, account) # on one with a disallowed workflow status created.set_application_status(constants.APPLICATION_STATUS_ACCEPTED) created.save() time.sleep(2) account.add_role("publisher") with self.assertRaises(Api403Error): ApplicationsCrudApi.update(a.id, data, account)
def test_16_update_application_update_request_success(self): # set up all the bits we need data = ApplicationFixtureFactory.incoming_application() account = models.Account() account.set_id("test") account.set_name("Tester") account.set_email("*****@*****.**") account.add_role("publisher") journal = models.Journal(**JournalFixtureFactory.make_journal_source( in_doaj=True)) journal.bibjson().remove_identifiers() journal.bibjson().add_identifier(journal.bibjson().E_ISSN, "9999-8888") journal.bibjson().add_identifier(journal.bibjson().P_ISSN, "7777-6666") journal.bibjson().title = "not changed" journal.set_id(data["admin"]["current_journal"]) journal.set_owner(account.id) journal.save(blocking=True) # call create on the object (which will save it to the index) a = ApplicationsCrudApi.create(data, account) # let the index catch up time.sleep(2) # get a copy of the newly created version for use in assertions later created = models.Suggestion.pull(a.id) # now make an updated version of the object data = ApplicationFixtureFactory.incoming_application() data["bibjson"]["title"] = "An updated title" data["bibjson"]["publisher"] = "An updated publisher" # call update on the object a2 = ApplicationsCrudApi.update(a.id, data, account) assert a2 != a # let the index catch up time.sleep(2) # get a copy of the updated version updated = models.Suggestion.pull(a.id) # now check the properties to make sure the update tool assert updated.bibjson().title == "not changed" assert updated.bibjson().publisher == "An updated publisher" assert updated.created_date == created.created_date
def test_03a_create_application_dryrun(self): # set up all the bits we need data = ApplicationFixtureFactory.incoming_application() del data["admin"]["current_journal"] account = models.Account() account.set_id("test") account.set_name("Tester") account.set_email("*****@*****.**") # call create on the object, with the dry_run flag set a = ApplicationsCrudApi.create(data, account, dry_run=True) time.sleep(2) # now check that the application index remains empty ss = [x for x in models.Suggestion.iterall()] assert len(ss) == 0
def test_16_update_application_update_request_success(self): # set up all the bits we need data = ApplicationFixtureFactory.incoming_application() account = models.Account() account.set_id("test") account.set_name("Tester") account.set_email("*****@*****.**") account.add_role("publisher") journal = models.Journal(**JournalFixtureFactory.make_journal_source(in_doaj=True)) journal.bibjson().remove_identifiers() journal.bibjson().add_identifier(journal.bibjson().E_ISSN, "9999-8888") journal.bibjson().add_identifier(journal.bibjson().P_ISSN, "7777-6666") journal.bibjson().title = "not changed" journal.set_id(data["admin"]["current_journal"]) journal.set_owner(account.id) journal.save(blocking=True) # call create on the object (which will save it to the index) a = ApplicationsCrudApi.create(data, account) # let the index catch up time.sleep(2) # get a copy of the newly created version for use in assertions later created = models.Suggestion.pull(a.id) # now make an updated version of the object data = ApplicationFixtureFactory.incoming_application() data["bibjson"]["title"] = "An updated title" data["bibjson"]["publisher"] = "An updated publisher" # call update on the object a2 = ApplicationsCrudApi.update(a.id, data, account) assert a2 != a # let the index catch up time.sleep(2) # get a copy of the updated version updated = models.Suggestion.pull(a.id) # now check the properties to make sure the update tool assert updated.bibjson().title == "not changed" assert updated.bibjson().publisher == "An updated publisher" assert updated.created_date == created.created_date
def test_02_create_application_success(self): # set up all the bits we need data = ApplicationFixtureFactory.incoming_application() del data["admin"]["current_journal"] account = models.Account() account.set_id("test") account.set_name("Tester") account.set_email("*****@*****.**") # call create on the object (which will save it to the index) a = ApplicationsCrudApi.create(data, account) # check that it got created with the right properties assert isinstance(a, models.Suggestion) assert a.id != "ignore_me" assert a.created_date != "2001-01-01T00:00:00Z" assert a.last_updated != "2001-01-01T00:00:00Z" assert a.suggester.get("name") == "Tester" assert a.suggester.get("email") == "*****@*****.**" assert a.owner == "test" assert a.suggested_on is not None assert len(a.bibjson().keywords) > 1 # also, because it's a special case, check the archiving_policy archiving_policy = a.bibjson().archiving_policy assert len(archiving_policy.get("policy")) == 4 lcount = 0 scount = 0 for ap in archiving_policy.get("policy"): if isinstance(ap, list): lcount += 1 assert ap[0] in ["A national library", "Other"] assert ap[1] in ["Trinity", "A safe place"] else: scount += 1 assert lcount == 2 assert scount == 2 assert "CLOCKSS" in archiving_policy.get("policy") assert "LOCKSS" in archiving_policy.get("policy") time.sleep(2) s = models.Suggestion.pull(a.id) assert s is not None
def test_02a_create_application_success_variations(self): # set up all the bits we need data = ApplicationFixtureFactory.incoming_application() del data["admin"]["current_journal"] account = models.Account() account.set_id("test") account.set_name("Tester") account.set_email("*****@*****.**") # try with only one issn data["bibjson"]["identifier"] = [{"type": "pissn", "id": "1234-5678"}] # call create on the object (which will save it to the index) a = ApplicationsCrudApi.create(data, account) # check that it got created successfully assert isinstance(a, models.Suggestion) time.sleep(2) s = models.Suggestion.pull(a.id) assert s is not None
def test_08_update_application_success(self): # set up all the bits we need data = ApplicationFixtureFactory.incoming_application() del data["admin"]["current_journal"] account = models.Account() account.set_id("test") account.set_name("Tester") account.set_email("*****@*****.**") account.add_role("publisher") # call create on the object (which will save it to the index) a = ApplicationsCrudApi.create(data, account) # let the index catch up time.sleep(2) # get a copy of the newly created version for use in assertions later created = models.Suggestion.pull(a.id) # now make an updated version of the object data = ApplicationFixtureFactory.incoming_application() del data["admin"]["current_journal"] data["bibjson"]["title"] = "An updated title" # call update on the object a2 = ApplicationsCrudApi.update(a.id, data, account) assert a2 != a # let the index catch up time.sleep(2) # get a copy of the updated version updated = models.Suggestion.pull(a.id) # now check the properties to make sure the update tool assert updated.bibjson().title == "An updated title" assert updated.created_date == created.created_date
def test_12_delete_application_dryrun(self): # set up all the bits we need data = ApplicationFixtureFactory.incoming_application() del data["admin"]["current_journal"] account = models.Account() account.set_id("test") account.set_name("Tester") account.set_email("*****@*****.**") account.add_role("publisher") # call create on the object (which will save it to the index) a = ApplicationsCrudApi.create(data, account) # let the index catch up time.sleep(2) # now delete it with the dry run flag ApplicationsCrudApi.delete(a.id, account, dry_run=True) # let the index catch up time.sleep(2) ap = models.Suggestion.pull(a.id) assert ap is not None
def test_17_update_application_update_request_fail(self): # set up all the bits we need data = ApplicationFixtureFactory.incoming_application() account = models.Account() account.set_id("test") account.set_name("Tester") account.set_email("*****@*****.**") account.add_role("publisher") journal = models.Journal(**JournalFixtureFactory.make_journal_source(in_doaj=True)) journal.bibjson().remove_identifiers() journal.bibjson().add_identifier(journal.bibjson().E_ISSN, "9999-8888") journal.bibjson().add_identifier(journal.bibjson().P_ISSN, "7777-6666") journal.bibjson().title = "not changed" journal.set_id(data["admin"]["current_journal"]) journal.set_owner(account.id) journal.save(blocking=True) # call create on the object (which will save it to the index) a = ApplicationsCrudApi.create(data, account) # let the index catch up time.sleep(2) # get a copy of the newly created version for use in assertions later created = models.Suggestion.pull(a.id) # now make an updated version of the object data = ApplicationFixtureFactory.incoming_application() data["bibjson"]["title"] = "An updated title" data["bibjson"]["publisher"] = "An updated publisher" # call update on the object in various context that will fail # without an account with self.assertRaises(Api401Error): ApplicationsCrudApi.update(a.id, data, None) # with the wrong account account.set_id("other") with self.assertRaises(Api404Error): ApplicationsCrudApi.update(a.id, data, account) # on the wrong id account.set_id("test") with self.assertRaises(Api404Error): ApplicationsCrudApi.update("adfasdfhwefwef", data, account) # with the wrong user role account.remove_role("publisher") with self.assertRaises(Api404Error): ApplicationsCrudApi.update(a.id, data, account) account.add_role("publisher") # on one with a disallowed workflow status created.set_application_status(constants.APPLICATION_STATUS_ACCEPTED) created.save(blocking=True) with self.assertRaises(Api403Error): ApplicationsCrudApi.update(a.id, data, account) # one with the wrong data structure data["flibble"] = "whatever" with self.assertRaises(Api400Error): ApplicationsCrudApi.update(a.id, data, account) del data["flibble"] # one where we tried to change the current_journal data["admin"]["current_journal"] = "owqierqwoieqwoijefwq" with self.assertRaises(Api400Error): ApplicationsCrudApi.update(a.id, data, account)
def test_03_create_application_fail(self): # if the account is dud with self.assertRaises(Api401Error): data = ApplicationFixtureFactory.incoming_application() a = ApplicationsCrudApi.create(data, None) # if the data is bust with self.assertRaises(Api400Error): account = models.Account() account.set_id("test") account.set_name("Tester") account.set_email("*****@*****.**") data = {"some": {"junk": "data"}} a = ApplicationsCrudApi.create(data, account) # if a formcontext exception is raised on finalise formcontext.FormContext.finalise = mock_finalise_exception with self.assertRaises(Api400Error): data = ApplicationFixtureFactory.incoming_application() del data["admin"]["current_journal"] publisher = models.Account( **AccountFixtureFactory.make_publisher_source()) try: a = ApplicationsCrudApi.create(data, publisher) except Api400Error as e: assert str(e) == "test exception" raise formcontext.FormContext.finalise = self.old_finalise # validation fails on the formcontext IncomingApplication.custom_validate = mock_custom_validate_always_pass with self.assertRaises(Api400Error): data = ApplicationFixtureFactory.incoming_application() del data["admin"]["current_journal"] # a duff email should trigger the form validation failure data["admin"]["contact"][0]["email"] = "not an email address" publisher = models.Account( **AccountFixtureFactory.make_publisher_source()) try: a = ApplicationsCrudApi.create(data, publisher) except Api400Error as e: raise IncomingApplication.custom_validate = self.old_custom_validate # issns are the same data = ApplicationFixtureFactory.incoming_application() del data["admin"]["current_journal"] data["bibjson"]["identifier"] = [{ "type": "pissn", "id": "1234-5678" }, { "type": "eissn", "id": "1234-5678" }] with self.assertRaises(Api400Error): publisher = models.Account( **AccountFixtureFactory.make_publisher_source()) try: a = ApplicationsCrudApi.create(data, publisher) except Api400Error as e: raise
def test_03_create_application_fail(self): # if the account is dud with self.assertRaises(Api401Error): data = ApplicationFixtureFactory.incoming_application() a = ApplicationsCrudApi.create(data, None) # if the data is bust with self.assertRaises(Api400Error): account = models.Account() account.set_id("test") account.set_name("Tester") account.set_email("*****@*****.**") data = {"some" : {"junk" : "data"}} a = ApplicationsCrudApi.create(data, account) # if a formcontext exception is raised on finalise formcontext.FormContext.finalise = mock_finalise_exception with self.assertRaises(Api400Error): data = ApplicationFixtureFactory.incoming_application() del data["admin"]["current_journal"] publisher = models.Account(**AccountFixtureFactory.make_publisher_source()) try: a = ApplicationsCrudApi.create(data, publisher) except Api400Error as e: assert e.message == "test exception" raise formcontext.FormContext.finalise = self.old_finalise # validation fails on the formcontext IncomingApplication.custom_validate = mock_custom_validate_always_pass with self.assertRaises(Api400Error): data = ApplicationFixtureFactory.incoming_application() del data["admin"]["current_journal"] # a duff email should trigger the form validation failure data["admin"]["contact"][0]["email"] = "not an email address" publisher = models.Account(**AccountFixtureFactory.make_publisher_source()) try: a = ApplicationsCrudApi.create(data, publisher) except Api400Error as e: raise IncomingApplication.custom_validate = self.old_custom_validate # issns are the same data = ApplicationFixtureFactory.incoming_application() del data["admin"]["current_journal"] data["bibjson"]["identifier"] = [ { "type" : "pissn", "id": "1234-5678" }, { "type" : "eissn", "id": "1234-5678" } ] with self.assertRaises(Api400Error): publisher = models.Account(**AccountFixtureFactory.make_publisher_source()) try: a = ApplicationsCrudApi.create(data, publisher) except Api400Error as e: raise
def test_17_update_application_update_request_fail(self): # set up all the bits we need data = ApplicationFixtureFactory.incoming_application() account = models.Account() account.set_id("test") account.set_name("Tester") account.set_email("*****@*****.**") account.add_role("publisher") journal = models.Journal(**JournalFixtureFactory.make_journal_source( in_doaj=True)) journal.bibjson().remove_identifiers() journal.bibjson().add_identifier(journal.bibjson().E_ISSN, "9999-8888") journal.bibjson().add_identifier(journal.bibjson().P_ISSN, "7777-6666") journal.bibjson().title = "not changed" journal.set_id(data["admin"]["current_journal"]) journal.set_owner(account.id) journal.save(blocking=True) # call create on the object (which will save it to the index) a = ApplicationsCrudApi.create(data, account) # let the index catch up time.sleep(2) # get a copy of the newly created version for use in assertions later created = models.Suggestion.pull(a.id) # now make an updated version of the object data = ApplicationFixtureFactory.incoming_application() data["bibjson"]["title"] = "An updated title" data["bibjson"]["publisher"] = "An updated publisher" # call update on the object in various context that will fail # without an account with self.assertRaises(Api401Error): ApplicationsCrudApi.update(a.id, data, None) # with the wrong account account.set_id("other") with self.assertRaises(Api404Error): ApplicationsCrudApi.update(a.id, data, account) # on the wrong id account.set_id("test") with self.assertRaises(Api404Error): ApplicationsCrudApi.update("adfasdfhwefwef", data, account) # with the wrong user role account.remove_role("publisher") with self.assertRaises(Api404Error): ApplicationsCrudApi.update(a.id, data, account) account.add_role("publisher") # on one with a disallowed workflow status created.set_application_status(constants.APPLICATION_STATUS_ACCEPTED) created.save(blocking=True) with self.assertRaises(Api403Error): ApplicationsCrudApi.update(a.id, data, account) # one with the wrong data structure data["flibble"] = "whatever" with self.assertRaises(Api400Error): ApplicationsCrudApi.update(a.id, data, account) del data["flibble"] # one where we tried to change the current_journal data["admin"]["current_journal"] = "owqierqwoieqwoijefwq" with self.assertRaises(Api400Error): ApplicationsCrudApi.update(a.id, data, account)