Esempio n. 1
0
    def test_07_retrieve_article_fail(self):
        # set up all the bits we need
        # add a journal to the account
        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)
        journal.save()
        time.sleep(1)

        data = ArticleFixtureFactory.make_article_source()
        data['admin']['in_doaj'] = False
        ap = models.Article(**data)
        ap.save()
        time.sleep(1)

        # should fail when no user and in_doaj is False
        with self.assertRaises(Api401Error):
            a = ArticlesCrudApi.retrieve(ap.id, None)

        # wrong user
        account = models.Account()
        account.set_id("asdklfjaioefwe")
        with self.assertRaises(Api404Error):
            a = ArticlesCrudApi.retrieve(ap.id, account)

        # non-existant article
        account = models.Account()
        account.set_id(ap.id)
        with self.assertRaises(Api404Error):
            a = ArticlesCrudApi.retrieve("ijsidfawefwefw", account)
Esempio n. 2
0
    def test_10_delete_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)
        journal.save()
        time.sleep(1)

        data = ArticleFixtureFactory.make_article_source()

        # 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)

        # now delete it
        ArticlesCrudApi.delete(a.id, account)

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

        ap = models.Article.pull(a.id)
        assert ap is None
Esempio n. 3
0
    def test_07_retrieve_article_fail(self):
        # set up all the bits we need
        # add a journal to the account
        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)
        journal.save()
        time.sleep(1)

        data = ArticleFixtureFactory.make_article_source()
        data['admin']['in_doaj'] = False
        ap = models.Article(**data)
        ap.save()
        time.sleep(1)

        # should fail when no user and in_doaj is False
        with self.assertRaises(Api401Error):
            a = ArticlesCrudApi.retrieve(ap.id, None)

        # wrong user
        account = models.Account()
        account.set_id("asdklfjaioefwe")
        with self.assertRaises(Api404Error):
            a = ArticlesCrudApi.retrieve(ap.id, account)

        # non-existant article
        account = models.Account()
        account.set_id(ap.id)
        with self.assertRaises(Api404Error):
            a = ArticlesCrudApi.retrieve("ijsidfawefwefw", account)
Esempio n. 4
0
    def test_10_delete_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)
        journal.save()
        time.sleep(1)

        data = ArticleFixtureFactory.make_article_source()

        # 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)

        # now delete it
        ArticlesCrudApi.delete(a.id, account)

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

        ap = models.Article.pull(a.id)
        assert ap is None
Esempio n. 5
0
File: api_v1.py Progetto: DOAJ/doaj
def update_article(article_id):
    # get the data from the request
    try:
        data = json.loads(request.data)
    except:
        raise Api400Error("Supplied data was not valid JSON")

    # delegate to the API implementation
    ArticlesCrudApi.update(article_id, data, current_user)

    # respond with a suitable No Content successful response
    return no_content()
Esempio n. 6
0
def update_article(article_id):
    # get the data from the request
    try:
        data = json.loads(request.data.decode("utf-8"))
    except:
        raise Api400Error("Supplied data was not valid JSON")

    # delegate to the API implementation
    ArticlesCrudApi.update(article_id, data, current_user)

    # respond with a suitable No Content successful response
    return no_content()
Esempio n. 7
0
    def test_03_create_article_fail(self):
        # if the account is dud
        with self.assertRaises(Api401Error):
            data = ArticleFixtureFactory.make_article_source()
            a = ArticlesCrudApi.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 = ArticlesCrudApi.create(data, account)
Esempio n. 8
0
    def test_03_create_article_fail(self):
        # if the account is dud
        with self.assertRaises(Api401Error):
            data = ArticleFixtureFactory.make_article_source()
            a = ArticlesCrudApi.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 = ArticlesCrudApi.create(data, account)
Esempio n. 9
0
    def test_11_delete_article_fail(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)
        journal.save()
        time.sleep(1)

        data = ArticleFixtureFactory.make_article_source()

        # 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)

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

        # without an account
        with self.assertRaises(Api401Error):
            ArticlesCrudApi.delete(a.id, None)

        # with the wrong account
        account.set_id("other")
        with self.assertRaises(Api404Error):
            ArticlesCrudApi.delete(a.id, account)

        # on the wrong id
        account.set_id("test")
        with self.assertRaises(Api404Error):
            ArticlesCrudApi.delete("adfasdfhwefwef", account)
Esempio n. 10
0
    def test_11_delete_article_fail(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)
        journal.save()
        time.sleep(1)

        data = ArticleFixtureFactory.make_article_source()

        # 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)

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

        # without an account
        with self.assertRaises(Api401Error):
            ArticlesCrudApi.delete(a.id, None)

        # with the wrong account
        account.set_id("other")
        with self.assertRaises(Api404Error):
            ArticlesCrudApi.delete(a.id, account)

        # on the wrong id
        account.set_id("test")
        with self.assertRaises(Api404Error):
            ArticlesCrudApi.delete("adfasdfhwefwef", account)
Esempio n. 11
0
    def test_06_retrieve_article_success(self):
        # set up all the bits we need
        # add a journal to the account
        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)
        journal.save()
        time.sleep(1)

        data = ArticleFixtureFactory.make_article_source()
        ap = models.Article(**data)
        ap.save()
        time.sleep(1)

        # call retrieve on the object with a valid user
        a = ArticlesCrudApi.retrieve(ap.id, account)

        # call retrieve with no user (will return if in_doaj is True)
        a = ArticlesCrudApi.retrieve(ap.id, None)

        # check that we got back the object we expected
        assert isinstance(a, OutgoingArticleDO)
        assert a.id == ap.id
        assert a.bibjson.journal.start_page == '3', a.bibjson.journal.start_page
        assert a.bibjson.journal.end_page == '21'
        assert a.bibjson.journal.volume == '1'
        assert a.bibjson.journal.number == '99'
        assert a.bibjson.journal.publisher == 'The Publisher', a.bibjson(
        ).publisher
        assert a.bibjson.journal.title == 'The Title'
        assert a.bibjson.journal.license[0].title == "CC BY"
        assert a.bibjson.journal.license[0].type == "CC BY"
        assert a.bibjson.journal.license[0].url == "http://license.example.com"
        assert a.bibjson.journal.license[0].version == "1.0"
        assert a.bibjson.journal.license[0].open_access == True
        assert a.bibjson.journal.language == ["EN", "FR"]
        assert a.bibjson.journal.country == "US"
Esempio n. 12
0
File: api_v1.py Progetto: DOAJ/doaj
def create_article():
    # get the data from the request
    try:
        data = json.loads(request.data)
    except:
        raise Api400Error("Supplied data was not valid JSON")

    # delegate to the API implementation
    a = ArticlesCrudApi.create(data, current_user._get_current_object())

    # respond with a suitable Created response
    return created(a, url_for("api_v1.retrieve_article", article_id=a.id))
Esempio n. 13
0
def create_article():
    # get the data from the request
    try:
        data = json.loads(request.data.decode("utf-8"))
    except:
        raise Api400Error("Supplied data was not valid JSON")

    # delegate to the API implementation
    a = ArticlesCrudApi.create(data, current_user._get_current_object())

    # respond with a suitable Created response
    return created(a, url_for("api_v1.retrieve_article", article_id=a.id))
Esempio n. 14
0
    def test_06_retrieve_article_success(self):
        # set up all the bits we need
        # add a journal to the account
        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)
        journal.save()
        time.sleep(1)

        data = ArticleFixtureFactory.make_article_source()
        ap = models.Article(**data)
        ap.save()
        time.sleep(1)

        # call retrieve on the object with a valid user
        a = ArticlesCrudApi.retrieve(ap.id, account)

        # call retrieve with no user (will return if in_doaj is True)
        a = ArticlesCrudApi.retrieve(ap.id, None)

        # check that we got back the object we expected
        assert isinstance(a, OutgoingArticleDO)
        assert a.id == ap.id
        assert a.bibjson.journal.start_page == '3', a.bibjson.journal.start_page
        assert a.bibjson.journal.end_page == '21'
        assert a.bibjson.journal.volume == '1'
        assert a.bibjson.journal.number == '99'
        assert a.bibjson.journal.publisher == 'The Publisher', a.bibjson().publisher
        assert a.bibjson.journal.title == 'The Title'
        assert a.bibjson.journal.license[0].title == "CC BY"
        assert a.bibjson.journal.license[0].type == "CC BY"
        assert a.bibjson.journal.license[0].url == "http://license.example.com"
        assert a.bibjson.journal.license[0].version == "1.0"
        assert a.bibjson.journal.license[0].open_access == True
        assert a.bibjson.journal.language == ["EN", "FR"]
        assert a.bibjson.journal.country == "US"
Esempio n. 15
0
    def test_09_update_article_fail(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)
        journal.save()
        time.sleep(1)

        data = ArticleFixtureFactory.make_article_source()

        # 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_article_source()
        data["bibjson"]["title"] = "An updated title"

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

        # without an account
        with self.assertRaises(Api401Error):
            ArticlesCrudApi.update(a.id, data, None)

        # with the wrong account
        account.set_id("other")
        with self.assertRaises(Api404Error):
            ArticlesCrudApi.update(a.id, data, account)

        # on the wrong id
        account.set_id("test")
        with self.assertRaises(Api404Error):
            ArticlesCrudApi.update("adfasdfhwefwef", data, account)
Esempio n. 16
0
    def test_09_update_article_fail(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)
        journal.save()
        time.sleep(1)

        data = ArticleFixtureFactory.make_article_source()

        # 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_article_source()
        data["bibjson"]["title"] = "An updated title"

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

        # without an account
        with self.assertRaises(Api401Error):
            ArticlesCrudApi.update(a.id, data, None)

        # with the wrong account
        account.set_id("other")
        with self.assertRaises(Api404Error):
            ArticlesCrudApi.update(a.id, data, account)

        # on the wrong id
        account.set_id("test")
        with self.assertRaises(Api404Error):
            ArticlesCrudApi.update("adfasdfhwefwef", data, account)
Esempio n. 17
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
Esempio n. 18
0
File: api_v1.py Progetto: DOAJ/doaj
def delete_article(article_id):
    ArticlesCrudApi.delete(article_id, current_user)
    return no_content()
Esempio n. 19
0
File: api_v1.py Progetto: DOAJ/doaj
@blueprint.route("/applications/<application_id>", methods=["DELETE"])
@api_key_required
@write_required(api=True)
@swag(swag_summary='Delete an application <span class="red">[Authenticated, not public]</span>', swag_spec=ApplicationsCrudApi.delete_swag())  # must be applied after @api_key_(optional|required) decorators. They don't preserve func attributes.
def delete_application(application_id):
    ApplicationsCrudApi.delete(application_id, current_user._get_current_object())
    return no_content()


#########################################
# Article CRUD API

@blueprint.route("/articles", methods=["POST"])
@api_key_required
@write_required(api=True)
@swag(swag_summary='Create an article <span class="red">[Authenticated, not public]</span>', swag_spec=ArticlesCrudApi.create_swag())  # must be applied after @api_key_(optional|required) decorators. They don't preserve func attributes.
def create_article():
    # get the data from the request
    try:
        data = json.loads(request.data)
    except:
        raise Api400Error("Supplied data was not valid JSON")

    # delegate to the API implementation
    a = ArticlesCrudApi.create(data, current_user._get_current_object())

    # respond with a suitable Created response
    return created(a, url_for("api_v1.retrieve_article", article_id=a.id))


@blueprint.route("/articles/<article_id>", methods=["GET"])
Esempio n. 20
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"
Esempio n. 21
0
File: api_v1.py Progetto: DOAJ/doaj
def retrieve_article(article_id):
    a = ArticlesCrudApi.retrieve(article_id, current_user)
    return jsonify_models(a)
Esempio n. 22
0
@api_key_required
@write_required(api=True)
@swag(swag_summary='Delete an application <span class="red">[Authenticated, not public]</span>', swag_spec=ApplicationsCrudApi.delete_swag())  # must be applied after @api_key_(optional|required) decorators. They don't preserve func attributes.
@analytics.sends_ga_event(GA_CATEGORY, GA_ACTIONS.get('delete_application', 'Delete application'), record_value_of_which_arg='application_id')
def delete_application(application_id):
    ApplicationsCrudApi.delete(application_id, current_user._get_current_object())
    return no_content()


#########################################
# Article CRUD API

@blueprint.route("/articles", methods=["POST"])
@api_key_required
@write_required(api=True)
@swag(swag_summary='Create an article <span class="red">[Authenticated, not public]</span>', swag_spec=ArticlesCrudApi.create_swag())  # must be applied after @api_key_(optional|required) decorators. They don't preserve func attributes.
@analytics.sends_ga_event(GA_CATEGORY, GA_ACTIONS.get('create_article', 'Create article'))
def create_article():
    # get the data from the request
    try:
        data = json.loads(request.data.decode("utf-8"))
    except:
        raise Api400Error("Supplied data was not valid JSON")

    # delegate to the API implementation
    a = ArticlesCrudApi.create(data, current_user._get_current_object())

    # respond with a suitable Created response
    return created(a, url_for("api_v1.retrieve_article", article_id=a.id))

Esempio n. 23
0
def delete_article(article_id):
    ArticlesCrudApi.delete(article_id, current_user)
    return no_content()
Esempio n. 24
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"
Esempio n. 25
0
def retrieve_article(article_id):
    a = ArticlesCrudApi.retrieve(article_id, current_user)
    return jsonify_models(a)
Esempio n. 26
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
Esempio n. 27
0
    ApplicationsCrudApi.delete(application_id,
                               current_user._get_current_object())
    return no_content()


#########################################
# Article CRUD API


@blueprint.route("/articles", methods=["POST"])
@api_key_required
@write_required(api=True)
@swag(
    swag_summary=
    'Create an article <span class="red">[Authenticated, not public]</span>',
    swag_spec=ArticlesCrudApi.create_swag()
)  # must be applied after @api_key_(optional|required) decorators. They don't preserve func attributes.
def create_article():
    # get the data from the request
    try:
        data = json.loads(request.data)
    except:
        raise Api400Error("Supplied data was not valid JSON")

    # delegate to the API implementation
    a = ArticlesCrudApi.create(data, current_user._get_current_object())

    # respond with a suitable Created response
    return created(a, url_for("api_v1.retrieve_article", article_id=a.id))