def test_invalid_editing_of_photo_returns_400(self): """Test invalid data (bad request) should be handled appropriately.""" data = { 'id': 5000000, 'image': 'http://localhost:8000/noimage.jee', 'name': 'the new picture', 'image_effect': "" } rv = self.client.put('/api/edit_photo/', data=data) self.assertEqual(rv.status_code, status.HTTP_400_BAD_REQUEST) # test invalid image effect: return a 400 bad request if invalid self.name = 'test.png' self.image = File(open('static/test.jpg', 'rb')) self.created_image = Photo(image=self.image, name=self.name, user=self.user) self.created_image.save() response = self.client.get(reverse('editor:photos')) self.assertEqual(response.status_code, status.HTTP_200_OK) data = { 'id': self.created_image.id, 'image': self.created_image.image, 'name': "the new picture", 'image_effect': "http://localhost:8000/noimage.jee" } rv = self.client.put('/api/edit_photo/', data=data) self.assertEqual(rv.status_code, status.HTTP_400_BAD_REQUEST)
class ImageEffectsTestCase(APITestCase): """Test case for Image effects.""" def setUp(self): """Set up a mock for opening actual file url.""" self.patcher = patch('urllib2.urlopen') self.urlopen_mock = self.patcher.start() self.username = fake.user_name() self.password = fake.password() self.photo_name = 'test.png' self.image_url = 'static/test.png' self.user = User.objects.create_user(username=self.username, password=self.password) self.user = authenticate(username=self.username, password=self.password) self.client.login(username=self.username, password=self.password) def test_application_of_filters(self): """Test that filters can be applied to images.""" self.name = 'test.png' self.image = File(open('static/test.png', 'rb')) self.created_image = Photo(image=self.image, name=self.name, user=self.user) self.created_image.save() data = {'imageID': self.created_image.id} self.urlopen_mock.return_value = MockResponse(data) response = self.client.get(reverse('editor:filters'), data) self.assertEqual(response.status_code, status.HTTP_200_OK) def test_image_effects_deletion(self): """Test deletion of image effects from the server.""" self.name = 'test.png' self.image = File(open('static/test.png', 'rb')) self.created_image = Photo(image=self.image, name=self.name, user=self.user) self.created_image.save() # try deletion of no-existent filters returns 204 no content data = {'id': 1000, 'image_url': ''} response = self.client.post(reverse('editor:remove_effects'), data) self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT) data = {'imageID': self.created_image.id} self.urlopen_mock.return_value = MockResponse(data) response = self.client.get(reverse('editor:filters'), data) self.assertEqual(response.status_code, status.HTTP_200_OK) # actual deletion data = {'id': self.created_image.pk, 'image_url': ''} rv = self.client.post(reverse('editor:remove_effects'), data) self.assertEqual(rv.status_code, status.HTTP_200_OK) def tearDown(self): """Tear down.""" self.patcher.stop()
def test_getting_photo_by_id(self): """Test a given photo can be retrieved using the photoID.""" self.created_image = Photo(image=self.image, name=self.photo_name, user=self.user) self.created_image.save() rv = self.client.get('/api/edit_photo/?id={}'.format( self.created_image.id)) self.assertEqual(rv.status_code, status.HTTP_200_OK) self.assertEqual(rv.data.get('name'), self.created_image.name)
def test_application_of_filters(self): """Test that filters can be applied to images.""" self.name = 'test.png' self.image = File(open('static/test.png', 'rb')) self.created_image = Photo(image=self.image, name=self.name, user=self.user) self.created_image.save() data = {'imageID': self.created_image.id} self.urlopen_mock.return_value = MockResponse(data) response = self.client.get(reverse('editor:filters'), data) self.assertEqual(response.status_code, status.HTTP_200_OK)
def test_user_can_delete_photo(self): """Test a given photo can be deleted.""" self.name = 'test.png' self.image = File(open('static/test.jpg', 'rb')) self.created_image = Photo(image=self.image, name=self.name, user=self.user) self.created_image.save() response = self.client.get(reverse('editor:photos')) self.assertEqual(response.status_code, status.HTTP_200_OK) rv = self.client.delete('/api/edit_photo/?id={}'.format( self.created_image.id)) self.assertEqual(rv.status_code, status.HTTP_204_NO_CONTENT)
def test_invalid_editing_of_photo_returns_400(self): """Test invalid data (bad request) should be handled appropriately.""" data = { 'id': 5000000, 'image': 'http://localhost:8000/noimage.jee', 'name': 'the new picture', 'image_effect': "" } rv = self.client.put('/api/edit_photo/', data=data) self.assertEqual(rv.status_code, status.HTTP_400_BAD_REQUEST) # test invalid image effect: return a 400 bad request if invalid self.name = 'test.png' self.image = File(open('static/test.jpg', 'rb')) self.created_image = Photo( image=self.image, name=self.name, user=self.user) self.created_image.save() response = self.client.get(reverse('editor:photos')) self.assertEqual(response.status_code, status.HTTP_200_OK) data = { 'id': self.created_image.id, 'image': self.created_image.image, 'name': "the new picture", 'image_effect': "http://localhost:8000/noimage.jee" } rv = self.client.put('/api/edit_photo/', data=data) self.assertEqual(rv.status_code, status.HTTP_400_BAD_REQUEST)
def test_getting_photo_by_id(self): """Test a given photo can be retrieved using the photoID.""" self.created_image = Photo( image=self.image, name=self.photo_name, user=self.user) self.created_image.save() rv = self.client.get( '/api/edit_photo/?id={}'.format(self.created_image.id)) self.assertEqual(rv.status_code, status.HTTP_200_OK) self.assertEqual(rv.data.get('name'), self.created_image.name)
def setUp(self): """Set up for testing.""" self.username = fake.user_name() self.password = fake.password() self.photo_name = 'test.png' image = Image.open('static/' + self.photo_name) self.image = pil_to_django(image, 'png') self.user = User.objects.create_user(username=self.username, password=self.password) self.created_image = Photo(image=self.image, name=self.photo_name, user=self.user)
def test_invalid_photo_name_during_photo_renaming_returns_400(self): """Test for invalid name on a photo rename request.""" self.name = 'test.png' self.image = File(open('static/test.jpg', 'rb')) self.created_image = Photo(image=self.image, name=self.name, user=self.user) self.created_image.save() response = self.client.get(reverse('editor:photos')) self.assertEqual(response.status_code, status.HTTP_200_OK) # invalid data random_things = Random.new() invalid_name = random_things.read(600) data = { 'id': self.created_image.id, 'name': invalid_name, # this is not a valid name 'image_effect': "" } rv = self.client.put('/api/edit_photo/', data=data) self.assertEqual(rv.status_code, status.HTTP_400_BAD_REQUEST)
def test_image_effects_deletion(self): """Test deletion of image effects from the server.""" self.name = 'test.png' self.image = File(open('static/test.png', 'rb')) self.created_image = Photo(image=self.image, name=self.name, user=self.user) self.created_image.save() # try deletion of no-existent filters returns 204 no content data = {'id': 1000, 'image_url': ''} response = self.client.post(reverse('editor:remove_effects'), data) self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT) data = {'imageID': self.created_image.id} self.urlopen_mock.return_value = MockResponse(data) response = self.client.get(reverse('editor:filters'), data) self.assertEqual(response.status_code, status.HTTP_200_OK) # actual deletion data = {'id': self.created_image.pk, 'image_url': ''} rv = self.client.post(reverse('editor:remove_effects'), data) self.assertEqual(rv.status_code, status.HTTP_200_OK)
def test_user_can_delete_photo(self): """Test a given photo can be deleted.""" self.name = 'test.png' self.image = File(open('static/test.jpg', 'rb')) self.created_image = Photo( image=self.image, name=self.name, user=self.user) self.created_image.save() response = self.client.get(reverse('editor:photos')) self.assertEqual(response.status_code, status.HTTP_200_OK) rv = self.client.delete( '/api/edit_photo/?id={}'.format(self.created_image.id)) self.assertEqual(rv.status_code, status.HTTP_204_NO_CONTENT)
def test_application_of_filters(self): """Test that filters can be applied to images.""" self.name = 'test.png' self.image = File(open('static/test.png', 'rb')) self.created_image = Photo( image=self.image, name=self.name, user=self.user) self.created_image.save() data = { 'imageID': self.created_image.id } self.urlopen_mock.return_value = MockResponse(data) response = self.client.get(reverse('editor:filters'), data) self.assertEqual(response.status_code, status.HTTP_200_OK)
def test_user_can_edit_photo(self): """Test a given photo can be edited.""" self.name = 'test.png' self.image = File(open('static/test.jpg', 'rb')) self.created_image = Photo(image=self.image, name=self.name, user=self.user) self.created_image.save() response = self.client.get(reverse('editor:photos')) self.assertEqual(response.status_code, status.HTTP_200_OK) data = { 'id': self.created_image.id, 'image': self.created_image.image, 'image_effect': "", 'name': 'the new picture', } rv = self.client.put('/api/edit_photo/', data=data) self.assertEqual(rv.status_code, status.HTTP_200_OK) # test actual data of edited photo rv = self.client.get('/api/edit_photo/?id={}'.format( self.created_image.id)) self.assertContains(rv, data['name'], status_code=200) # Test saving the image effect for a given photo. data = { 'id': self.created_image.id, 'image': self.created_image.image, 'image_effect': "http://localhost:8000/" + self.image_url, 'name': 'the new picture', } rv = self.client.put('/api/edit_photo/', data=data) self.assertEqual(rv.status_code, status.HTTP_200_OK) # test actual data of edited photo rv = self.client.get('/api/edit_photo/?id={}'.format( self.created_image.id)) self.assertContains(rv, "effects/test.png", status_code=200)
def setUp(self): """Set up user data.""" self.username = fake.user_name() self.password = fake.password() self.photo_name = 'test.png' self.image_url = 'static/test.png' self.user = User.objects.create_user(username=self.username, password=self.password) self.user = authenticate(username=self.username, password=self.password) self.client.login(username=self.username, password=self.password) # get the image ready for loading self.image = Image.frombytes('L', (100, 100), "\x00" * 100 * 100) self.image = pil_to_django(self.image, 'png') self.image_create = Photo(image=self.image, name=self.photo_name, user=self.user).save()
def test_invalid_photo_name_during_photo_renaming_returns_400(self): """Test for invalid name on a photo rename request.""" self.name = 'test.png' self.image = File(open('static/test.jpg', 'rb')) self.created_image = Photo( image=self.image, name=self.name, user=self.user) self.created_image.save() response = self.client.get(reverse('editor:photos')) self.assertEqual(response.status_code, status.HTTP_200_OK) # invalid data random_things = Random.new() invalid_name = random_things.read(600) data = { 'id': self.created_image.id, 'name': invalid_name, # this is not a valid name 'image_effect': "" } rv = self.client.put('/api/edit_photo/', data=data) self.assertEqual(rv.status_code, status.HTTP_400_BAD_REQUEST)
def test_user_can_edit_photo(self): """Test a given photo can be edited.""" self.name = 'test.png' self.image = File(open('static/test.jpg', 'rb')) self.created_image = Photo( image=self.image, name=self.name, user=self.user) self.created_image.save() response = self.client.get(reverse('editor:photos')) self.assertEqual(response.status_code, status.HTTP_200_OK) data = { 'id': self.created_image.id, 'image': self.created_image.image, 'image_effect': "", 'name': 'the new picture', } rv = self.client.put('/api/edit_photo/', data=data) self.assertEqual(rv.status_code, status.HTTP_200_OK) # test actual data of edited photo rv = self.client.get( '/api/edit_photo/?id={}'.format(self.created_image.id)) self.assertContains(rv, data['name'], status_code=200) # Test saving the image effect for a given photo. data = { 'id': self.created_image.id, 'image': self.created_image.image, 'image_effect': "http://localhost:8000/" + self.image_url, 'name': 'the new picture', } rv = self.client.put('/api/edit_photo/', data=data) self.assertEqual(rv.status_code, status.HTTP_200_OK) # test actual data of edited photo rv = self.client.get( '/api/edit_photo/?id={}'.format(self.created_image.id)) self.assertContains(rv, "effects/test.png", status_code=200)
def test_image_effects_deletion(self): """Test deletion of image effects from the server.""" self.name = 'test.png' self.image = File(open('static/test.png', 'rb')) self.created_image = Photo( image=self.image, name=self.name, user=self.user) self.created_image.save() # try deletion of no-existent filters returns 204 no content data = {'id': 1000, 'image_url': ''} response = self.client.post(reverse('editor:remove_effects'), data) self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT) data = { 'imageID': self.created_image.id } self.urlopen_mock.return_value = MockResponse(data) response = self.client.get(reverse('editor:filters'), data) self.assertEqual(response.status_code, status.HTTP_200_OK) # actual deletion data = {'id': self.created_image.pk, 'image_url': ''} rv = self.client.post(reverse('editor:remove_effects'), data) self.assertEqual(rv.status_code, status.HTTP_200_OK)
class UserPhotoTestCase(APITestCase): """Test user login.""" def setUp(self): """Set up user data.""" self.username = fake.user_name() self.password = fake.password() self.photo_name = 'test.png' self.image_url = 'static/test.png' self.user = User.objects.create_user(username=self.username, password=self.password) self.user = authenticate(username=self.username, password=self.password) self.client.login(username=self.username, password=self.password) # get the image ready for loading self.image = Image.frombytes('L', (100, 100), "\x00" * 100 * 100) self.image = pil_to_django(self.image, 'png') self.image_create = Photo(image=self.image, name=self.photo_name, user=self.user).save() def tearDown(self): """Tear down all things test_user.""" del self.user del self.image_create @patch('editor.models.Photo.save', MagicMock(name="save")) def test_user_photo_creation(self): """Test photo creation by a given user.""" image_name = 'test.png' with open(self.image_url, 'rb') as image: data = {'image': image, 'name': image_name} response = self.client.post(reverse('editor:photos'), data) image.close() self.assertEqual(response.status_code, status.HTTP_201_CREATED) self.assertEqual(response.data.get('name'), image_name) def test_photo_retrievals(self): """Test user can retrieve their photos.""" image_name = 'test.png' with open(self.image_url, 'rb') as image: data = {'image': image, 'name': image_name} response = self.client.post(reverse('editor:photos'), data) image.close() response = self.client.get(reverse('editor:photos')) self.assertEqual(response.status_code, status.HTTP_200_OK) # test data retrieved data = [i.values() for i in response.data] self.assertIn(u'{}'.format(self.photo_name), data[0]) def test_getting_photo_by_id(self): """Test a given photo can be retrieved using the photoID.""" self.created_image = Photo(image=self.image, name=self.photo_name, user=self.user) self.created_image.save() rv = self.client.get('/api/edit_photo/?id={}'.format( self.created_image.id)) self.assertEqual(rv.status_code, status.HTTP_200_OK) self.assertEqual(rv.data.get('name'), self.created_image.name) def test_user_can_edit_photo(self): """Test a given photo can be edited.""" self.name = 'test.png' self.image = File(open('static/test.jpg', 'rb')) self.created_image = Photo(image=self.image, name=self.name, user=self.user) self.created_image.save() response = self.client.get(reverse('editor:photos')) self.assertEqual(response.status_code, status.HTTP_200_OK) data = { 'id': self.created_image.id, 'image': self.created_image.image, 'image_effect': "", 'name': 'the new picture', } rv = self.client.put('/api/edit_photo/', data=data) self.assertEqual(rv.status_code, status.HTTP_200_OK) # test actual data of edited photo rv = self.client.get('/api/edit_photo/?id={}'.format( self.created_image.id)) self.assertContains(rv, data['name'], status_code=200) # Test saving the image effect for a given photo. data = { 'id': self.created_image.id, 'image': self.created_image.image, 'image_effect': "http://localhost:8000/" + self.image_url, 'name': 'the new picture', } rv = self.client.put('/api/edit_photo/', data=data) self.assertEqual(rv.status_code, status.HTTP_200_OK) # test actual data of edited photo rv = self.client.get('/api/edit_photo/?id={}'.format( self.created_image.id)) self.assertContains(rv, "effects/test.png", status_code=200) def test_invalid_editing_of_photo_returns_400(self): """Test invalid data (bad request) should be handled appropriately.""" data = { 'id': 5000000, 'image': 'http://localhost:8000/noimage.jee', 'name': 'the new picture', 'image_effect': "" } rv = self.client.put('/api/edit_photo/', data=data) self.assertEqual(rv.status_code, status.HTTP_400_BAD_REQUEST) # test invalid image effect: return a 400 bad request if invalid self.name = 'test.png' self.image = File(open('static/test.jpg', 'rb')) self.created_image = Photo(image=self.image, name=self.name, user=self.user) self.created_image.save() response = self.client.get(reverse('editor:photos')) self.assertEqual(response.status_code, status.HTTP_200_OK) data = { 'id': self.created_image.id, 'image': self.created_image.image, 'name': "the new picture", 'image_effect': "http://localhost:8000/noimage.jee" } rv = self.client.put('/api/edit_photo/', data=data) self.assertEqual(rv.status_code, status.HTTP_400_BAD_REQUEST) def test_invalid_photo_name_during_photo_renaming_returns_400(self): """Test for invalid name on a photo rename request.""" self.name = 'test.png' self.image = File(open('static/test.jpg', 'rb')) self.created_image = Photo(image=self.image, name=self.name, user=self.user) self.created_image.save() response = self.client.get(reverse('editor:photos')) self.assertEqual(response.status_code, status.HTTP_200_OK) # invalid data random_things = Random.new() invalid_name = random_things.read(600) data = { 'id': self.created_image.id, 'name': invalid_name, # this is not a valid name 'image_effect': "" } rv = self.client.put('/api/edit_photo/', data=data) self.assertEqual(rv.status_code, status.HTTP_400_BAD_REQUEST) def test_user_can_delete_photo(self): """Test a given photo can be deleted.""" self.name = 'test.png' self.image = File(open('static/test.jpg', 'rb')) self.created_image = Photo(image=self.image, name=self.name, user=self.user) self.created_image.save() response = self.client.get(reverse('editor:photos')) self.assertEqual(response.status_code, status.HTTP_200_OK) rv = self.client.delete('/api/edit_photo/?id={}'.format( self.created_image.id)) self.assertEqual(rv.status_code, status.HTTP_204_NO_CONTENT) def test_filters_request_of_invalid_image(self): """Test correct server response when an IO error occurs.""" invalid_data = {'imageID': 300} response = self.client.get(reverse('editor:filters'), invalid_data) self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
class ImageEffectsTestCase(APITestCase): """Test case for Image effects.""" def setUp(self): """Set up a mock for opening actual file url.""" self.patcher = patch('urllib2.urlopen') self.urlopen_mock = self.patcher.start() self.username = fake.user_name() self.password = fake.password() self.photo_name = 'test.png' self.image_url = 'static/test.png' self.user = User.objects.create_user( username=self.username, password=self.password) self.user = authenticate( username=self.username, password=self.password) self.client.login(username=self.username, password=self.password) def test_application_of_filters(self): """Test that filters can be applied to images.""" self.name = 'test.png' self.image = File(open('static/test.png', 'rb')) self.created_image = Photo( image=self.image, name=self.name, user=self.user) self.created_image.save() data = { 'imageID': self.created_image.id } self.urlopen_mock.return_value = MockResponse(data) response = self.client.get(reverse('editor:filters'), data) self.assertEqual(response.status_code, status.HTTP_200_OK) def test_image_effects_deletion(self): """Test deletion of image effects from the server.""" self.name = 'test.png' self.image = File(open('static/test.png', 'rb')) self.created_image = Photo( image=self.image, name=self.name, user=self.user) self.created_image.save() # try deletion of no-existent filters returns 204 no content data = {'id': 1000, 'image_url': ''} response = self.client.post(reverse('editor:remove_effects'), data) self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT) data = { 'imageID': self.created_image.id } self.urlopen_mock.return_value = MockResponse(data) response = self.client.get(reverse('editor:filters'), data) self.assertEqual(response.status_code, status.HTTP_200_OK) # actual deletion data = {'id': self.created_image.pk, 'image_url': ''} rv = self.client.post(reverse('editor:remove_effects'), data) self.assertEqual(rv.status_code, status.HTTP_200_OK) def tearDown(self): """Tear down.""" self.patcher.stop()
class UserPhotoTestCase(APITestCase): """Test user login.""" def setUp(self): """Set up user data.""" self.username = fake.user_name() self.password = fake.password() self.photo_name = 'test.png' self.image_url = 'static/test.png' self.user = User.objects.create_user( username=self.username, password=self.password) self.user = authenticate( username=self.username, password=self.password) self.client.login(username=self.username, password=self.password) # get the image ready for loading self.image = Image.frombytes('L', (100, 100), "\x00" * 100 * 100) self.image = pil_to_django(self.image, 'png') self.image_create = Photo( image=self.image, name=self.photo_name, user=self.user).save() def tearDown(self): """Tear down all things test_user.""" del self.user del self.image_create @patch('editor.models.Photo.save', MagicMock(name="save")) def test_user_photo_creation(self): """Test photo creation by a given user.""" image_name = 'test.png' with open(self.image_url, 'rb') as image: data = {'image': image, 'name': image_name} response = self.client.post(reverse('editor:photos'), data) image.close() self.assertEqual(response.status_code, status.HTTP_201_CREATED) self.assertEqual(response.data.get('name'), image_name) def test_photo_retrievals(self): """Test user can retrieve their photos.""" image_name = 'test.png' with open(self.image_url, 'rb') as image: data = {'image': image, 'name': image_name} response = self.client.post(reverse('editor:photos'), data) image.close() response = self.client.get(reverse('editor:photos')) self.assertEqual(response.status_code, status.HTTP_200_OK) # test data retrieved data = [i.values() for i in response.data] self.assertIn( u'{}'.format(self.photo_name), data[0]) def test_getting_photo_by_id(self): """Test a given photo can be retrieved using the photoID.""" self.created_image = Photo( image=self.image, name=self.photo_name, user=self.user) self.created_image.save() rv = self.client.get( '/api/edit_photo/?id={}'.format(self.created_image.id)) self.assertEqual(rv.status_code, status.HTTP_200_OK) self.assertEqual(rv.data.get('name'), self.created_image.name) def test_user_can_edit_photo(self): """Test a given photo can be edited.""" self.name = 'test.png' self.image = File(open('static/test.jpg', 'rb')) self.created_image = Photo( image=self.image, name=self.name, user=self.user) self.created_image.save() response = self.client.get(reverse('editor:photos')) self.assertEqual(response.status_code, status.HTTP_200_OK) data = { 'id': self.created_image.id, 'image': self.created_image.image, 'image_effect': "", 'name': 'the new picture', } rv = self.client.put('/api/edit_photo/', data=data) self.assertEqual(rv.status_code, status.HTTP_200_OK) # test actual data of edited photo rv = self.client.get( '/api/edit_photo/?id={}'.format(self.created_image.id)) self.assertContains(rv, data['name'], status_code=200) # Test saving the image effect for a given photo. data = { 'id': self.created_image.id, 'image': self.created_image.image, 'image_effect': "http://localhost:8000/" + self.image_url, 'name': 'the new picture', } rv = self.client.put('/api/edit_photo/', data=data) self.assertEqual(rv.status_code, status.HTTP_200_OK) # test actual data of edited photo rv = self.client.get( '/api/edit_photo/?id={}'.format(self.created_image.id)) self.assertContains(rv, "effects/test.png", status_code=200) def test_invalid_editing_of_photo_returns_400(self): """Test invalid data (bad request) should be handled appropriately.""" data = { 'id': 5000000, 'image': 'http://localhost:8000/noimage.jee', 'name': 'the new picture', 'image_effect': "" } rv = self.client.put('/api/edit_photo/', data=data) self.assertEqual(rv.status_code, status.HTTP_400_BAD_REQUEST) # test invalid image effect: return a 400 bad request if invalid self.name = 'test.png' self.image = File(open('static/test.jpg', 'rb')) self.created_image = Photo( image=self.image, name=self.name, user=self.user) self.created_image.save() response = self.client.get(reverse('editor:photos')) self.assertEqual(response.status_code, status.HTTP_200_OK) data = { 'id': self.created_image.id, 'image': self.created_image.image, 'name': "the new picture", 'image_effect': "http://localhost:8000/noimage.jee" } rv = self.client.put('/api/edit_photo/', data=data) self.assertEqual(rv.status_code, status.HTTP_400_BAD_REQUEST) def test_invalid_photo_name_during_photo_renaming_returns_400(self): """Test for invalid name on a photo rename request.""" self.name = 'test.png' self.image = File(open('static/test.jpg', 'rb')) self.created_image = Photo( image=self.image, name=self.name, user=self.user) self.created_image.save() response = self.client.get(reverse('editor:photos')) self.assertEqual(response.status_code, status.HTTP_200_OK) # invalid data random_things = Random.new() invalid_name = random_things.read(600) data = { 'id': self.created_image.id, 'name': invalid_name, # this is not a valid name 'image_effect': "" } rv = self.client.put('/api/edit_photo/', data=data) self.assertEqual(rv.status_code, status.HTTP_400_BAD_REQUEST) def test_user_can_delete_photo(self): """Test a given photo can be deleted.""" self.name = 'test.png' self.image = File(open('static/test.jpg', 'rb')) self.created_image = Photo( image=self.image, name=self.name, user=self.user) self.created_image.save() response = self.client.get(reverse('editor:photos')) self.assertEqual(response.status_code, status.HTTP_200_OK) rv = self.client.delete( '/api/edit_photo/?id={}'.format(self.created_image.id)) self.assertEqual(rv.status_code, status.HTTP_204_NO_CONTENT) def test_filters_request_of_invalid_image(self): """Test correct server response when an IO error occurs.""" invalid_data = { 'imageID': 300 } response = self.client.get(reverse('editor:filters'), invalid_data) self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)