Beispiel #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
 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
 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
Beispiel #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
 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)
Beispiel #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)
 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)
Beispiel #8
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)