예제 #1
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 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
예제 #2
0
    def test_03_delete_application_success(self):
        # set up all the bits we need
        data = ApplicationFixtureFactory.incoming_application()
        del data["admin"]["current_journal"]
        dataset = [data] * 10

        # create the account we're going to work as
        account = models.Account()
        account.set_id("test")
        account.set_name("Tester")
        account.set_email("*****@*****.**")
        account.add_role("publisher")

        # call create on the objects (which will save it to the index)
        ids = ApplicationsBulkApi.create(dataset, account)

        # let the index catch up
        time.sleep(2)

        # now delete half of them
        dels = ids[:5]
        ApplicationsBulkApi.delete(dels, account)

        # let the index catch up
        time.sleep(2)

        for id in dels:
            ap = models.Suggestion.pull(id)
            assert ap is None
        for id in ids[5:]:
            ap = models.Suggestion.pull(id)
            assert ap is not None
예제 #3
0
    def test_01_create_applications_success(self):
        # set up all the bits we need - 10 applications
        data = ApplicationFixtureFactory.incoming_application()
        del data["admin"]["current_journal"]
        dataset = [data] * 10

        # create an account that we'll do the create as
        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)
        ids = ApplicationsBulkApi.create(dataset, account)

        # check that we got the right number of ids back
        assert len(ids) == 10

        # let the index catch up
        time.sleep(2)

        # check that each id was actually created
        for id in ids:
            s = models.Suggestion.pull(id)
            assert s is not None
예제 #4
0
    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
예제 #5
0
    def test_03_delete_application_success(self):
        # set up all the bits we need
        data = ApplicationFixtureFactory.incoming_application()
        del data["admin"]["current_journal"]
        dataset = [data] * 10

        # create the account we're going to work as
        account = models.Account()
        account.set_id("test")
        account.set_name("Tester")
        account.set_email("*****@*****.**")
        account.add_role("publisher")

        # call create on the objects (which will save it to the index)
        ids = ApplicationsBulkApi.create(dataset, account)

        # let the index catch up
        time.sleep(2)

        # now delete half of them
        dels = ids[:5]
        ApplicationsBulkApi.delete(dels, account)

        # let the index catch up
        time.sleep(2)

        for id in dels:
            ap = models.Suggestion.pull(id)
            assert ap is None
        for id in ids[5:]:
            ap = models.Suggestion.pull(id)
            assert ap is not None
예제 #6
0
    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
예제 #7
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
예제 #8
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
예제 #9
0
    def test_05_test_via_endpoint(self):
        """ Use a request context to test the API via the route """

        # set up all the bits we need
        data = ApplicationFixtureFactory.incoming_application()
        del data["admin"]["current_journal"]
        dataset = [data] * 10

        # create the main account we're going to work as
        account = models.Account()
        account.set_id("test")
        account.set_name("Tester")
        account.set_email("*****@*****.**")
        account.generate_api_key()
        account.add_role('publisher')
        account.add_role('api')
        account.save(blocking=True)

        # Add another user who doesn't own these articles
        somebody_else = models.Account()
        somebody_else.set_id("somebody_else")
        somebody_else.set_name("Somebody Else")
        somebody_else.set_email("*****@*****.**")
        somebody_else.generate_api_key()
        somebody_else.add_role('publisher')
        somebody_else.add_role('api')
        somebody_else.save(blocking=True)

        assert account.api_key != somebody_else.api_key

        with self.app_test.test_request_context():
            with self.app_test.test_client() as t_client:
                # Create some new applications
                resp = t_client.post(url_for('api_v1.bulk_application_create',
                                             api_key=account.api_key),
                                     data=json.dumps(dataset))
                assert resp.status_code == 201
                reply = json.loads(resp.data.decode("utf-8"))
                assert len(reply) == len(dataset)
                first_apl = reply.pop()
                assert first_apl['status'] == 'created'
                # Check we actually created new records
                time.sleep(1.5)
                assert len(models.Suggestion.all()) == len(dataset)

                # Bulk delete
                all_but_one = [new_art['id'] for new_art in reply]
                resp = t_client.delete(url_for(
                    'api_v1.bulk_application_delete', api_key=account.api_key),
                                       data=json.dumps(all_but_one))
                assert resp.status_code == 204
                time.sleep(1)
                # we should have deleted all but one of the applications.
                assert len(models.Suggestion.all()) == 1
                # And our other user isn't allowed to delete the remaining one.
                resp = t_client.delete(url_for(
                    'api_v1.bulk_application_delete',
                    api_key=somebody_else.api_key),
                                       data=json.dumps([first_apl['id']]))
                assert resp.status_code == 400
예제 #10
0
    def test_01_create_applications_success(self):
        # set up all the bits we need - 10 applications
        data = ApplicationFixtureFactory.incoming_application()
        del data["admin"]["current_journal"]
        dataset = [data] * 10

        # create an account that we'll do the create as
        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)
        ids = ApplicationsBulkApi.create(dataset, account)

        # check that we got the right number of ids back
        assert len(ids) == 10

        # let the index catch up
        time.sleep(2)

        # check that each id was actually created
        for id in ids:
            s = models.Suggestion.pull(id)
            assert s is not None
예제 #11
0
    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)
예제 #12
0
    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)
예제 #13
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
예제 #14
0
    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)
예제 #15
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
예제 #16
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
예제 #17
0
    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
예제 #18
0
    def test_02_applications_crud(self):
        # add some data to the index with a Create
        user_data = ApplicationFixtureFactory.incoming_application()
        del user_data["admin"]["current_journal"]

        with self.app_test.test_client() as t_client:
            # log into the app as our user
            self.login(t_client, 'test', 'password123')

            # CREATE a new application
            response = t_client.post('/api/v1/applications?api_key=' + self.api_key, data=json.dumps(user_data))
            assert response.status_code == 201          # 201 "Created"
            assert response.mimetype == 'application/json'

            # Check it gives back a newly created application, with an ID
            new_app_id = json.loads(response.data.decode("utf-8"))['id']
            new_app_loc = json.loads(response.data.decode("utf-8"))['location']
            assert new_app_id is not None
            assert new_app_id in new_app_loc

            # RETRIEVE the same application using the ID
            response = t_client.get('/api/v1/applications/{0}?api_key={1}'.format(new_app_id, self.api_key))
            assert response.status_code == 200          # 200 "OK"
            assert response.mimetype == 'application/json'

            retrieved_application = json.loads(response.data.decode("utf-8"))
            new_app_title = retrieved_application['bibjson']['title']
            assert new_app_title == user_data['bibjson']['title']

            # UPDATE the title of the application
            updated_data = deepcopy(user_data)
            updated_data['bibjson']['title'] = 'This is a new title for this application'
            response = t_client.put('/api/v1/applications/{0}?api_key={1}'.format(new_app_id, self.api_key), data=json.dumps(updated_data))
            assert response.status_code == 204          # 204 "No Content"
            assert response.mimetype == 'application/json'

            response = t_client.get('/api/v1/applications/{0}?api_key={1}'.format(new_app_id, self.api_key))
            retrieved_application = json.loads(response.data.decode("utf-8"))
            new_app_title = retrieved_application['bibjson']['title']
            assert new_app_title == updated_data['bibjson']['title']
            assert new_app_title != user_data['bibjson']['title']

            # DELETE the application
            assert models.Suggestion.pull(new_app_id) is not None
            response = t_client.delete('/api/v1/applications/{0}?api_key={1}'.format(new_app_id, self.api_key))
            assert response.status_code == 204          # 204 "No Content"
            assert response.mimetype == 'application/json'

            # Try to RETRIEVE the Application again - check it isn't there anymore
            response = t_client.get('/api/v1/applications/{0}?api_key={1}'.format(new_app_id, self.api_key))
            assert response.status_code == 404
            assert response.mimetype == 'application/json'

            self.logout(t_client)
예제 #19
0
    def test_02_applications_crud(self):
        # add some data to the index with a Create
        user_data = ApplicationFixtureFactory.incoming_application()
        del user_data["admin"]["current_journal"]

        with self.app_test.test_client() as t_client:
            # log into the app as our user
            self.login(t_client, 'test', 'password123')

            # CREATE a new application
            response = t_client.post('/api/v1/applications?api_key=' + self.api_key, data=json.dumps(user_data))
            assert response.status_code == 201          # 201 "Created"
            assert response.mimetype == 'application/json'

            # Check it gives back a newly created application, with an ID
            new_app_id = json.loads(response.data)['id']
            new_app_loc = json.loads(response.data)['location']
            assert new_app_id is not None
            assert new_app_id in new_app_loc

            # RETRIEVE the same application using the ID
            response = t_client.get('/api/v1/applications/{0}?api_key={1}'.format(new_app_id, self.api_key))
            assert response.status_code == 200          # 200 "OK"
            assert response.mimetype == 'application/json'

            retrieved_application = json.loads(response.data)
            new_app_title = retrieved_application['bibjson']['title']
            assert new_app_title == user_data['bibjson']['title']

            # UPDATE the title of the application
            updated_data = deepcopy(user_data)
            updated_data['bibjson']['title'] = 'This is a new title for this application'
            response = t_client.put('/api/v1/applications/{0}?api_key={1}'.format(new_app_id, self.api_key), data=json.dumps(updated_data))
            assert response.status_code == 204          # 204 "No Content"
            assert response.mimetype == 'application/json'

            response = t_client.get('/api/v1/applications/{0}?api_key={1}'.format(new_app_id, self.api_key))
            retrieved_application = json.loads(response.data)
            new_app_title = retrieved_application['bibjson']['title']
            assert new_app_title == updated_data['bibjson']['title']
            assert new_app_title != user_data['bibjson']['title']

            # DELETE the application
            assert models.Suggestion.pull(new_app_id) is not None
            response = t_client.delete('/api/v1/applications/{0}?api_key={1}'.format(new_app_id, self.api_key))
            assert response.status_code == 204          # 204 "No Content"
            assert response.mimetype == 'application/json'

            # Try to RETRIEVE the Application again - check it isn't there anymore
            response = t_client.get('/api/v1/applications/{0}?api_key={1}'.format(new_app_id, self.api_key))
            assert response.status_code == 404
            assert response.mimetype == 'application/json'

            self.logout(t_client)
예제 #20
0
 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
예제 #21
0
    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
예제 #22
0
    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
예제 #23
0
    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
예제 #24
0
 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
예제 #25
0
    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
예제 #26
0
    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
예제 #27
0
    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
예제 #28
0
    def test_04_delete_applications_fail(self):
        # set up all the bits we need
        data = ApplicationFixtureFactory.incoming_application()
        del data["admin"]["current_journal"]
        dataset = [data] * 10

        # create the account we're going to work as
        account = models.Account()
        account.set_id("test")
        account.set_name("Tester")
        account.set_email("*****@*****.**")

        # call create on the objects (which will save it to the index)
        ids = ApplicationsBulkApi.create(dataset, account)

        # let the index catch up
        time.sleep(2)

        # call delete on the object in various context that will fail

        # without an account
        with self.assertRaises(Api401Error):
            ApplicationsBulkApi.delete(ids, None)

        # with the wrong account
        account.set_id("other")
        with self.assertRaises(Api400Error):
            ApplicationsBulkApi.delete(ids, account)

        # on the wrong id
        ids.append("adfasdfhwefwef")
        account.set_id("test")
        with self.assertRaises(Api400Error):
            ApplicationsBulkApi.delete(ids, account)

        # on one with a disallowed workflow status
        created = models.Suggestion.pull(ids[3])
        created.set_application_status(constants.APPLICATION_STATUS_ACCEPTED)
        created.save()
        time.sleep(2)

        with self.assertRaises(Api400Error):
            ApplicationsBulkApi.delete(ids, account)
예제 #29
0
    def test_04_delete_applications_fail(self):
        # set up all the bits we need
        data = ApplicationFixtureFactory.incoming_application()
        del data["admin"]["current_journal"]
        dataset = [data] * 10

        # create the account we're going to work as
        account = models.Account()
        account.set_id("test")
        account.set_name("Tester")
        account.set_email("*****@*****.**")

        # call create on the objects (which will save it to the index)
        ids = ApplicationsBulkApi.create(dataset, account)

        # let the index catch up
        time.sleep(2)

        # call delete on the object in various context that will fail

        # without an account
        with self.assertRaises(Api401Error):
            ApplicationsBulkApi.delete(ids, None)

        # with the wrong account
        account.set_id("other")
        with self.assertRaises(Api400Error):
            ApplicationsBulkApi.delete(ids, account)

        # on the wrong id
        ids.append("adfasdfhwefwef")
        account.set_id("test")
        with self.assertRaises(Api400Error):
            ApplicationsBulkApi.delete(ids, account)

        # on one with a disallowed workflow status
        created = models.Suggestion.pull(ids[3])
        created.set_application_status(constants.APPLICATION_STATUS_ACCEPTED)
        created.save()
        time.sleep(2)

        with self.assertRaises(Api400Error):
            ApplicationsBulkApi.delete(ids, account)
예제 #30
0
    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
예제 #31
0
    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
예제 #32
0
    def test_02_create_applications_fail(self):
        # if the account is dud
        with self.assertRaises(Api401Error):
            data = ApplicationFixtureFactory.incoming_application()
            del data["admin"]["current_journal"]
            dataset = [data] * 10
            ids = ApplicationsBulkApi.create(dataset, None)

        # check that the index is empty, as none of them should have been made
        all = [x for x in models.Suggestion.iterall()]
        assert len(all) == 0

        # if the data is bust
        with self.assertRaises(Api400Error):
            account = models.Account()
            account.set_id("test")
            account.set_name("Tester")
            account.set_email("*****@*****.**")
            dataset = dataset[:5] + [{"some": {"junk": "data"}}] + dataset[5:]
            ids = ApplicationsBulkApi.create(dataset, account)

        # check that the index is empty, as none of them should have been made
        all = [x for x in models.Suggestion.iterall()]
        assert len(all) == 0
예제 #33
0
    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
예제 #34
0
    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)
예제 #35
0
    def test_02_create_applications_fail(self):
        # if the account is dud
        with self.assertRaises(Api401Error):
            data = ApplicationFixtureFactory.incoming_application()
            del data["admin"]["current_journal"]
            dataset = [data] * 10
            ids = ApplicationsBulkApi.create(dataset, None)

        # check that the index is empty, as none of them should have been made
        all = [x for x in models.Suggestion.iterall()]
        assert len(all) == 0

        # if the data is bust
        with self.assertRaises(Api400Error):
            account = models.Account()
            account.set_id("test")
            account.set_name("Tester")
            account.set_email("*****@*****.**")
            dataset = dataset[:5] + [{"some" : {"junk" : "data"}}] + dataset[5:]
            ids = ApplicationsBulkApi.create(dataset, account)

        # check that the index is empty, as none of them should have been made
        all = [x for x in models.Suggestion.iterall()]
        assert len(all) == 0
예제 #36
0
    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
예제 #37
0
    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)
예제 #38
0
import requests, json, time
from copy import deepcopy
from doajtest.fixtures import ApplicationFixtureFactory, ArticleFixtureFactory

# applications
API = "http://localhost:5004/api/v1/bulk/applications"
KEY = "d117ad1b35b94469b3dae09c29bfed55"

dataset = [ApplicationFixtureFactory.incoming_application()] * 10

resp = requests.post(API + "?api_key=" + KEY, data=json.dumps(dataset))
assert resp.status_code == 201

j = resp.json()
assert len(j) == 10

print j

ids = [r.get("id") for r in j]
print ids

time.sleep(2)

resp = requests.delete(API + "?api_key=" + KEY, data=json.dumps(ids))
assert resp.status_code == 204

# articles
# make sure you give the api key of a user who has a journal which is
# in_doaj = True and also has the same ISSNs as the articles in the test
# data - usually this will be PISSN 1234-5678 and EISSN 9876-5432
API = "http://localhost:5004/api/v1/bulk/articles"
예제 #39
0
    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
예제 #40
0
    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)
예제 #41
0
    def test_01_incoming_application_do(self):
        # make a blank one
        ia = IncomingApplication()

        # make one from an incoming application model fixture
        data = ApplicationFixtureFactory.incoming_application()
        ia = IncomingApplication(data)

        # make another one that's broken
        data = ApplicationFixtureFactory.incoming_application()
        del data["bibjson"]["title"]
        with self.assertRaises(DataStructureException):
            ia = IncomingApplication(data)

        # now progressively remove the conditionally required/advanced validation stuff
        #
        # missing identifiers
        data = ApplicationFixtureFactory.incoming_application()
        data["bibjson"]["identifier"] = []
        with self.assertRaises(DataStructureException):
            ia = IncomingApplication(data)

        # no issns specified
        data["bibjson"]["identifier"] = [{"type": "wibble", "id": "alksdjfas"}]
        with self.assertRaises(DataStructureException):
            ia = IncomingApplication(data)

        # issns the same (but not normalised the same)
        data["bibjson"]["identifier"] = [{
            "type": "pissn",
            "id": "12345678"
        }, {
            "type": "eissn",
            "id": "1234-5678"
        }]
        with self.assertRaises(DataStructureException):
            ia = IncomingApplication(data)

        # no homepage link
        data = ApplicationFixtureFactory.incoming_application()
        data["bibjson"]["link"] = [{"type": "awaypage", "url": "http://there"}]
        with self.assertRaises(DataStructureException):
            ia = IncomingApplication(data)

        # plagiarism detection but no url
        data = ApplicationFixtureFactory.incoming_application()
        data["bibjson"]["plagiarism_detection"] = {"detection": True}
        with self.assertRaises(DataStructureException):
            ia = IncomingApplication(data)

        # embedded licence but no url
        data = ApplicationFixtureFactory.incoming_application()
        data["bibjson"]["license"][0]["embedded"] = True
        del data["bibjson"]["license"][0]["embedded_example_url"]
        with self.assertRaises(DataStructureException):
            ia = IncomingApplication(data)

        # author copyright and no link
        data = ApplicationFixtureFactory.incoming_application()
        data["bibjson"]["author_copyright"]["copyright"] = True
        del data["bibjson"]["author_copyright"]["url"]
        with self.assertRaises(DataStructureException):
            ia = IncomingApplication(data)

        # author publishing rights and no ling
        data = ApplicationFixtureFactory.incoming_application()
        data["bibjson"]["author_publishing_rights"]["publishing_rights"] = True
        del data["bibjson"]["author_publishing_rights"]["url"]
        with self.assertRaises(DataStructureException):
            ia = IncomingApplication(data)

        # invalid domain in archiving_policy
        data = ApplicationFixtureFactory.incoming_application()
        data["bibjson"]["archiving_policy"]["policy"] = [{
            "domain": "my house",
            "name": "something"
        }]
        with self.assertRaises(DataStructureException):
            ia = IncomingApplication(data)

        # invalid name in non-domained policy
        data = ApplicationFixtureFactory.incoming_application()
        data["bibjson"]["archiving_policy"]["policy"] = [{"name": "something"}]
        with self.assertRaises(DataStructureException):
            ia = IncomingApplication(data)

        # too many keywords
        data = ApplicationFixtureFactory.incoming_application()
        data["bibjson"]["keywords"] = [
            "one", "two", "three", "four", "five", "six", "seven"
        ]
        with self.assertRaises(DataStructureException):
            ia = IncomingApplication(data)
예제 #42
0
    def test_01_incoming_application_do(self):
        # make a blank one
        ia = IncomingApplication()

        # make one from an incoming application model fixture
        data = ApplicationFixtureFactory.incoming_application()
        ia = IncomingApplication(data)

        # make another one that's broken
        data = ApplicationFixtureFactory.incoming_application()
        del data["bibjson"]["title"]
        with self.assertRaises(DataStructureException):
            ia = IncomingApplication(data)

        # now progressively remove the conditionally required/advanced validation stuff
        #
        # missing identifiers
        data = ApplicationFixtureFactory.incoming_application()
        data["bibjson"]["identifier"] = []
        with self.assertRaises(DataStructureException):
            ia = IncomingApplication(data)

        # no issns specified
        data["bibjson"]["identifier"] = [{"type" : "wibble", "id": "alksdjfas"}]
        with self.assertRaises(DataStructureException):
            ia = IncomingApplication(data)

        # issns the same (but not normalised the same)
        data["bibjson"]["identifier"] = [{"type" : "pissn", "id": "12345678"}, {"type" : "eissn", "id": "1234-5678"}]
        with self.assertRaises(DataStructureException):
            ia = IncomingApplication(data)

        # no homepage link
        data = ApplicationFixtureFactory.incoming_application()
        data["bibjson"]["link"] = [{"type" : "awaypage", "url": "http://there"}]
        with self.assertRaises(DataStructureException):
            ia = IncomingApplication(data)

        # plagiarism detection but no url
        data = ApplicationFixtureFactory.incoming_application()
        data["bibjson"]["plagiarism_detection"] = {"detection" : True}
        with self.assertRaises(DataStructureException):
            ia = IncomingApplication(data)

        # embedded licence but no url
        data = ApplicationFixtureFactory.incoming_application()
        data["bibjson"]["license"][0]["embedded"] = True
        del data["bibjson"]["license"][0]["embedded_example_url"]
        with self.assertRaises(DataStructureException):
            ia = IncomingApplication(data)

        # author copyright and no link
        data = ApplicationFixtureFactory.incoming_application()
        data["bibjson"]["author_copyright"]["copyright"] = True
        del data["bibjson"]["author_copyright"]["url"]
        with self.assertRaises(DataStructureException):
            ia = IncomingApplication(data)

        # author publishing rights and no ling
        data = ApplicationFixtureFactory.incoming_application()
        data["bibjson"]["author_publishing_rights"]["publishing_rights"] = True
        del data["bibjson"]["author_publishing_rights"]["url"]
        with self.assertRaises(DataStructureException):
            ia = IncomingApplication(data)

        # invalid domain in archiving_policy
        data = ApplicationFixtureFactory.incoming_application()
        data["bibjson"]["archiving_policy"]["policy"] = [{"domain" : "my house", "name" : "something"}]
        with self.assertRaises(DataStructureException):
            ia = IncomingApplication(data)

        # invalid name in non-domained policy
        data = ApplicationFixtureFactory.incoming_application()
        data["bibjson"]["archiving_policy"]["policy"] = [{"name" : "something"}]
        with self.assertRaises(DataStructureException):
            ia = IncomingApplication(data)

        # too many keywords
        data = ApplicationFixtureFactory.incoming_application()
        data["bibjson"]["keywords"] = ["one", "two", "three", "four", "five", "six", "seven"]
        with self.assertRaises(DataStructureException):
            ia = IncomingApplication(data)
예제 #43
0
    def test_04_coerce(self):
        data = ApplicationFixtureFactory.incoming_application()

        # first test a load of successes
        data["bibjson"]["country"] = "Bangladesh"
        data["bibjson"]["apc"]["currency"] = "Taka"
        data["bibjson"]["allows_fulltext_indexing"] = "true"
        data["bibjson"]["publication_time"] = "15"
        data["bibjson"]["language"] = ["French", "English"]
        data["bibjson"]["persistent_identifier_scheme"] = ["doi", "HandleS", "something"]
        data["bibjson"]["format"] = ["pdf", "html", "doc"]
        data["bibjson"]["license"][0]["title"] = "cc by"
        data["bibjson"]["license"][0]["type"] = "CC by"
        data["bibjson"]["deposit_policy"] = ["sherpa/romeo", "other"]

        ia = IncomingApplication(data)

        assert ia.bibjson.country == "BD"
        assert ia.bibjson.apc.currency == "BDT"
        assert ia.bibjson.allows_fulltext_indexing is True
        assert isinstance(ia.bibjson.title, unicode)
        assert ia.bibjson.publication_time == 15
        assert "fr" in ia.bibjson.language
        assert "en" in ia.bibjson.language
        assert len(ia.bibjson.language) == 2
        assert ia.bibjson.persistent_identifier_scheme[0] == "DOI"
        assert ia.bibjson.persistent_identifier_scheme[1] == "Handles"
        assert ia.bibjson.persistent_identifier_scheme[2] == "something"
        assert ia.bibjson.format[0] == "PDF"
        assert ia.bibjson.format[1] == "HTML"
        assert ia.bibjson.format[2] == "doc"
        assert ia.bibjson.license[0].title == "CC BY"
        assert ia.bibjson.license[0].type == "CC BY"
        assert ia.bibjson.deposit_policy[0] == "Sherpa/Romeo"
        assert ia.bibjson.deposit_policy[1] == "other"

        # now test some failures
        # invalid country name
        data = ApplicationFixtureFactory.incoming_application()
        data["bibjson"]["country"] = "LandLand"
        with self.assertRaises(DataStructureException):
            ia = IncomingApplication(data)

        # invalid currency name
        data = ApplicationFixtureFactory.incoming_application()
        data["bibjson"]["apc"]["currency"] = "Wonga"
        with self.assertRaises(DataStructureException):
            ia = IncomingApplication(data)

        # an invalid url
        data = ApplicationFixtureFactory.incoming_application()
        data["bibjson"]["apc_url"] = "Two streets down on the left"
        with self.assertRaises(DataStructureException):
            ia = IncomingApplication(data)

        # invalid bool
        data = ApplicationFixtureFactory.incoming_application()
        data["bibjson"]["allows_fulltext_indexing"] = "Yes"
        with self.assertRaises(DataStructureException):
            ia = IncomingApplication(data)

        # invalid int
        data = ApplicationFixtureFactory.incoming_application()
        data["bibjson"]["publication_time"] = "Fifteen"
        with self.assertRaises(DataStructureException):
            ia = IncomingApplication(data)

        # invalid language code
        data = ApplicationFixtureFactory.incoming_application()
        data["bibjson"]["language"] = ["Hagey Pagey"]
        with self.assertRaises(DataStructureException):
            ia = IncomingApplication(data)
예제 #44
0
    def test_04_coerce(self):
        data = ApplicationFixtureFactory.incoming_application()

        # first test a load of successes
        data["bibjson"]["country"] = "Bangladesh"
        data["bibjson"]["apc"]["currency"] = "Taka"
        data["bibjson"]["allows_fulltext_indexing"] = "true"
        data["bibjson"]["publication_time"] = "15"
        data["bibjson"]["language"] = ["French", "English"]
        data["bibjson"]["persistent_identifier_scheme"] = [
            "doi", "HandleS", "something"
        ]
        data["bibjson"]["format"] = ["pdf", "html", "doc"]
        data["bibjson"]["license"][0]["title"] = "cc by"
        data["bibjson"]["license"][0]["type"] = "CC by"
        data["bibjson"]["deposit_policy"] = ["sherpa/romeo", "other"]

        ia = IncomingApplication(data)

        assert ia.bibjson.country == "BD"
        assert ia.bibjson.apc.currency == "BDT"
        assert ia.bibjson.allows_fulltext_indexing is True
        assert isinstance(ia.bibjson.title, str)
        assert ia.bibjson.publication_time == 15
        assert "fr" in ia.bibjson.language
        assert "en" in ia.bibjson.language
        assert len(ia.bibjson.language) == 2
        assert ia.bibjson.persistent_identifier_scheme[0] == "DOI"
        assert ia.bibjson.persistent_identifier_scheme[1] == "Handles"
        assert ia.bibjson.persistent_identifier_scheme[2] == "something"
        assert ia.bibjson.format[0] == "PDF"
        assert ia.bibjson.format[1] == "HTML"
        assert ia.bibjson.format[2] == "doc"
        assert ia.bibjson.license[0].title == "CC BY"
        assert ia.bibjson.license[0].type == "CC BY"
        assert ia.bibjson.deposit_policy[0] == "Sherpa/Romeo"
        assert ia.bibjson.deposit_policy[1] == "other"

        # now test some failures
        # invalid country name
        data = ApplicationFixtureFactory.incoming_application()
        data["bibjson"]["country"] = "LandLand"
        with self.assertRaises(DataStructureException):
            ia = IncomingApplication(data)

        # invalid currency name
        data = ApplicationFixtureFactory.incoming_application()
        data["bibjson"]["apc"]["currency"] = "Wonga"
        with self.assertRaises(DataStructureException):
            ia = IncomingApplication(data)

        # an invalid url
        data = ApplicationFixtureFactory.incoming_application()
        data["bibjson"]["apc_url"] = "Two streets down on the left"
        with self.assertRaises(DataStructureException):
            ia = IncomingApplication(data)

        # invalid bool
        data = ApplicationFixtureFactory.incoming_application()
        data["bibjson"]["allows_fulltext_indexing"] = "Yes"
        with self.assertRaises(DataStructureException):
            ia = IncomingApplication(data)

        # invalid int
        data = ApplicationFixtureFactory.incoming_application()
        data["bibjson"]["publication_time"] = "Fifteen"
        with self.assertRaises(DataStructureException):
            ia = IncomingApplication(data)

        # invalid language code
        data = ApplicationFixtureFactory.incoming_application()
        data["bibjson"]["language"] = ["Hagey Pagey"]
        with self.assertRaises(DataStructureException):
            ia = IncomingApplication(data)