def test_gallery_with_auto_open_image_loads(self): ''' Tests that the gallery view loads when a photo to open by is specified ''' #Copy test image to media area shutil.copy2(self.test_image, self.test_image_destination) im = Image(gallery=self.gallery, family=self.family, original_image=self.test_image_destination, thumbnail=self.test_image_destination, large_thumbnail=self.test_image_destination) im.save() self.client.login(email='*****@*****.**', password='******') response = self.client.get('/gallery={0}/image={1}/'.format( self.gallery.id, im.id)) im.delete_image_files() self.assertEqual(200, response.status_code) self.assertTemplateUsed(response, 'gallery/gallery.html')
def test_geocode_image_location_post(self): ''' Test you can geocode image view ''' #Copy test image to media area shutil.copy2(self.test_image, self.test_image_destination) im = Image(gallery=self.gallery, family=self.family, original_image=self.test_image_destination, thumbnail=self.test_image_destination, large_thumbnail=self.test_image_destination) im.save() self.client.login(email='*****@*****.**', password='******') response = self.client.post('/image={0}/address/'.format(im.id), {'address': 'Freddie Mercury Montreux'}) im.delete_image_files() self.assertEqual(200, response.status_code) self.assertEqual(True, b'46.43' in response.content) self.assertEqual(True, b'6.9' in response.content) im = Image.objects.get(id=im.id) self.assertEqual(46.43, round(im.latitude, 2)) self.assertEqual(6.9, round(im.longitude, 1))
def test_person_gallery_with_auto_open_image_does_not_load_for_another_family( self): ''' Tests specified photo does not open if in another family ''' #Copy test image to media area shutil.copy2(self.test_image, self.test_image_destination) image = Image(gallery=self.gallery, family=self.another_family, original_image=self.test_image_destination, thumbnail=self.test_image_destination, large_thumbnail=self.test_image_destination) image.save p = Person.objects.create(name='badger', family_id=self.family.id) self.client.login(email='*****@*****.**', password='******') response = self.client.get('/person={0}/photos/image={1}/'.format( p.id, image.id)) self.assertEqual(404, response.status_code) image.delete_image_files()
def test_make_thumbnails_and_delete(self): ''' Tests the make thumbnails routine ''' #Copy test image to media area shutil.copy2(self.test_image, self.test_image_destination) image = Image(gallery=self.gallery, family=self.family, original_image=self.test_image_destination) image.make_thumbnails() PIL.Image.open(settings.MEDIA_ROOT + str(image.thumbnail)) PIL.Image.open(settings.MEDIA_ROOT + str(image.large_thumbnail)) PIL.Image.open(settings.MEDIA_ROOT + str(self.gallery.thumbnail)) #Clear up mess afterwards image.delete_image_files()
def test_geocode_image_location_post_other_family(self): ''' Test another family cannot geocode image ''' #Copy test image to media area shutil.copy2(self.test_image, self.test_image_destination) im = Image(gallery=self.gallery, family=self.family, original_image=self.test_image_destination, thumbnail=self.test_image_destination, large_thumbnail=self.test_image_destination) im.save() self.client.login(email='*****@*****.**', password='******') response = self.client.post('/image={0}/address/'.format(im.id), {'address': 'Freddie Mercury Montreux'}) im.delete_image_files() self.assertEqual(404, response.status_code)