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)
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
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)
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
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()
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()
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)
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)
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)
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)
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"
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))
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))
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"
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)
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)
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
def delete_article(article_id): ArticlesCrudApi.delete(article_id, current_user) return no_content()
@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"])
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"
def retrieve_article(article_id): a = ArticlesCrudApi.retrieve(article_id, current_user) return jsonify_models(a)
@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))
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"
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
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))