def test_change_admin_code(self): api = Api() client = Client() (location, obj) = api.resources['message'].create_test_resource() old_code = obj.admin_code new_code = "GDFGACVAS" patch_data = {"admin_code": new_code} response = client.patch(location, patch_data, parse='json') obj = obj.__class__.objects.get(id=obj.id) self.assertEqual(old_code, obj.admin_code) print location
def test_change_admin_code(self): api = Api() client = Client() (location, obj) = api.resources['message'].create_test_resource() old_code = obj.admin_code new_code = "GDFGACVAS" patch_data = { "admin_code" : new_code } response = client.patch(location, patch_data, parse='json') obj = obj.__class__.objects.get(id=obj.id) self.assertEqual(old_code, obj.admin_code) print location
def multi_readonly_patch(self, resource_name, resource, field_name, field): client = Client() api = Api() if field.readonly and resource.can_create() : #Create a resource to modify it (location, obj) = resource.create_test_resource() bad_value = UnderResourceFields.generate_field_test_data(field) #authenticate to be allowed to modify the resource post_data = api.resources['userprofile'].get_example_data('POST') client.login(username=post_data['email'], password=post_data['password']) #attempt to PATCH patch_data = {} patch_data[field_name] = bad_value patch_response = client.patch(location,patch_data, parse='json') get_response = client.get(location, parse='json') msg = "%s.%s can be changed by a PATCH request even though it's readonly!." msg %= (resource_name, field_name) self.assertNotEqual(get_response.data.get(field_name,None), bad_value,msg)
def multi_readonly_patch(self, resource_name, resource, field_name, field): client = Client() api = Api() if field.readonly and resource.can_create(): #Create a resource to modify it (location, obj) = resource.create_test_resource() bad_value = UnderResourceFields.generate_field_test_data(field) #authenticate to be allowed to modify the resource post_data = api.resources['userprofile'].get_example_data('POST') client.login(username=post_data['email'], password=post_data['password']) #attempt to PATCH patch_data = {} patch_data[field_name] = bad_value patch_response = client.patch(location, patch_data, parse='json') get_response = client.get(location, parse='json') msg = "%s.%s can be changed by a PATCH request even though it's readonly!." msg %= (resource_name, field_name) self.assertNotEqual(get_response.data.get(field_name, None), bad_value, msg)