def setUp(self): # User self.user = User(first_name="Andrew", last_name="Warhola", username="******", password="******") self.user.is_superuser = True self.user.is_active = True self.user.save() self.client_auth = APIClient() self.client_auth.force_authenticate(user=self.user) # Gallery self.gallery = Gallery( label="Diptyque Marilyn", description="Andrew Warhol's Artwork pictures", ) self.gallery.save() # Medium self.medium = Medium( label="Picture Diptyque Marilyn", description="Color & Grey Marilyn", gallery=self.gallery, ) self.medium.save()
class ModelsTestCase(TestCase): """ Tests Assets Models """ def setUp(self): # create place self.gallery = Gallery( label="Diptyque Marilyn", description="Andrew Warhol's Artwork pictures", ) self.gallery.save() self.medium = Medium( label="Picture Diptyque Marilyn", description="Color & Grey Marilyn", gallery=self.gallery, ) self.medium.save() def tearDown(self): pass def test_gallery(self): "simple TEST gallery" # get gallery galleries = Gallery.objects.all() # test gallerie created self.assertEqual(galleries.count(), 1) def test_medium(self): "simple TEST medium" # get gallery media = Medium.objects.all() # test medium created self.assertEqual(media.count(), 1)
def setUp(self): # create gallery self.gallery = Gallery(label="Avatars gallery") self.gallery.save() # create medium associated self.medium = Medium(label="Avatar", gallery=self.gallery) self.medium.save()
class GalleryEndPoint(TestCase): """ Tests concernants Gallery's endpoint """ def setUp(self): self.user = User(first_name="Andrew", last_name="Warhola", username="******", password="******") # bypass permission self.user.is_superuser = True self.user.is_active = True self.user.save() self.gallery = Gallery( label="Diptyque Marilyn", description="Andrew Warhol's Artwork pictures", ) self.gallery.save() def tearDown(self): pass def test_list(self): """ Test list of gallery endpoint """ url = reverse('gallery-list') self.response = self.client.get(url) self.assertEqual(self.response.status_code, 200) def test_ressource(self): """ Test acces detail of gallery endpoint """ url = reverse('gallery-detail', kwargs={'pk': 1}) self.response = self.client.get(url) self.assertEqual(self.response.status_code, 200) def test_create_gallery(self): """ Test create gallery endpoint """ self.client_auth = APIClient() self.client_auth.force_authenticate(user=self.user) url = reverse('gallery-list') data = {'label': 'test', 'description': 'test'} self.response = self.client_auth.post(url, data) self.assertEqual(self.response.status_code, 201)
def setUp(self): # create place self.gallery = Gallery( label="Diptyque Marilyn", description="Andrew Warhol's Artwork pictures", ) self.gallery.save() self.medium = Medium( label="Picture Diptyque Marilyn", description="Color & Grey Marilyn", gallery=self.gallery, ) self.medium.save()
def setUp(self): self.user = User(first_name="Andrew", last_name="Warhola", username="******", password="******") # bypass permission self.user.is_superuser = True self.user.is_active = True self.user.save() self.gallery = Gallery( label="Diptyque Marilyn", description="Andrew Warhol's Artwork pictures", ) self.gallery.save()
class UploadTestCase(TestCase): """ Tests Upload Commands """ def setUp(self): # create gallery self.gallery = Gallery(label="Avatars gallery") self.gallery.save() # create medium associated self.medium = Medium(label="Avatar", gallery=self.gallery) self.medium.save() def tearDown(self): pass def test_upload_file_image(self): "simple TEST upload" # set up file name image_name = '#éavatar!$*' image_name_slug = 'avatar' # create image file image_file = create_image(image_name + '.png') # set to medium self.medium.picture = image_file self.medium.save() # tests # contain the name of the file self.assertIn(image_name_slug, self.medium.picture.name) # name without accent self.assertNotIn(image_name[1], self.medium.picture.name) # name without root path self.assertNotIn(settings.MEDIA_ROOT.replace(os.sep, '/'), self.medium.picture.name) # media url with url settings self.assertIn(settings.MEDIA_URL, self.medium.picture.url) # media path with root settings self.assertIn(settings.MEDIA_ROOT, self.medium.picture.path)
class MediumEndPoint(TestCase): """ Tests concernants Medium's endpoint """ def setUp(self): # User self.user = User(first_name="Andrew", last_name="Warhola", username="******", password="******") self.user.is_superuser = True self.user.is_active = True self.user.save() self.client_auth = APIClient() self.client_auth.force_authenticate(user=self.user) # Gallery self.gallery = Gallery( label="Diptyque Marilyn", description="Andrew Warhol's Artwork pictures", ) self.gallery.save() # Medium self.medium = Medium( label="Picture Diptyque Marilyn", description="Color & Grey Marilyn", gallery=self.gallery, ) self.medium.save() def tearDown(self): pass def generate_photo_file(self): file = io.BytesIO() image = Image.new('RGBA', size=(100, 100), color=(155, 0, 0)) image.save(file, 'png') file.name = 'test.png' file.seek(0) return file def test_list(self): """ Test list of medium """ url = reverse('medium-list') response = self.client.get(url) self.assertEqual(response.status_code, 200) def test_ressource(self): """ Test detail of media """ url = reverse('medium-detail', kwargs={'pk': 1}) response = self.client.get(url) self.assertEqual(response.status_code, 200) def test_upload_image(self): """ Test upload file """ self.client_auth.force_authenticate(user=self.user) url_post_media = reverse('medium-detail', kwargs={'pk': 1}) file = self.generate_photo_file() data = { 'label': 'Upload', 'description': 'test', 'gallery': reverse('gallery-detail', kwargs={'pk': self.gallery.id}), 'picture': file, } response = self.client_auth.patch(url_post_media, data=data) assert response.status_code == 200