Esempio n. 1
0
    def test_image_field(self):
        """Should be able to create image field"""

        testfield = ImageField('Title', many=True)

        image_1 = DispatchTestHelpers.create_image(self.client)
        image_2 = DispatchTestHelpers.create_image(self.client)

        data = [image_1.data['id'], image_2.data['id']]

        try:
            testfield.validate(data)
        except InvalidField:
            self.fail(
                'Field data is valid, exception should not have been thrown')

        json = testfield.to_json(data)

        image_1 = Image.objects.get(pk=image_1.data['id'])
        image_2 = Image.objects.get(pk=image_2.data['id'])

        self.assertEqual(json[0]['id'], 1)
        self.assertEqual(json[0]['filename'], image_1.get_filename())
        self.assertEqual(json[1]['id'], 2)
        self.assertEqual(json[1]['filename'], image_2.get_filename())
Esempio n. 2
0
    def test_image_to_json_no_data(self):
        """Test the case where None data is passed to 'to_json' """

        testfield = ImageField('Title')

        data = None

        self.assertEqual(testfield.to_json(data), None)
Esempio n. 3
0
    def test_image_single_id(self):
        """Should be able to create image field with only 1 id"""

        testfield = ImageField('Title')

        image = DispatchTestHelpers.create_image(self.client)

        try:
            testfield.validate(image.data['id'])
        except InvalidField:
            self.fail('Field data is valid, exception should not have been thrown')

        json = testfield.to_json(image.data['id'])

        image = Image.objects.get(pk=image.data['id'])

        self.assertEqual(json['id'], 1)
        self.assertEqual(json['filename'], image.get_filename())