class EditPhotoTest(TestCase): def setUp(self): self.user = User.objects.create_user('adam', '*****@*****.**', 'adampassword') self.user.is_staff = True self.user.is_superuser = True self.user.save() self.client.login(username='******', password='******') self.album = Album.objects.create(owner=self.user, name='Test') self.keyword = PhotoTag.objects.create(name='test') image_fd, image_path = tempfile.mkstemp(suffix='.jpg') os.close(image_fd) Image.new('RGB', (640, 480)).save(image_path, 'JPEG') self.photo = Photo() self.photo.owner = self.user self.photo.album = self.album image = open(image_path) self.photo.image = ImageFile(image) self.photo.is_jpeg = True self.photo.save() os.remove(image_path) def tearDown(self): self.client.logout() User.objects.all().delete() Album.objects.all().delete() PhotoTag.objects.all().delete() Photo.objects.all().delete() def test_form(self): photo_edit = 'photasm.photos.views.photo_edit' photo_edit_url = reverse(photo_edit, args=[0]) response = self.client.get(photo_edit_url) self.assertEqual(response.status_code, 404) photo_edit_url = reverse(photo_edit, args=[self.photo.id]) response = self.client.get(photo_edit_url) self.assertEqual(response.status_code, 200) post_data = { 'album': self.album.id, 'description': 'test image', 'artist': 'Adam', 'country': 'USA', 'province_state': 'VA', 'city': 'Blacksburg', 'location': 'Drillfield', 'time_created': '2007-09-28 03:00:00', 'keywords': self.keyword.id, } response = self.client.post(photo_edit_url, post_data) self.photo = Photo.objects.get(id=self.photo.id) self.assertRedirects(response, self.photo.get_absolute_url()) self.assertFalse(self.photo.sync_metadata_to_file()) self.assertEqual(self.photo.description, 'test image') response = self.client.post(photo_edit_url, {}) self.assertEqual(response.status_code, 200) photo_edit = 'photo_edit_in_album' photo_edit_url = reverse(photo_edit, kwargs={ 'object_id': self.photo.id, 'in_album': 'albums', }) post_data['description'] = 'test image in album' response = self.client.post(photo_edit_url, post_data) self.photo = Photo.objects.get(id=self.photo.id) photo_url = reverse("photo_in_album", kwargs={ "object_id": self.photo.id, }) self.assertRedirects(response, photo_url) def test_admin_form(self): photo_edit_url = '/admin/photos/photo/%d/' % self.photo.id post_data = { 'owner': self.user.id, 'album': self.album.id, 'description': 'test image', 'artist': 'Adam', 'country': 'USA', 'province_state': 'VA', 'city': 'Blacksburg', 'location': 'Drillfield', 'time_created': '2007-09-28 03:00:00', 'keywords': self.keyword.id, 'metadata_sync_enabled': True, '_save': 'Save', } response = self.client.post(photo_edit_url, post_data) self.photo = Photo.objects.get(id=self.photo.id) self.assertEqual(response.status_code, 302) self.assertFalse(self.photo.sync_metadata_to_file()) self.assertEqual(self.photo.description, 'test image')