Exemplo n.º 1
0
    def test_02_create_duplicate_articles(self):
        # set up all the bits we need - 10 articles
        data = ArticleFixtureFactory.make_incoming_api_article()
        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("*****@*****.**")

        # add a journal to the account
        journal = models.Journal(**JournalFixtureFactory.make_journal_source(
            in_doaj=True))
        journal.set_owner(account.id)
        journal.save()

        time.sleep(2)

        # call create on the object (which will save it to the index)
        with self.assertRaises(Api400Error):
            ids = ArticlesBulkApi.create(dataset, account)

        time.sleep(2)

        with self.assertRaises(ESMappingMissingError):
            all_articles = models.Article.all()
Exemplo n.º 2
0
    def test_03_create_articles_fail(self):
        # if the account is dud
        with self.assertRaises(Api401Error):
            data = ArticleFixtureFactory.make_incoming_api_article()
            dataset = [data] * 10
            ids = ArticlesBulkApi.create(dataset, None)

        # check that the index is empty, as none of them should have been made
        all = [x for x in models.Article.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("*****@*****.**")
            # add a journal to the account
            journal = models.Journal(
                **JournalFixtureFactory.make_journal_source(in_doaj=True))
            journal.set_owner(account.id)
            journal.save()
            time.sleep(1)
            dataset = dataset[:5] + [{"some": {"junk": "data"}}] + dataset[5:]
            ids = ArticlesBulkApi.create(dataset, account)

        # check that the index is empty, as none of them should have been made
        all = [x for x in models.Article.iterall()]
        assert len(all) == 0
Exemplo n.º 3
0
    def test_03_create_articles_fail(self):
        # if the account is dud
        with self.assertRaises(Api401Error):
            data = ArticleFixtureFactory.make_incoming_api_article()
            dataset = [data] * 10
            ids = ArticlesBulkApi.create(dataset, None)

        # check that the index is empty, as none of them should have been made
        all = [x for x in models.Article.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("*****@*****.**")
            # add a journal to the account
            journal = models.Journal(**JournalFixtureFactory.make_journal_source(in_doaj=True))
            journal.set_owner(account.id)
            journal.save()
            time.sleep(1)
            dataset = dataset[:5] + [{"some" : {"junk" : "data"}}] + dataset[5:]
            ids = ArticlesBulkApi.create(dataset, account)

        # check that the index is empty, as none of them should have been made
        all = [x for x in models.Article.iterall()]
        assert len(all) == 0
Exemplo n.º 4
0
    def test_02_create_duplicate_articles(self):
        # set up all the bits we need - 10 articles
        data = ArticleFixtureFactory.make_incoming_api_article()
        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("*****@*****.**")

        # add a journal to the account
        journal = models.Journal(**JournalFixtureFactory.make_journal_source(in_doaj=True))
        journal.set_owner(account.id)
        journal.save()

        time.sleep(2)

        # call create on the object (which will save it to the index)
        with self.assertRaises(Api400Error):
            ids = ArticlesBulkApi.create(dataset, account)

        time.sleep(2)

        with self.assertRaises(ESMappingMissingError):
            all_articles = models.Article.all()
Exemplo n.º 5
0
    def test_01_create_articles_success(self):
        def find_dict_in_list(lst, key, value):
            for i, dic in enumerate(lst):
                if dic[key] == value:
                    return i
            return -1

        # set up all the bits we need - 10 articles
        dataset = []
        for i in range(1, 11):
            data = ArticleFixtureFactory.make_incoming_api_article()
            # change the DOI and fulltext URLs to escape duplicate detection
            # and try with multiple articles
            doi_ix = find_dict_in_list(data['bibjson']['identifier'], 'type',
                                       'doi')
            if doi_ix == -1:
                data['bibjson']['identifier'].append({"type": "doi"})
            data['bibjson']['identifier'][doi_ix][
                'id'] = '10.0000/SOME.IDENTIFIER.{0}'.format(i)

            fulltext_url_ix = find_dict_in_list(data['bibjson']['link'],
                                                'type', 'fulltext')
            if fulltext_url_ix == -1:
                data['bibjson']['link'].append({"type": "fulltext"})
            data['bibjson']['link'][fulltext_url_ix][
                'url'] = 'http://www.example.com/article_{0}'.format(i)

            dataset.append(deepcopy(data))

        # create an account that we'll do the create as
        account = models.Account()
        account.set_id("test")
        account.set_name("Tester")
        account.set_email("*****@*****.**")

        # add a journal to the account
        journal = models.Journal(**JournalFixtureFactory.make_journal_source(
            in_doaj=True))
        journal.set_owner(account.id)
        journal.save()

        time.sleep(2)

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

        # check that we got the right number of ids back
        assert len(ids) == 10
        assert len(list(set(ids))) == 10, len(list(
            set(ids)))  # are they actually 10 unique IDs?

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

        # check that each id was actually created
        for id in ids:
            s = models.Article.pull(id)
            assert s is not None
Exemplo n.º 6
0
    def test_05_delete_articles_fail(self):
        # set up all the bits we need
        dataset = []
        for i in range(10):
            data = ArticleFixtureFactory.make_incoming_api_article(
                doi="10.123/test/" + str(i),
                fulltext="http://example.com/" + str(i))
            dataset.append(data)

        # create the main account we're going to work as
        article_owner = models.Account()
        article_owner.set_id("test")
        article_owner.set_name("Tester")
        article_owner.set_email("*****@*****.**")
        # create another account which will own the articles so the one
        # above will be "another user" trying to delete our precious articles.
        somebody_else = models.Account()
        somebody_else.set_id("somebody_else")
        somebody_else.set_name("Somebody Else")
        somebody_else.set_email("*****@*****.**")
        # add a journal to the article owner account to create that link
        # between account and articles
        journal = models.Journal(**JournalFixtureFactory.make_journal_source(
            in_doaj=True))
        journal.set_owner(article_owner.id)
        journal.save()
        time.sleep(1)

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

        # 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):
            ArticlesBulkApi.delete(ids, None)

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

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

        with self.assertRaises(Api400Error):
            ArticlesBulkApi.delete(ids, article_owner)
Exemplo n.º 7
0
    def test_01_create_articles_success(self):
        def find_dict_in_list(lst, key, value):
            for i, dic in enumerate(lst):
                if dic[key] == value:
                    return i
            return -1

        # set up all the bits we need - 10 articles
        dataset = []
        for i in range(1, 11):
            data = ArticleFixtureFactory.make_incoming_api_article()
            # change the DOI and fulltext URLs to escape duplicate detection
            # and try with multiple articles
            doi_ix = find_dict_in_list(data['bibjson']['identifier'], 'type', 'doi')
            if doi_ix == -1:
                data['bibjson']['identifier'].append({"type" : "doi"})
            data['bibjson']['identifier'][doi_ix]['id'] = '10.0000/SOME.IDENTIFIER.{0}'.format(i)
            
            fulltext_url_ix = find_dict_in_list(data['bibjson']['link'], 'type', 'fulltext')
            if fulltext_url_ix == -1:
                data['bibjson']['link'].append({"type" : "fulltext"})
            data['bibjson']['link'][fulltext_url_ix]['url'] = 'http://www.example.com/article_{0}'.format(i)

            dataset.append(deepcopy(data))

        # create an account that we'll do the create as
        account = models.Account()
        account.set_id("test")
        account.set_name("Tester")
        account.set_email("*****@*****.**")

        # add a journal to the account
        journal = models.Journal(**JournalFixtureFactory.make_journal_source(in_doaj=True))
        journal.set_owner(account.id)
        journal.save()

        time.sleep(2)

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

        # check that we got the right number of ids back
        assert len(ids) == 10
        assert len(list(set(ids))) == 10, len(list(set(ids)))  # are they actually 10 unique IDs?

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

        # check that each id was actually created
        for id in ids:
            s = models.Article.pull(id)
            assert s is not None
Exemplo n.º 8
0
    def test_05_delete_articles_fail(self):
        # set up all the bits we need
        dataset = []
        for i in range(10):
            data = ArticleFixtureFactory.make_incoming_api_article(doi="10.123/test/" + str(i), fulltext="http://example.com/" + str(i))
            dataset.append(data)

        # create the main account we're going to work as
        article_owner = models.Account()
        article_owner.set_id("test")
        article_owner.set_name("Tester")
        article_owner.set_email("*****@*****.**")
        # create another account which will own the articles so the one
        # above will be "another user" trying to delete our precious articles.
        somebody_else = models.Account()
        somebody_else.set_id("somebody_else")
        somebody_else.set_name("Somebody Else")
        somebody_else.set_email("*****@*****.**")
        # add a journal to the article owner account to create that link
        # between account and articles
        journal = models.Journal(**JournalFixtureFactory.make_journal_source(in_doaj=True))
        journal.set_owner(article_owner.id)
        journal.save()
        time.sleep(1)

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

        # 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):
            ArticlesBulkApi.delete(ids, None)

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

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

        with self.assertRaises(Api400Error):
            ArticlesBulkApi.delete(ids, article_owner)
Exemplo n.º 9
0
    def test_04_delete_article_success(self):
        # set up all the bits we need
        dataset = []
        for i in range(10):
            data = ArticleFixtureFactory.make_incoming_api_article(
                doi="10.123/test/" + str(i),
                fulltext="http://example.com/" + str(i))
            dataset.append(data)

        # create the account we're going to work as
        account = models.Account()
        account.set_id("test")
        account.set_name("Tester")
        account.set_email("*****@*****.**")
        # add a journal to the account
        journal = models.Journal(**JournalFixtureFactory.make_journal_source(
            in_doaj=True))
        journal.set_owner(account.id)
        journal.save()
        time.sleep(1)

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

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

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

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

        for id in dels:
            ap = models.Article.pull(id)
            assert ap is None
        for id in ids[5:]:
            ap = models.Article.pull(id)
            assert ap is not None
Exemplo n.º 10
0
    def test_04_delete_article_success(self):
        # set up all the bits we need
        dataset = []
        for i in range(10):
            data = ArticleFixtureFactory.make_incoming_api_article(doi="10.123/test/" + str(i), fulltext="http://example.com/" + str(i))
            dataset.append(data)

        # create the account we're going to work as
        account = models.Account()
        account.set_id("test")
        account.set_name("Tester")
        account.set_email("*****@*****.**")
        # add a journal to the account
        journal = models.Journal(**JournalFixtureFactory.make_journal_source(in_doaj=True))
        journal.set_owner(account.id)
        journal.save()
        time.sleep(1)

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

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

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

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

        for id in dels:
            ap = models.Article.pull(id)
            assert ap is None
        for id in ids[5:]:
            ap = models.Article.pull(id)
            assert ap is not None
Exemplo n.º 11
0
    def test_06_test_via_endpoint(self):
        """ Use a request context to test the API via the route """

        # set up all the bits we need
        dataset = []
        for i in range(10):
            data = ArticleFixtureFactory.make_incoming_api_article(
                doi="10.123/test/" + str(i),
                fulltext="http://example.com/" + str(i))
            dataset.append(data)

        # create the main account we're going to work as
        article_owner = models.Account()
        article_owner.set_id("test")
        article_owner.set_name("Tester")
        article_owner.set_email("*****@*****.**")
        article_owner.generate_api_key()
        article_owner.add_role('publisher')
        article_owner.add_role('api')
        article_owner.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 article_owner.api_key != somebody_else.api_key

        # add a journal to the article owner account to create that link between account and articles
        journal = models.Journal(**JournalFixtureFactory.make_journal_source(
            in_doaj=True))
        journal.set_owner(article_owner.id)
        journal.save(blocking=True)

        with self.app_test.test_request_context():
            with self.app_test.test_client() as t_client:

                # Bulk create
                # The wrong owner can't create articles
                resp = t_client.post(url_for('api_v1.bulk_article_create',
                                             api_key=somebody_else.api_key),
                                     data=json.dumps(dataset))
                assert resp.status_code == 400

                # But the correct owner can create articles
                resp = t_client.post(url_for('api_v1.bulk_article_create',
                                             api_key=article_owner.api_key),
                                     data=json.dumps(dataset))
                assert resp.status_code == 201
                reply = json.loads(resp.data)
                assert len(reply) == len(dataset)
                first_art = reply.pop()
                assert first_art['status'] == 'created'
                # Check we actually created new records
                time.sleep(1)
                assert len(models.Article.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_article_delete',
                                               api_key=article_owner.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 articles.
                assert len(models.Article.all()) == 1
                # And our other user isn't allowed to delete the remaining one.
                resp = t_client.delete(url_for('api_v1.bulk_article_delete',
                                               api_key=somebody_else.api_key),
                                       data=json.dumps([first_art['id']]))
                assert resp.status_code == 400
Exemplo n.º 12
0
    def test_02_create_article_success(self):
        # set up all the bits we need
        data = ArticleFixtureFactory.make_incoming_api_article()
        data['bibjson']['journal']['publisher'] = 'Wrong Publisher'
        data['bibjson']['journal']['title'] = 'Wrong Journal Title'
        data['bibjson']['journal']['license'] = [{
            "title": "BAD LICENSE",
            "type": "GOOD DOG",
            "url": "Lala land",
            "version": "XI",
            "open_access": False
        }]
        data['bibjson']['journal']['language'] = [
            "ES", "These aren't even", "lang codes"
        ]
        data['bibjson']['journal']['country'] = "This better not work"

        account = models.Account()
        account.set_id("test")
        account.set_name("Tester")
        account.set_email("*****@*****.**")

        # add a journal to the account
        journal = models.Journal(**JournalFixtureFactory.make_journal_source(
            in_doaj=True))
        journal.set_owner(account.id)
        # make sure non-overwritable journal metadata matches the article
        journal.bibjson().title = "The Title"
        journal.bibjson().publisher = "The Publisher"
        journal.bibjson().set_license(
            **{
                "license_title": "CC BY",
                "license_type": "CC BY",
                "url": "http://license.example.com",
                "version": "1.0",
                "open_access": True,
            })
        journal.bibjson().country = "US"
        journal.bibjson().set_language(["EN", "FR"])
        journal.save()
        time.sleep(1)

        # call create on the object (which will save it to the index)
        a = ArticlesCrudApi.create(data, account)

        # check that it got created with the right properties
        assert isinstance(a, models.Article)
        assert a.id != "abcdefghijk_article"
        assert a.created_date != "2000-01-01T00:00:00Z"
        assert a.last_updated != "2000-01-01T00:00:00Z"
        # allowed to overwrite these
        assert a.bibjson().start_page == '3'
        assert a.bibjson().end_page == '21'
        assert a.bibjson().volume == '1'
        assert a.bibjson().number == '99'
        # but none of these - these should all be the same as the original article in the index
        assert a.bibjson().publisher == 'The Publisher', a.bibjson().publisher
        assert a.bibjson().journal_title == 'The Title'
        assert a.bibjson().get_journal_license() == {
            "title": "CC BY",
            "type": "CC BY",
            "url": "http://license.example.com",
            "version": "1.0",
            "open_access": True,
        }
        assert a.bibjson().journal_language == ["EN", "FR"]
        assert a.bibjson().journal_country == "US"

        time.sleep(1)

        am = models.Article.pull(a.id)
        assert am is not None
Exemplo n.º 13
0
    def test_08_update_article_success(self):
        # set up all the bits we need
        account = models.Account()
        account.set_id('test')
        account.set_name("Tester")
        account.set_email("*****@*****.**")
        journal = models.Journal(**JournalFixtureFactory.make_journal_source(
            in_doaj=True))
        journal.set_owner(account.id)
        # make sure non-overwritable journal metadata matches the article
        journal.bibjson().title = "The Title"
        journal.bibjson().publisher = "The Publisher"
        journal.bibjson().set_license(
            **{
                "license_title": "CC BY",
                "license_type": "CC BY",
                "url": "http://license.example.com",
                "version": "1.0",
                "open_access": True,
            })
        journal.bibjson().country = "US"
        journal.bibjson().set_language(["EN", "FR"])
        journal.save()
        time.sleep(1)

        data = ArticleFixtureFactory.make_incoming_api_article()

        # call create on the object (which will save it to the index)
        a = ArticlesCrudApi.create(data, account)

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

        # get a copy of the newly created version for use in assertions later
        created = models.Article.pull(a.id)

        # now make an updated version of the object
        data = ArticleFixtureFactory.make_incoming_api_article()
        data["bibjson"]["title"] = "An updated title"
        # change things we are allowed to change
        data['bibjson']['journal']['start_page'] = 4
        data['bibjson']['journal']['end_page'] = 22
        data['bibjson']['journal']['volume'] = 2
        data['bibjson']['journal']['number'] = '100'

        # change things we are not allowed to change
        data['bibjson']['journal']['publisher'] = 'Wrong Publisher'
        data['bibjson']['journal']['title'] = 'Wrong Journal Title'
        data['bibjson']['journal']['license'] = [{
            "title": "BAD LICENSE",
            "type": "GOOD DOG",
            "url": "Lala land",
            "version": "XI",
            "open_access": False
        }]
        data['bibjson']['journal']['language'] = [
            "ES", "These aren't even", "lang codes"
        ]
        data['bibjson']['journal']['country'] = "This better not work"

        # call update on the object
        a2 = ArticlesCrudApi.update(a.id, data, account)
        assert a2 != a

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

        # get a copy of the updated version
        updated = models.Article.pull(a.id)

        # now check the properties to make sure the update took
        assert updated.bibjson().title == "An updated title"
        assert updated.created_date == created.created_date
        assert updated.last_updated != created.last_updated

        # allowed to overwrite these
        assert updated.bibjson().start_page == '4'
        assert updated.bibjson().end_page == '22'
        assert updated.bibjson().volume == '2'
        assert updated.bibjson().number == '100'
        # but none of these - these should all be the same as the original article in the index
        assert updated.bibjson().publisher == 'The Publisher', updated.bibjson(
        ).publisher
        assert updated.bibjson().journal_title == 'The Title'
        assert updated.bibjson().get_journal_license() == {
            "title": "CC BY",
            "type": "CC BY",
            "url": "http://license.example.com",
            "version": "1.0",
            "open_access": True,
        }
        assert updated.bibjson().journal_language == ["EN", "FR"]
        assert updated.bibjson().journal_country == "US"
Exemplo n.º 14
0
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"
KEY = "d117ad1b35b94469b3dae09c29bfed55"

# make the dataset
# if you use the dataset = [ArticleFixtureFactory.make_incoming_api_article()] * 10
# syntax it'll just create 10 references to the same dict, so by changing one (later)
# you'll change all of them
dataset = []
for i in range(0, 10):
    dataset.append(deepcopy(ArticleFixtureFactory.make_incoming_api_article()))

for i, d in enumerate(dataset):
    # This will fail if you already have articles with
    # fulltext URL http://www.example.org/article{var} or
    # or DOI 10.000{var}/SOME.IDENTIFIER
    # attached to them due to duplication detection in CRUD API Article create.
    d['bibjson']['identifier'][0] = {
        'id':
        '10.000{var}/test/SOME.TOTALLY.DIFFERENT.IDENTIFIER'.format(var=i),
        'type': 'doi'
    }
    d['bibjson']['link'][0] = {
        'content_type': 'HTML',
        'type': 'fulltext',
        'url': 'http://www.ohdear.org/article{var}'.format(var=i)
Exemplo n.º 15
0
    def test_02_create_article_success(self):
        # set up all the bits we need
        data = ArticleFixtureFactory.make_incoming_api_article()
        data['bibjson']['journal']['publisher'] = 'Wrong Publisher'
        data['bibjson']['journal']['title'] = 'Wrong Journal Title'
        data['bibjson']['journal']['license'] = [
            {
                "title" : "BAD LICENSE",
                "type" : "GOOD DOG",
                "url" : "Lala land",
                "version" : "XI",
                "open_access": False
            }
        ]
        data['bibjson']['journal']['language'] = ["ES", "These aren't even", "lang codes"]
        data['bibjson']['journal']['country'] = "This better not work"

        account = models.Account()
        account.set_id("test")
        account.set_name("Tester")
        account.set_email("*****@*****.**")

        # add a journal to the account
        journal = models.Journal(**JournalFixtureFactory.make_journal_source(in_doaj=True))
        journal.set_owner(account.id)
        # make sure non-overwritable journal metadata matches the article
        journal.bibjson().title = "The Title"
        journal.bibjson().publisher = "The Publisher"
        journal.bibjson().set_license(
            **{
                "license_title" : "CC BY",
                "license_type" : "CC BY",
                "url" : "http://license.example.com",
                "version" : "1.0",
                "open_access": True,
            }
        )
        journal.bibjson().country = "US"
        journal.bibjson().set_language(["EN", "FR"])
        journal.save()
        time.sleep(1)

        # call create on the object (which will save it to the index)
        a = ArticlesCrudApi.create(data, account)

        # check that it got created with the right properties
        assert isinstance(a, models.Article)
        assert a.id != "abcdefghijk_article"
        assert a.created_date != "2000-01-01T00:00:00Z"
        assert a.last_updated != "2000-01-01T00:00:00Z"
        # allowed to overwrite these
        assert a.bibjson().start_page == '3'
        assert a.bibjson().end_page == '21'
        assert a.bibjson().volume == '1'
        assert a.bibjson().number == '99'
        # but none of these - these should all be the same as the original article in the index
        assert a.bibjson().publisher == 'The Publisher', a.bibjson().publisher
        assert a.bibjson().journal_title == 'The Title'
        assert a.bibjson().get_journal_license() == {
            "title" : "CC BY",
            "type" : "CC BY",
            "url" : "http://license.example.com",
            "version" : "1.0",
            "open_access": True,
        }
        assert a.bibjson().journal_language == ["EN", "FR"]
        assert a.bibjson().journal_country == "US"

        time.sleep(1)

        am = models.Article.pull(a.id)
        assert am is not None
Exemplo n.º 16
0
    def test_08_update_article_success(self):
        # set up all the bits we need
        account = models.Account()
        account.set_id('test')
        account.set_name("Tester")
        account.set_email("*****@*****.**")
        journal = models.Journal(**JournalFixtureFactory.make_journal_source(in_doaj=True))
        journal.set_owner(account.id)
        # make sure non-overwritable journal metadata matches the article
        journal.bibjson().title = "The Title"
        journal.bibjson().publisher = "The Publisher"
        journal.bibjson().set_license(
            **{
                "license_title" : "CC BY",
                "license_type" : "CC BY",
                "url" : "http://license.example.com",
                "version" : "1.0",
                "open_access": True,
            }
        )
        journal.bibjson().country = "US"
        journal.bibjson().set_language(["EN", "FR"])
        journal.save()
        time.sleep(1)

        data = ArticleFixtureFactory.make_incoming_api_article()

        # call create on the object (which will save it to the index)
        a = ArticlesCrudApi.create(data, account)

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

        # get a copy of the newly created version for use in assertions later
        created = models.Article.pull(a.id)

        # now make an updated version of the object
        data = ArticleFixtureFactory.make_incoming_api_article()
        data["bibjson"]["title"] = "An updated title"
        # change things we are allowed to change
        data['bibjson']['journal']['start_page'] = 4
        data['bibjson']['journal']['end_page'] = 22
        data['bibjson']['journal']['volume'] = 2
        data['bibjson']['journal']['number'] = '100'

        # change things we are not allowed to change
        data['bibjson']['journal']['publisher'] = 'Wrong Publisher'
        data['bibjson']['journal']['title'] = 'Wrong Journal Title'
        data['bibjson']['journal']['license'] = [
            {
                "title" : "BAD LICENSE",
                "type" : "GOOD DOG",
                "url" : "Lala land",
                "version" : "XI",
                "open_access": False
            }
        ]
        data['bibjson']['journal']['language'] = ["ES", "These aren't even", "lang codes"]
        data['bibjson']['journal']['country'] = "This better not work"

        # call update on the object
        a2 = ArticlesCrudApi.update(a.id, data, account)
        assert a2 != a

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

        # get a copy of the updated version
        updated = models.Article.pull(a.id)

        # now check the properties to make sure the update took
        assert updated.bibjson().title == "An updated title"
        assert updated.created_date == created.created_date
        assert updated.last_updated != created.last_updated

        # allowed to overwrite these
        assert updated.bibjson().start_page == '4'
        assert updated.bibjson().end_page == '22'
        assert updated.bibjson().volume == '2'
        assert updated.bibjson().number == '100'
        # but none of these - these should all be the same as the original article in the index
        assert updated.bibjson().publisher == 'The Publisher', updated.bibjson().publisher
        assert updated.bibjson().journal_title == 'The Title'
        assert updated.bibjson().get_journal_license() == {
            "title" : "CC BY",
            "type" : "CC BY",
            "url" : "http://license.example.com",
            "version" : "1.0",
            "open_access": True,
        }
        assert updated.bibjson().journal_language == ["EN", "FR"]
        assert updated.bibjson().journal_country == "US"