def test_exists_after_creation(self): """ Test that image creation and upload to S3 works. """ images = Image.objects.all() self.assertTrue(len(images) == 0) i = Image(description = "cute dog!", owner=self.account) i.tip = self.tip i.image_large.name = "dog_shelf.jpeg" input_file_path = os.path.join(self.test_image_dir, "dog_shelf.jpeg") with open(input_file_path, "rb") as f_in: content = ImageFile(f_in) default_storage.save(i.image_large.name, content) i.save() # -------------------------------------------------------------------- # Verify that the Django ORM representation exists. # -------------------------------------------------------------------- images = Image.objects.all() self.assertTrue(len(images) == 1) image = images[0] self.assertEqual(i.image_large.name, "dog_shelf.jpeg") # -------------------------------------------------------------------- # -------------------------------------------------------------------- # Verify that an HTTP GET of the image URL works. # -------------------------------------------------------------------- r = requests.get(i.get_absolute_url()) self.assertEqual(r.status_code, 200) self.assertEqual(r.headers.get("Content-Type", None), "image/jpeg")
def test_image_add(self): tip = Tip(title = "Peel Pub", location = "Peel Street, near McGill campus", guide = self.guide) tip.save() self.assertEqual(len(tip.image_set.all()), 0) i = Image(description = "cute dog!", owner=self.account) i.tip = tip i.save() self.assertEqual(len(tip.image_set.all()), 1)