Beispiel #1
0
    def test_post_signal_image_other_attachments_exists(self):
        """ It should be possible to add an image when no image is added to the signal, even if
        other types of attachments are added. """
        add_non_image_attachments(self.signal)

        url = f'{self.endpoint}image/'
        image = SimpleUploadedFile(
            'image.gif', small_gif, content_type='image/gif')
        response = self.client.post(
            url, {'signal_id': self.signal.signal_id, 'image': image})

        self.assertEqual(response.status_code, 202)
        self.signal.refresh_from_db()
        self.assertTrue(self.signal.image)
Beispiel #2
0
    def test_return_first_image_attachment(self):
        """ If multiple attachments are present, the v0 API should return only the first ever
        uploaded image through the 'image' field and ignore the rest. """

        # Create some random attachments, keep the first
        add_non_image_attachments(self.last)
        image_attachment, _ = add_image_attachments(self.last, 2)
        add_non_image_attachments(self.last)
        add_image_attachments(self.last, 3)

        url = "/signals/auth/signal/{}/".format(self.last.id)
        response = self.client.get(url)

        self.assertEqual(200, response.status_code)
        json_resp = response.json()

        self.assertEqual("http://testserver" + image_attachment.image_crop.url, json_resp["image"])
        self.assertFalse('attachments' in json_resp, "Attachments is a v1-only field")
Beispiel #3
0
    def test_post_signal_image_image_attachment_exists(self):
        """ It should not be possible to add an image through the v0 api when one of the already
        present attachments is an image """

        # Add some non-image attachments
        add_non_image_attachments(self.signal)

        # Add image attachment
        add_image_attachments(self.signal, 1)

        image2 = SimpleUploadedFile('image.gif', small_gif, content_type='image/gif')

        # Then assert that adding another image through the v0 API fails
        url = f'{self.endpoint}image/'
        response = self.client.post(
            url, {'signal_id': self.signal.signal_id, 'image': image2})

        # 403 is not the best response code, but consistent with existing v0 endpoint
        self.assertEqual(response.status_code, 403)
        self.signal.refresh_from_db()
        self.assertTrue(self.signal.image)