test_representative_image.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #!/bin/sh
  2. import unittest
  3. from jinja2.utils import generate_lorem_ipsum
  4. # Generate content with image
  5. TEST_CONTENT_IMAGE_URL = 'https://testimage.com/test.jpg'
  6. TEST_CONTENT = str(generate_lorem_ipsum(n=3, html=True)) + '<img src="' + TEST_CONTENT_IMAGE_URL + '"/>'+ str(generate_lorem_ipsum(n=2,html=True))
  7. TEST_SUMMARY_IMAGE_URL = 'https://testimage.com/summary.jpg'
  8. TEST_SUMMARY_WITHOUTIMAGE = str(generate_lorem_ipsum(n=1, html=True))
  9. TEST_SUMMARY_WITHIMAGE = TEST_SUMMARY_WITHOUTIMAGE + '<img src="' + TEST_SUMMARY_IMAGE_URL + '"/>'
  10. from pelican.contents import Article
  11. import representative_image
  12. class TestRepresentativeImage(unittest.TestCase):
  13. def setUp(self):
  14. super(TestRepresentativeImage, self).setUp()
  15. representative_image.register()
  16. def test_extract_image_from_content(self):
  17. args = {
  18. 'content': TEST_CONTENT,
  19. 'metadata': {
  20. 'summary': TEST_SUMMARY_WITHOUTIMAGE,
  21. },
  22. }
  23. article = Article(**args)
  24. self.assertEqual(article.featured_image, TEST_CONTENT_IMAGE_URL)
  25. def test_extract_image_from_summary(self):
  26. args = {
  27. 'content': TEST_CONTENT,
  28. 'metadata': {
  29. 'summary': TEST_SUMMARY_WITHIMAGE,
  30. },
  31. }
  32. article = Article(**args)
  33. self.assertEqual(article.featured_image, TEST_SUMMARY_IMAGE_URL)
  34. self.assertEqual(article.summary, TEST_SUMMARY_WITHOUTIMAGE)
  35. if __name__ == '__main__':
  36. unittest.main()