Example #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())
Example #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)
Example #3
0
    def test_image_doesnt_exist(self):
        """Test the case where an image id is passed for an image that doesnt exist"""

        testfield = ImageField('Title')

        id = 1

        try:
            testfield.get_single(id)
        except Image.DoesNotExist:
            pass
Example #4
0
    def test_image_singular_data(self):
        """Test the case where ImageField is initialized with many, but given 1 piece of data"""

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

        image = DispatchTestHelpers.create_image(self.client)

        try:
            testfield.validate(image.data['id'])
            self.fail('Field data is invalid, exception should have been thrown')
        except InvalidField:
            pass
Example #5
0
    def test_image_false_many(self):
        """Test the case where many is false where you have more than 1 image"""

        testfield = ImageField('Title')

        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)
            self.fail('Field data is invalid, exception should have been thrown')
        except:
            pass
Example #6
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())
Example #7
0
class TestWidgetR(Widget):
    id = 'test-widget-r'
    name = 'Test Widget R'
    template = 'widget/test-widget.html'

    zones = [TestZone]

    title = CharField('Title', required=True)
    description = TextField('Description', required=True)
    article = ArticleField('Featured article', required=True)
    image = ImageField('Featured image', required=True)
    widget = WidgetField('Featured Widget', [TestWidgetSub], required=True)
Example #8
0
class TestWidget2(Widget):
    id = 'test-widget-2'
    name = 'Test widget 2'
    template = 'widgets/test-widget.html'

    zones = [TestZone]

    title = CharField('Title 2')
    description = TextField('Description 2')
    article = ArticleField('Featured article 2')
    image = ImageField('Featured image 2')
    widget = WidgetField('Featured Widget 2', [TestWidgetSub])
Example #9
0
class TestWidget(Widget):
    id = 'test-widget'
    name = 'Test widget'
    template = 'widgets/test-widget.html'

    accepted_keywords = ('extra', )

    zones = [TestZone]

    title = CharField('Title')
    description = TextField('Description')
    article = ArticleField('Featured article')
    image = ImageField('Featured image')
Example #10
0
    def test_image_prepare_data(self):
        """Should be able to return prepared data for the template"""

        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')

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

        result = testfield.prepare_data(data)

        self.assertEqual(result[0].get_filename(), image_1.get_filename())
        self.assertEqual(result[1].get_filename(), image_2.get_filename())