def test_03_delete_application_success(self): # set up all the bits we need data = ApplicationFixtureFactory.incoming_application() del data["admin"]["current_journal"] dataset = [data] * 10 # create the account we're going to work as account = models.Account() account.set_id("test") account.set_name("Tester") account.set_email("*****@*****.**") account.add_role("publisher") # call create on the objects (which will save it to the index) ids = ApplicationsBulkApi.create(dataset, account) # let the index catch up time.sleep(2) # now delete half of them dels = ids[:5] ApplicationsBulkApi.delete(dels, account) # let the index catch up time.sleep(2) for id in dels: ap = models.Suggestion.pull(id) assert ap is None for id in ids[5:]: ap = models.Suggestion.pull(id) assert ap is not None
def bulk_application_delete(): # get the data from the request try: data = json.loads(request.data.decode("utf-8")) except: raise Api400Error("Supplied data was not valid JSON") ApplicationsBulkApi.delete(data, current_user._get_current_object()) return no_content()
def bulk_application_delete(): # get the data from the request try: data = json.loads(request.data) except: raise Api400Error("Supplied data was not valid JSON") ApplicationsBulkApi.delete(data, current_user._get_current_object()) return no_content()
def test_01_create_applications_success(self): # set up all the bits we need - 10 applications data = ApplicationFixtureFactory.incoming_application() del data["admin"]["current_journal"] dataset = [data] * 10 # create an account that we'll do the create as account = models.Account() account.set_id("test") account.set_name("Tester") account.set_email("*****@*****.**") # call create on the object (which will save it to the index) ids = ApplicationsBulkApi.create(dataset, account) # check that we got the right number of ids back assert len(ids) == 10 # let the index catch up time.sleep(2) # check that each id was actually created for id in ids: s = models.Suggestion.pull(id) assert s is not None
def test_04_delete_applications_fail(self): # set up all the bits we need data = ApplicationFixtureFactory.incoming_application() del data["admin"]["current_journal"] dataset = [data] * 10 # create the account we're going to work as account = models.Account() account.set_id("test") account.set_name("Tester") account.set_email("*****@*****.**") # call create on the objects (which will save it to the index) ids = ApplicationsBulkApi.create(dataset, account) # let the index catch up time.sleep(2) # call delete on the object in various context that will fail # without an account with self.assertRaises(Api401Error): ApplicationsBulkApi.delete(ids, None) # with the wrong account account.set_id("other") with self.assertRaises(Api400Error): ApplicationsBulkApi.delete(ids, account) # on the wrong id ids.append("adfasdfhwefwef") account.set_id("test") with self.assertRaises(Api400Error): ApplicationsBulkApi.delete(ids, account) # on one with a disallowed workflow status created = models.Suggestion.pull(ids[3]) created.set_application_status(constants.APPLICATION_STATUS_ACCEPTED) created.save() time.sleep(2) with self.assertRaises(Api400Error): ApplicationsBulkApi.delete(ids, account)
def test_02_create_applications_fail(self): # if the account is dud with self.assertRaises(Api401Error): data = ApplicationFixtureFactory.incoming_application() del data["admin"]["current_journal"] dataset = [data] * 10 ids = ApplicationsBulkApi.create(dataset, None) # check that the index is empty, as none of them should have been made all = [x for x in models.Suggestion.iterall()] assert len(all) == 0 # if the data is bust with self.assertRaises(Api400Error): account = models.Account() account.set_id("test") account.set_name("Tester") account.set_email("*****@*****.**") dataset = dataset[:5] + [{"some": {"junk": "data"}}] + dataset[5:] ids = ApplicationsBulkApi.create(dataset, account) # check that the index is empty, as none of them should have been made all = [x for x in models.Suggestion.iterall()] assert len(all) == 0
def test_02_create_applications_fail(self): # if the account is dud with self.assertRaises(Api401Error): data = ApplicationFixtureFactory.incoming_application() del data["admin"]["current_journal"] dataset = [data] * 10 ids = ApplicationsBulkApi.create(dataset, None) # check that the index is empty, as none of them should have been made all = [x for x in models.Suggestion.iterall()] assert len(all) == 0 # if the data is bust with self.assertRaises(Api400Error): account = models.Account() account.set_id("test") account.set_name("Tester") account.set_email("*****@*****.**") dataset = dataset[:5] + [{"some" : {"junk" : "data"}}] + dataset[5:] ids = ApplicationsBulkApi.create(dataset, account) # check that the index is empty, as none of them should have been made all = [x for x in models.Suggestion.iterall()] assert len(all) == 0
def bulk_application_create(): # 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 ids = ApplicationsBulkApi.create(data, current_user._get_current_object()) # get all the locations for the ids inl = [] for id in ids: inl.append((id, url_for("api_v1.retrieve_application", application_id=id))) # respond with a suitable Created response return bulk_created(inl)
def bulk_application_create(): # 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 ids = ApplicationsBulkApi.create(data, current_user._get_current_object()) # get all the locations for the ids inl = [] for id in ids: inl.append((id, url_for("api_v1.retrieve_application", application_id=id))) # respond with a suitable Created response return bulk_created(inl)
@blueprint.route('/journals/<journal_id>', methods=['GET']) @api_key_optional @swag(swag_summary='Retrieve a journal by ID', swag_spec=JournalsCrudApi.retrieve_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('retrieve_journal', 'Retrieve journal'), record_value_of_which_arg='journal_id') def retrieve_journal(journal_id): return jsonify_data_object(JournalsCrudApi.retrieve(journal_id, current_user)) ######################################### # Application Bulk API @blueprint.route("/bulk/applications", methods=["POST"]) @api_key_required @write_required(api=True) @swag(swag_summary='Create applications in bulk <span class="red">[Authenticated, not public]</span>', swag_spec=ApplicationsBulkApi.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('bulk_application_create', 'Bulk application create')) def bulk_application_create(): # 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 ids = ApplicationsBulkApi.create(data, current_user._get_current_object()) # get all the locations for the ids inl = [] for id in ids: inl.append((id, url_for("api_v1.retrieve_application", application_id=id)))
# Journal R API @blueprint.route('/journals/<journal_id>', methods=['GET']) @api_key_optional @swag(swag_summary='Retrieve a journal by ID', swag_spec=JournalsCrudApi.retrieve_swag()) # must be applied after @api_key_(optional|required) decorators. They don't preserve func attributes. def retrieve_journal(journal_id): return jsonify_data_object(JournalsCrudApi.retrieve(journal_id, current_user)) ######################################### # Application Bulk API @blueprint.route("/bulk/applications", methods=["POST"]) @api_key_required @write_required(api=True) @swag(swag_summary='Create applications in bulk <span class="red">[Authenticated, not public]</span>', swag_spec=ApplicationsBulkApi.create_swag()) # must be applied after @api_key_(optional|required) decorators. They don't preserve func attributes. def bulk_application_create(): # 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 ids = ApplicationsBulkApi.create(data, current_user._get_current_object()) # get all the locations for the ids inl = [] for id in ids: inl.append((id, url_for("api_v1.retrieve_application", application_id=id)))
def retrieve_journal(journal_id): return jsonify_data_object( JournalsCrudApi.retrieve(journal_id, current_user)) ######################################### # Application Bulk API @blueprint.route("/bulk/applications", methods=["POST"]) @api_key_required @write_required(api=True) @swag( swag_summary= 'Create applications in bulk <span class="red">[Authenticated, not public]</span>', swag_spec=ApplicationsBulkApi.create_swag() ) # must be applied after @api_key_(optional|required) decorators. They don't preserve func attributes. def bulk_application_create(): # 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 ids = ApplicationsBulkApi.create(data, current_user) # get all the locations for the ids inl = [] for id in ids: inl.append(