Beispiel #1
0
    def test_extensions_valid_enabled(self):
        image = ImageFactory.create(default_alt_text='Test')

        field = AdminFileFormField(
            mock.Mock(), Image.objects.all(), 'id', extensions=['jpg', 'gif'])

        assert isinstance(field.clean(str(image.pk)), Image)
Beispiel #2
0
    def test_without_alt_text_enabled(self):
        image = ImageFactory.create(default_alt_text=None)

        field = AdminFileFormField(mock.Mock(), Image.objects.all(), 'id')

        with pytest.raises(forms.ValidationError):
            field.clean(str(image.pk))
Beispiel #3
0
    def test_extensions_invalid_enabled(self):
        image = ImageFactory.create(default_alt_text='Test')

        field = AdminFileFormField(
            mock.Mock(), Image.objects.all(), 'id', extensions=['png', 'gif'])

        with pytest.raises(forms.ValidationError):
            field.clean(str(image.pk))
Beispiel #4
0
    def test_with_alt_text_enabled(self):
        image = ImageFactory.create(default_alt_text='Test')

        field = AdminFileFormField(mock.Mock(), Image.objects.all(), 'id')

        assert isinstance(field.clean(str(image.pk)), Image)
Beispiel #5
0
    def test_without_alt_text_disabled(self):
        image = ImageFactory.create(default_alt_text=None)

        field = AdminFileFormField(
            mock.Mock(), Image.objects.all(), 'id', alt_text_required=False)
        assert isinstance(field.clean(str(image.pk)), Image)
Beispiel #6
0
    def test_super_not_clean(self):
        field = AdminFileFormField(
            mock.Mock(), Image.objects.all(), 'id', required=False)

        assert field.clean('') is None