Beispiel #1
0
    def test_imageuploadview_with_junk(self):
        self.client.force_login(UserFactory.create(is_staff=True))

        with open(get_test_file_path('text-file.md'), 'rb') as fd:
            response = self.client.post(reverse('posts:image_upload'), data={'image': fd})
        self.assertEqual(response.status_code, 400)
        self.assertEqual(response.json()['image'], 'Image missing or broken.')
Beispiel #2
0
    def test_imageuploadview_happy_path(self):
        # pollution canary
        self.assertEqual(PostImage.objects.count(), 0)
        self.client.force_login(UserFactory.create(is_staff=True))

        with open(get_test_file_path('large-image.jpg'), 'rb') as fd:
            response = self.client.post(reverse('posts:image_upload'), data={'image': fd})
        self.assertEqual(response.status_code, 200)
        image = PostImage.objects.first()
        self.assertEqual(response.json()['image_code'], f'![]({image.get_absolute_url()})')
Beispiel #3
0
 def test_imageuploadview_unauthed(self):
     with open(get_test_file_path('small-image.jpg'), 'rb') as fd:
         response = self.client.post(reverse('posts:image_upload'), data={'image': fd})
     self.assertEqual(response.status_code, 302)
     self.assertTrue(response['Location'].startswith(reverse(settings.LOGIN_URL)))
Beispiel #4
0
 def image(obj, create, extracted, **kwargs):
     attachment_path = get_test_file_path(extracted)
     with open(attachment_path, mode='rb') as fd:
         obj.image.save(extracted, File(fd, name=extracted))  # pylint:disable=no-member