Ejemplo n.º 1
0
 def test_correctly_saves_its_data(self):
     # Run & check
     for markup_text, expected_html_text in self.MARKUP_TEXT_FIELD_TESTS:
         test = TestableModel()
         test.content = markup_text
         test.save()
         assert test.content.rendered == expected_html_text
Ejemplo n.º 2
0
 def test_correctly_saves_its_data(self):
     # Run & check
     for markup_text, expected_html_text in self.MARKUP_TEXT_FIELD_TESTS:
         test = TestableModel()
         test.content = markup_text
         test.save()
         assert test.content.rendered == expected_html_text
Ejemplo n.º 3
0
 def test_can_accept_none_values(self):
     # Setup
     test = TestableModel()
     test.content = None
     # Run
     test.save()
     # Check
     assert test.content is None
     rendered = hasattr(test.content, 'rendered')
     assert not rendered
Ejemplo n.º 4
0
 def test_can_accept_none_values(self):
     # Setup
     test = TestableModel()
     test.content = None
     # Run
     test.save()
     # Check
     assert test.content is None
     rendered = hasattr(test.content, 'rendered')
     assert not rendered
Ejemplo n.º 5
0
 def test_should_not_accept_images_with_incorrect_sizes_or_dimensions(self):
     # Setup
     test = TestableModel()
     field = test._meta.get_field('validated_image')
     invalid_images = ['too_large_image', 'too_wide_image', 'too_high_image', ]
     # Run & check
     for img in invalid_images:
         field.save_form_data(test, self.images_dict[img])
         with pytest.raises(ValidationError):
             test.full_clean()
Ejemplo n.º 6
0
 def test_can_resize_images_before_saving_them(self):
     # Setup
     test = TestableModel()
     # Run
     field = test._meta.get_field('resized_image')
     field.save_form_data(test, self.images_dict['to_be_resized_image'])
     test.full_clean()
     test.save()
     # Check
     image = Image.open(BytesIO(test.resized_image.read()))
     assert image.size == (RESIZED_IMAGE_WIDTH, RESIZED_IMAGE_HEIGHT)
Ejemplo n.º 7
0
 def test_should_not_accept_images_with_incorrect_sizes_or_dimensions(self):
     # Setup
     test = TestableModel()
     field = test._meta.get_field('validated_image')
     invalid_images = [
         'too_large_image',
         'too_wide_image',
         'too_high_image',
     ]
     # Run & check
     for img in invalid_images:
         field.save_form_data(test, self.images_dict[img])
         with pytest.raises(ValidationError):
             test.full_clean()
Ejemplo n.º 8
0
 def test_can_resize_images_before_saving_them(self):
     # Setup
     test = TestableModel()
     # Run
     field = test._meta.get_field('resized_image')
     field.save_form_data(test, self.images_dict['to_be_resized_image'])
     test.full_clean()
     test.save()
     # Check
     image = Image.open(BytesIO(test.resized_image.read()))
     assert image.size == (RESIZED_IMAGE_WIDTH, RESIZED_IMAGE_HEIGHT)
Ejemplo n.º 9
0
 def test_provides_access_to_the_raw_text_and_to_the_rendered_text(self):
     # Setup
     test = TestableModel()
     test.content = '**hello**'
     test.save()
     field = test._meta.get_field('content')
     markup_content = '**hello world!**'
     markup_content_len = len(markup_content)
     # Run
     test.content.raw = markup_content
     markup_bk = test.content
     test.content = markup_bk
     test.save()
     # Check
     assert field.value_to_string(test) == markup_content
     assert test.content.rendered == '<p><strong>hello world!</strong></p>'
     assert len(test.content) == markup_content_len
     with pytest.raises(AttributeError):
         print(TestableModel.content.rendered)
Ejemplo n.º 10
0
 def test_provides_access_to_the_raw_text_and_to_the_rendered_text(self):
     # Setup
     test = TestableModel()
     test.content = '**hello**'
     test.save()
     field = test._meta.get_field('content')
     markup_content = '**hello world!**'
     markup_content_len = len(markup_content)
     # Run
     test.content.raw = markup_content
     markup_bk = test.content
     test.content = markup_bk
     test.save()
     # Check
     assert field.value_to_string(test) == markup_content
     assert test.content.rendered == '<p><strong>hello world!</strong></p>'
     assert len(test.content) == markup_content_len
     with pytest.raises(AttributeError):
         print(TestableModel.content.rendered)