def test_publication_date_is_filled_if_published(self): fp = FlatPageFactory() fp.save() self.assertIsNone(fp.publication_date) fp.published = True fp.save() self.assertIsNotNone(fp.publication_date)
def test_media_returns_all_images_attributes(self): html = u""" <h1>One page</h1> <body><p>Yéâh</p> <img src="/media/image1.png" title="Image 1" alt="image-1"/> <img src="/media/image2.jpg"/> <img title="No src"/> </body> """ page = FlatPageFactory(content=html) self.assertEqual(page.parse_media(), [ {'url': '/media/image1.png', 'title': 'Image 1', 'alt': 'image-1', 'mimetype': ['image', 'png']}, {'url': '/media/image2.jpg', 'title': '', 'alt': '', 'mimetype': ['image', 'jpeg']} ])
def test_media_is_empty_if_content_has_no_image(self): page = FlatPageFactory( content="""<h1>One page</h1><body>One looove</body>""") self.assertEqual(page.parse_media(), [])
def test_media_is_empty_if_content_is_none(self): page = FlatPageFactory() self.assertEqual(page.parse_media(), [])
def test_validation_does_not_fail_if_url_is_none(self): fp = FlatPageFactory(external_url=None, content="<p></p>") fp.clean()
def test_validation_does_not_fail_if_url_and_content_are_falsy(self): fp = FlatPageFactory(external_url=" ", content="<p></p>") fp.clean()
def test_target_is_all_by_default(self): fp = FlatPageFactory() self.assertEquals(fp.target, 'all')
def test_slug_is_taken_from_title(self): fp = FlatPageFactory(title="C'est pour toi") self.assertEquals(fp.slug, 'cest-pour-toi')
def test_flatpages_are_updatable(self): self.login() page = FlatPageFactory(content="One looove") response = self.client.get( '/admin/flatpages/flatpage/{0}/change/'.format(page.pk)) self.assertContains(response, "One looove")
def test_validation_fails_if_both_url_and_content_are_in_any_language( self): fp = FlatPageFactory(external_url="http://geotrek.fr", content_it="<p>Boom!</p>") self.assertRaises(ValidationError, fp.clean)
def test_is_public(self): fp = FlatPageFactory(title="Blabla", published_fr=True) self.assertTrue(fp.is_public())