def test_correctly_saves_its_data(self): # Run & check for markup_text, expected_html_text in self.MARKUP_TEXT_FIELD_TESTS: test = DummyModel() test.content = markup_text test.save() assert test.content.rendered.rstrip() == expected_html_text
def test_content_returns_the_raw_value_when_converted_to_a_string(self): # Setup test = DummyModel() test.content = '**hello world!**' test.save() # Run & check assert force_text(test.content) == '**hello world!**'
def test_default_return_value_for_subtask(self): d1 = DummyModel(name="qux") d1.save() d2 = DummyModel(name="mux") d2.save() self._run(persist_results=True) self.assertEqual(DummyModel.objects.filter(name=str([d1.id, d2.id])).count(), 1)
def test_can_accept_none_values(self): # Setup test = DummyModel() 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 = DummyModel() # 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 = DummyModel() 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.rstrip() == '<p><strong>hello world!</strong></p>' assert len(test.content) == markup_content_len with pytest.raises(AttributeError): print(DummyModel.content.rendered)