def test_valid_get_request_with_params_filters_correctly(self): url = API_V1_LIST_CREATE_URL.format(self.TEST_MODEL.RESOURCE_NAME) # make a request w/out a filter, so it should have all the fixtures for user_1 no_filter_response = self.client_1.get(url) results = self._get_results_from_response(no_filter_response) for filterable_key in self.filterable_keys: # so if the filter was UUID - show all the values for UUID # or something like quantity, show all the values for quantity filter_values = [result[filterable_key] for result in results] filter_values_unique = set(filter_values) for value in filter_values_unique: request_parameters = {filterable_key: value} filtered_response = self.client_1.get(url, request_parameters) filtered_results = self._get_results_from_response( filtered_response) self.assertEqual(len(filtered_results), filter_values.count(value)) unique_values_in_filtered_results = { item[filterable_key] for item in filtered_results } # if we've filtered on a specific value ... the only unique filtered value should be one self.assertEqual(len(unique_values_in_filtered_results), 1)
def test_all_resources_have_valid_get(self): for resource in VALID_REST_RESOURCES: resource_name = resource.RESOURCE_NAME url = API_V1_LIST_CREATE_URL.format(resource_name) request = self.client_1.get(url) self.assertEqual(request.status_code, 200)
def test_put_parameter_updates_ingredient_uuids_correctly(self): url = API_V1_LIST_CREATE_URL.format(self.TEST_MODEL.RESOURCE_NAME) request = self.client_1.get(url) supplement_uuid = request.data[0]['uuid'] supplement_ingredients = request.data[0]['ingredient_compositions'] supplement_ingredients_uuids = [ item['uuid'] for item in supplement_ingredients ] # if the fixtures ever get modified / messed up, fixtures need to ensure this is greater than one self.assertTrue(len(supplement_ingredients_uuids) > 1) supplement_ingredients_uuid_to_use = supplement_ingredients_uuids[0] data = { 'uuid': supplement_uuid, 'ingredient_compositions': [{ 'uuid': supplement_ingredients_uuid_to_use }] } response = self.client_1.put(url, data, format='json') self.assertEqual(response.data['uuid'], supplement_uuid) self.assertEqual(response.data['ingredient_compositions'][0]['uuid'], supplement_ingredients_uuid_to_use)
def test_put_parameter_when_ingredient_uuid_is_wrong(self): url = API_V1_LIST_CREATE_URL.format(self.TEST_MODEL.RESOURCE_NAME) request = self.client_1.get(url) supplement_uuid = request.data[0]['uuid'] supplement_ingredients = request.data[0]['ingredient_compositions'] supplement_ingredients_uuids = [ item['uuid'] for item in supplement_ingredients ] # if the fixtures ever get modified / messed up, fixtures need to ensure this is greater than one self.assertTrue(len(supplement_ingredients_uuids) > 1) supplement_ingredients_uuid_to_use = supplement_ingredients_uuids[0] data = { 'uuid': supplement_uuid, # ingredient_compositions should be sent as a list of dictionaries, here we send it as a dictionary 'ingredient_compositions': { 'uuid': supplement_ingredients_uuid_to_use } } response = self.client_1.put(url, data, format='json') self.assertEqual(response.status_code, 400)
def test_get_request_work_uuid_filter_works_for_filtering_on_compositions( self): url = API_V1_LIST_CREATE_URL.format(self.TEST_MODEL.RESOURCE_NAME) request = self.client_1.get(url) supplement_ingredients = request.data[0]['ingredient_compositions'] supplement_ingredients_uuids = [ item['uuid'] for item in supplement_ingredients ] supplement_ingredients_uuid = supplement_ingredients_uuids[0] # filter on a composition to see if it returns back uuid_filter_url = '{url}?ingredient_compositions_uuids={supplement_ingredients_uuid}'.format( url=url, supplement_ingredients_uuid=supplement_ingredients_uuids[0]) uuid_request = self.client_1.get(uuid_filter_url) self.assertEqual(uuid_request.status_code, 200) length_of_compositions = len(uuid_request.data) ingredient_composition = IngredientComposition.objects.filter( uuid=supplement_ingredients_uuid) supplements_with_same_composition = Supplement.objects.filter( ingredient_compositions=ingredient_composition) self.assertEqual(length_of_compositions, supplements_with_same_composition.count())
def test_valid_get_request_with_params_filters_correctly(self, request_parameters): url = API_V1_LIST_CREATE_URL.format(self.TEST_MODEL.RESOURCE_NAME) # don't do application/json for single key/value, issue with unpacking request = self.client_1.get(url, request_parameters) # pagination views puts data in "results" if self.PAGINATION: request_data = request.data['results'] else: request_data = request.data for record in request_data: # if we are using a get with request parameters, we want to be certain # that it's correctly filtering on those request_parameters correctly # ie. if I filter for anything with a quantity of 5.0, i only get # 5.0 back! Build a dictionary containing only what was in the # request parameters and compare that it's equal record_values = {key: record[key] for key in request_parameters} # a bit of a hack, but string responses of datetimes can change slightly # based on how zero utc is represented, here bring the object back to datetime # and then isoformat it out again for key in record_values: if 'time' == key[-4:]: returned_time_string = record_values[key] serialized_time_string = dateutil.parser.parse(returned_time_string).isoformat() record_values[key] = serialized_time_string self.assertEqual(record_values, request_parameters) self.assertIsNotNone(request_data) self.assertTrue(len(request_data) > 0) self.assertEqual(request.status_code, 200)
def test_put_request_updates_for_strings(self): """ This test is literally garbage now that I come back and look at this. """ data = self._get_initial_data() # take the first object and update something within it initial_result = data[0] uuid = initial_result.pop('uuid') # make a copied result to update with new parameters copied_result = initial_result.copy() # don't update anything that's a list or a dictionary # also include an ignore list where certain attributes are read-only readonly_parameters = ['supplement_name', 'supplement_uuid', 'description'] copied_result = {k: v for k, v in copied_result.items() if isinstance(v, str) and k not in readonly_parameters} # for any results, if its a string, update them to a constant "aka" api, since we know that's accepted in # tuple validation attributes_to_update = list(copied_result.keys()) string_update_param = 'api' for attribute in attributes_to_update: try: parser.parse(copied_result[attribute]) # don't update datetime variables copied_result.pop(attribute) continue except ValueError: pass copied_result[attribute] = string_update_param # since we updated a few that no longer should be updated, let's refresh this list attributes_to_update = list(copied_result.keys()) # now add uuid back since that's the one value that should be immutable copied_result['uuid'] = uuid url = API_V1_LIST_CREATE_URL.format(self.TEST_MODEL.RESOURCE_NAME) result = self.client_1.put(url, data=copied_result, format='json') for attribute in attributes_to_update: # we are ignoring all the notes field since that can be dynamically generated if attribute == 'notes': continue self.assertEqual(result.data[attribute], string_update_param) # now for safe measure, let's use a get to retrieve the same object via UUID get_response = self._get_initial_data(data={'uuid': uuid}) second_result = get_response[0] for attribute in attributes_to_update: # we are ignoring all the notes field since that can be dynamically generated if attribute == 'notes': continue self.assertEqual(second_result[attribute], string_update_param)
def test_valid_get_request_with_params_filters_correctly(self): url = API_V1_LIST_CREATE_URL.format(self.TEST_MODEL.RESOURCE_NAME) request = self.client_1.get(url) data = request.data first_name = data[0]['name'] request_parameters = {'name': first_name} super().test_valid_get_request_with_params_filters_correctly(request_parameters)
def test_valid_get_request_with_params_filters_correctly(self): url = API_V1_LIST_CREATE_URL.format(self.TEST_MODEL.RESOURCE_NAME) request = self.client_1.get(url) data = request.data first_name = data[0]['name'] request_parameters = {'name': first_name} super().test_valid_get_request_with_params_filters_correctly( request_parameters)
def test_put_request_updates_for_strings(self): data = self._get_initial_data() # take the first object and update something within it initial_result = data[0] uuid = initial_result.pop('uuid') # make a copied result to update with new parameters copied_result = initial_result.copy() # don't update anything that's a list or a dictionary # also include an ignore list where certain attributes are read-only readonly_parameters = ['supplement_name', 'supplement_uuid'] copied_result = { k: v for k, v in copied_result.items() if isinstance(v, str) and k not in readonly_parameters } # for any results, if its a string, update them to a constant "aka" api, since we know that's accepted in # tuple validation attributes_to_update = list(copied_result.keys()) string_update_param = 'api' for attribute in attributes_to_update: try: parser.parse(copied_result[attribute]) # don't update datetime variables copied_result.pop(attribute) continue except ValueError: pass copied_result[attribute] = string_update_param # since we updated a few that no longer should be updated, let's refresh this list attributes_to_update = list(copied_result.keys()) # now add uuid back since that's the one value that should be immutable copied_result['uuid'] = uuid url = API_V1_LIST_CREATE_URL.format(self.TEST_MODEL.RESOURCE_NAME) result = self.client_1.put(url, data=copied_result, format='json') for attribute in attributes_to_update: self.assertEqual(result.data[attribute], string_update_param) # now for safe measure, let's use a get to retrieve the same object via UUID get_response = self._get_initial_data(data={'uuid': uuid}) second_result = get_response[0] for attribute in attributes_to_update: self.assertEqual(second_result[attribute], string_update_param)
def _get_initial_data(self, data=None): url = API_V1_LIST_CREATE_URL.format(self.TEST_MODEL.RESOURCE_NAME) if data: request = self.client_1.get(url, data=data) else: request = self.client_1.get(url) if self.PAGINATION: data = request.data['results'] else: data = request.data return data
def test_valid_get_with_ingredient_uuid(self): url = API_V1_LIST_CREATE_URL.format(self.TEST_MODEL.RESOURCE_NAME) # get the first valid data point result = self.client_1.get(url).data[0] result_ingredient_uuid = result['ingredient']['uuid'] parameters = {'ingredient_uuid': result_ingredient_uuid} data = self.client_1.get(url, parameters).data ingredient_uuids_found = [item['ingredient']['uuid'] for item in data] ingredient_uuids_found = set(ingredient_uuids_found) self.assertEqual(len(ingredient_uuids_found), 1) self.assertEqual(result_ingredient_uuid, ingredient_uuids_found.pop())
def test_event_invalid_supplement_post_request(self): url = API_V1_LIST_CREATE_URL.format(self.TEST_MODEL.RESOURCE_NAME) now = datetime.datetime.now().isoformat() # negative ids don't exist ... so this should fail data = { 'supplement_uuid': -1, 'time': now, } data = json.dumps(data) request = self.client_1.post(url, data, content_type='application/json') self.assertEqual(request.status_code, 400)
def test_valid_get_with_measurement_uuid(self): url = API_V1_LIST_CREATE_URL.format(self.TEST_MODEL.RESOURCE_NAME) # get the first valid data point result = self.client_1.get(url).data[0] result_measurement_uuid = result['measurement']['uuid'] parameters = {'measurement_uuid': result_measurement_uuid} data = self.client_1.get(url, parameters).data measurement_uuids_found = [item['measurement']['uuid'] for item in data] measurement_uuids_found = set(measurement_uuids_found) self.assertEqual(len(measurement_uuids_found), 1) self.assertEqual(result_measurement_uuid, measurement_uuids_found.pop())
def _get_initial_data(self, data=None): url = API_V1_LIST_CREATE_URL.format(self.TEST_MODEL.RESOURCE_NAME) if data: request = self.client_1.get(url, data=data) else: request = self.client_1.get(url) if self.PAGINATION: data = request.data['results'] else: data = request.data return data
def test_event_invalid_supplement_post_request(self): url = API_V1_LIST_CREATE_URL.format(self.TEST_MODEL.RESOURCE_NAME) now = datetime.datetime.now().isoformat() # negative ids don't exist ... so this should fail data = { 'supplement_uuid': -1, 'time': now, } data = json.dumps(data) request = self.client_1.post(url, data, content_type='application/json') self.assertEqual(request.status_code, 400)
def test_put_parameter_updates_supplement_name(self): url = API_V1_LIST_CREATE_URL.format(self.TEST_MODEL.RESOURCE_NAME) request = self.client_1.get(url) supplement_uuid = request.data[0]['uuid'] modified_supplement_name = 'Cheeseburgers' data = {'uuid': supplement_uuid, 'name': modified_supplement_name} response = self.client_1.put(url, data) self.assertEqual(response.data['name'], modified_supplement_name) # for good measure, let's send another request (this time via a GET) to make sure that it's updated correctly uuid_filter = {'uuid': supplement_uuid} response = self.client_1.get(url, uuid_filter) self.assertEqual(response.data[0]['name'], modified_supplement_name)
def test_put_parameter_updates_supplement_name(self): url = API_V1_LIST_CREATE_URL.format(self.TEST_MODEL.RESOURCE_NAME) request = self.client_1.get(url) supplement_uuid = request.data[0]['uuid'] modified_supplement_name = 'Cheeseburgers' data = { 'uuid': supplement_uuid, 'name': modified_supplement_name } response = self.client_1.put(url, data) self.assertEqual(response.data['name'], modified_supplement_name) # for good measure, let's send another request (this time via a GET) to make sure that it's updated correctly uuid_filter = {'uuid': supplement_uuid} response = self.client_1.get(url, uuid_filter) self.assertEqual(response.data[0]['name'], modified_supplement_name)
def test_valid_get_request_for_key_in_response(self, key_check): """ Do a get request, and then check for a certain key type""" # TD - Refactor so key_check is a list of keys ... url = API_V1_LIST_CREATE_URL.format(self.TEST_MODEL.RESOURCE_NAME) request = self.client_1.get(url) # pagination views puts data in "results if self.PAGINATION: request_data = request.data['results'] else: request_data = request.data contains_ids = [item['uuid'] for item in request_data] key_check_items = [item[key_check] for item in request_data] # cannot use assertNone self.assertTrue(len(contains_ids) > 0) self.assertEqual(request.status_code, 200) self.assertTrue(len(key_check_items) > 0)
def test_valid_get_request_for_key_in_response(self, key_check): """ Do a get request, and then check for a certain key type""" # TD - Refactor so key_check is a list of keys ... url = API_V1_LIST_CREATE_URL.format(self.TEST_MODEL.RESOURCE_NAME) request = self.client_1.get(url) # pagination views puts data in "results if self.PAGINATION: request_data = request.data['results'] else: request_data = request.data contains_ids = [item['uuid'] for item in request_data] key_check_items = [item[key_check] for item in request_data] # cannot use assertNone self.assertTrue(len(contains_ids) > 0) self.assertEqual(request.status_code, 200) self.assertTrue(len(key_check_items) > 0)
def test_put_request_with_numbers(self): data = self._get_initial_data() # take the first object and update something within it initial_result = data[0] uuid = initial_result.pop('uuid') # make a copied result to update with new parameters copied_result = initial_result.copy() # get only numbers params, but make sure that the numbers don't include true/false copied_result = { k: v for k, v in copied_result.items() if isinstance(v, numbers.Real) and not isinstance(v, bool) } # for any results, if its a string, update them to a constant attributes_to_update = list(copied_result.keys()) for number_to_try in [5, 10.0]: number_update_param = number_to_try for attribute in attributes_to_update: copied_result[attribute] = number_update_param # now add uuid back since that's the one value that should be immutable copied_result['uuid'] = uuid url = API_V1_LIST_CREATE_URL.format(self.TEST_MODEL.RESOURCE_NAME) result = self.client_1.put(url, data=copied_result, format='json') for attribute in attributes_to_update: self.assertEqual(result.data[attribute], number_update_param, result.data) # now for safe measure, let's use a get to retrieve the same object via UUID get_response = self._get_initial_data(data={'uuid': uuid}) second_result = get_response[0] for attribute in attributes_to_update: self.assertEqual(second_result[attribute], number_update_param)
def test_get_request_work_uuid_filter_works_for_filtering_on_compositions(self): url = API_V1_LIST_CREATE_URL.format(self.TEST_MODEL.RESOURCE_NAME) request = self.client_1.get(url) supplement_ingredients = request.data[0]['ingredient_compositions'] supplement_ingredients_uuids = [item['uuid'] for item in supplement_ingredients] supplement_ingredients_uuid = supplement_ingredients_uuids[0] # filter on a composition to see if it returns back uuid_filter_url = '{url}?ingredient_compositions_uuids={supplement_ingredients_uuid}'.format( url=url, supplement_ingredients_uuid=supplement_ingredients_uuids[0]) uuid_request = self.client_1.get(uuid_filter_url) self.assertEqual(uuid_request.status_code, 200) length_of_compositions = len(uuid_request.data) ingredient_composition = IngredientComposition.objects.filter(uuid=supplement_ingredients_uuid) supplements_with_same_composition = Supplement.objects.filter(ingredient_compositions=ingredient_composition) self.assertEqual(length_of_compositions, supplements_with_same_composition.count())
def test_put_parameter_when_ingredient_uuid_is_wrong(self): url = API_V1_LIST_CREATE_URL.format(self.TEST_MODEL.RESOURCE_NAME) request = self.client_1.get(url) supplement_uuid = request.data[0]['uuid'] supplement_ingredients = request.data[0]['ingredient_compositions'] supplement_ingredients_uuids = [item['uuid'] for item in supplement_ingredients] # if the fixtures ever get modified / messed up, fixtures need to ensure this is greater than one self.assertTrue(len(supplement_ingredients_uuids) > 1) supplement_ingredients_uuid_to_use = supplement_ingredients_uuids[0] data = { 'uuid': supplement_uuid, # ingredient_compositions should be sent as a list of dictionaries, here we send it as a dictionary 'ingredient_compositions': {'uuid': supplement_ingredients_uuid_to_use} } response = self.client_1.put(url, data, format='json') self.assertEqual(response.status_code, 400)
def test_put_parameter_updates_ingredient_uuids_correctly(self): url = API_V1_LIST_CREATE_URL.format(self.TEST_MODEL.RESOURCE_NAME) request = self.client_1.get(url) supplement_uuid = request.data[0]['uuid'] supplement_ingredients = request.data[0]['ingredient_compositions'] supplement_ingredients_uuids = [item['uuid'] for item in supplement_ingredients] # if the fixtures ever get modified / messed up, fixtures need to ensure this is greater than one self.assertTrue(len(supplement_ingredients_uuids) > 1) supplement_ingredients_uuid_to_use = supplement_ingredients_uuids[0] data = { 'uuid': supplement_uuid, 'ingredient_compositions': [{'uuid': supplement_ingredients_uuid_to_use}] } response = self.client_1.put(url, data, format='json') self.assertEqual(response.data['uuid'], supplement_uuid) self.assertEqual(response.data['ingredient_compositions'][0]['uuid'], supplement_ingredients_uuid_to_use)
def test_put_request_with_numbers(self): data = self._get_initial_data() # take the first object and update something within it initial_result = data[0] uuid = initial_result.pop('uuid') # make a copied result to update with new parameters copied_result = initial_result.copy() # get only numbers params, but make sure that the numbers don't include true/false copied_result = {k: v for k, v in copied_result.items() if isinstance(v, numbers.Real) and not isinstance(v, bool)} # for any results, if its a string, update them to a constant attributes_to_update = list(copied_result.keys()) for number_to_try in [5, 10.0]: number_update_param = number_to_try for attribute in attributes_to_update: copied_result[attribute] = number_update_param # now add uuid back since that's the one value that should be immutable copied_result['uuid'] = uuid url = API_V1_LIST_CREATE_URL.format(self.TEST_MODEL.RESOURCE_NAME) result = self.client_1.put(url, data=copied_result, format='json') for attribute in attributes_to_update: self.assertEqual(result.data[attribute], number_update_param, result.data) # now for safe measure, let's use a get to retrieve the same object via UUID get_response = self._get_initial_data(data={'uuid': uuid}) second_result = get_response[0] for attribute in attributes_to_update: self.assertEqual(second_result[attribute], number_update_param)
def test_valid_get_request_with_params_filters_correctly(self): url = API_V1_LIST_CREATE_URL.format(self.TEST_MODEL.RESOURCE_NAME) # make a request w/out a filter, so it should have all the fixtures for user_1 no_filter_response = self.client_1.get(url) results = self._get_results_from_response(no_filter_response) for filterable_key in self.filterable_keys: # so if the filter was UUID - show all the values for UUID # or something like quantity, show all the values for quantity filter_values = [result[filterable_key] for result in results] filter_values_unique = set(filter_values) for value in filter_values_unique: request_parameters = {filterable_key: value} filtered_response = self.client_1.get(url, request_parameters) filtered_results = self._get_results_from_response(filtered_response) self.assertEqual(len(filtered_results), filter_values.count(value)) unique_values_in_filtered_results = {item[filterable_key] for item in filtered_results} # if we've filtered on a specific value ... the only unique filtered value should be one self.assertEqual(len(unique_values_in_filtered_results), 1)
def test_valid_get_request_with_params_filters_correctly( self, request_parameters): url = API_V1_LIST_CREATE_URL.format(self.TEST_MODEL.RESOURCE_NAME) # don't do application/json for single key/value, issue with unpacking request = self.client_1.get(url, request_parameters) # pagination views puts data in "results" if self.PAGINATION: request_data = request.data['results'] else: request_data = request.data for record in request_data: # if we are using a get with request parameters, we want to be certain # that it's correctly filtering on those request_parameters correctly # ie. if I filter for anything with a quantity of 5.0, i only get # 5.0 back! Build a dictionary containing only what was in the # request parameters and compare that it's equal record_values = {key: record[key] for key in request_parameters} # a bit of a hack, but string responses of datetimes can change slightly # based on how zero utc is represented, here bring the object back to datetime # and then isoformat it out again for key in record_values: if 'time' == key[-4:]: returned_time_string = record_values[key] serialized_time_string = dateutil.parser.parse( returned_time_string).isoformat() record_values[key] = serialized_time_string self.assertEqual(record_values, request_parameters) self.assertIsNotNone(request_data) self.assertTrue(len(request_data) > 0) self.assertEqual(request.status_code, 200)
def test_valid_get_on_uuid(self): url = API_V1_LIST_CREATE_URL.format(self.TEST_MODEL.RESOURCE_NAME) request = self.client_1.get(url) # pagination views puts data in "results" if self.PAGINATION: request_data = request.data['results'] else: request_data = request.data # this assumes that the fixtures data will create more than 1 record! self.assertTrue(len(request_data) > 1) # if this isn't true, we'll blindly say this test is passing # when once the amount of objects is greater than 1 in real use cases # it'll be returning the wrong objects instantly request_first_data_point = request_data[0] first_data_point_uuid = request_first_data_point['uuid'] # now make another request, but specifically pick a uuid # it should only return an object with that uuid parameters = {'uuid': first_data_point_uuid} second_request = self.client_1.get(url, parameters) # pagination views puts data in "results if self.PAGINATION: second_request_data = second_request.data['results'] else: second_request_data = second_request.data result = second_request_data[0] result_uuid = result['uuid'] self.assertEqual(first_data_point_uuid, result_uuid) # if we filter by uuid, it's unique there should only be one! self.assertEqual(len(second_request_data), 1)
def test_valid_get_on_uuid(self): url = API_V1_LIST_CREATE_URL.format(self.TEST_MODEL.RESOURCE_NAME) request = self.client_1.get(url) # pagination views puts data in "results" if self.PAGINATION: request_data = request.data['results'] else: request_data = request.data # this assumes that the fixtures data will create more than 1 record! self.assertTrue(len(request_data) > 1) # if this isn't true, we'll blindly say this test is passing # when once the amount of objects is greater than 1 in real use cases # it'll be returning the wrong objects instantly request_first_data_point = request_data[0] first_data_point_uuid = request_first_data_point['uuid'] # now make another request, but specifically pick a uuid # it should only return an object with that uuid parameters = {'uuid': first_data_point_uuid} second_request = self.client_1.get(url, parameters) # pagination views puts data in "results if self.PAGINATION: second_request_data = second_request.data['results'] else: second_request_data = second_request.data result = second_request_data[0] result_uuid = result['uuid'] self.assertEqual(first_data_point_uuid, result_uuid) # if we filter by uuid, it's unique there should only be one! self.assertEqual(len(second_request_data), 1)
def test_empty_post_request(self): url = API_V1_LIST_CREATE_URL.format(self.TEST_MODEL.RESOURCE_NAME) request = self.client_1.post(url) self.assertEqual(request.status_code, 400)
def test_get_request(self): url = API_V1_LIST_CREATE_URL.format(self.TEST_MODEL.RESOURCE_NAME) request = self.client_1.get(url) self.assertTrue(len(request.data) > 0) self.assertEqual(request.status_code, 200)
def test_post_request(self): url = API_V1_LIST_CREATE_URL.format(self.TEST_MODEL.RESOURCE_NAME) request = self.client_1.put(url) # expected to fail, this is a read-only set of stuff self.assertEqual(request.status_code, 405)
def test_put_request_with_invalid_uuid_will_fail(self): url = API_V1_LIST_CREATE_URL.format(self.TEST_MODEL.RESOURCE_NAME) uuid = uuid4() crap_response = self.client_1.put(url, {'uuid': uuid}) self.assertEqual(crap_response.status_code, 404)
def test_put_empty_data_returns_404(self): url = API_V1_LIST_CREATE_URL.format(self.TEST_MODEL.RESOURCE_NAME) result = self.client_1.put(url) self.assertEqual(result.status_code, 404)
def test_put_request_with_invalid_uuid_will_fail(self): url = API_V1_LIST_CREATE_URL.format(self.TEST_MODEL.RESOURCE_NAME) uuid = uuid4() crap_response = self.client_1.put(url, {'uuid': uuid}) self.assertEqual(crap_response.status_code, 404)
def test_get_request(self): url = API_V1_LIST_CREATE_URL.format(self.TEST_MODEL.RESOURCE_NAME) request = self.client_1.get(url) self.assertTrue(len(request.data) > 0) self.assertEqual(request.status_code, 200)
def test_fake_resources_404(self): url = API_V1_LIST_CREATE_URL.format('fake_made_up_resource') request = self.client_1.get(url) self.assertEqual(request.status_code, 404)
def test_put_empty_data_returns_404(self): url = API_V1_LIST_CREATE_URL.format(self.TEST_MODEL.RESOURCE_NAME) result = self.client_1.put(url) self.assertEqual(result.status_code, 404)
def test_empty_post_request(self): url = API_V1_LIST_CREATE_URL.format(self.TEST_MODEL.RESOURCE_NAME) request = self.client_1.post(url) self.assertEqual(request.status_code, 400)
def test_post_request(self): url = API_V1_LIST_CREATE_URL.format(self.TEST_MODEL.RESOURCE_NAME) request = self.client_1.put(url) # expected to fail, this is a read-only set of stuff self.assertEqual(request.status_code, 405)
def _make_get_request(self, client): url = API_V1_LIST_CREATE_URL.format(self.TEST_MODEL.RESOURCE_NAME) request = client.get(url) return request
def _make_post_request(self, client, request_parameters): url = API_V1_LIST_CREATE_URL.format(self.TEST_MODEL.RESOURCE_NAME) data = json.dumps(request_parameters) request = client.post(url, data=data, content_type='application/json') return request
def setUpTestData(cls): cls.url = API_V1_LIST_CREATE_URL.format(cls.TEST_MODEL.RESOURCE_NAME) cls.create_user_fixtures() super().setUpTestData()