Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

45 rindas
1.2 KiB

  1. # -*- coding: utf-8 -*-
  2. import unittest
  3. from validate.links import find_links_in_text
  4. class TestValidateLinks(unittest.TestCase):
  5. def test_find_link_in_text(self):
  6. text = """
  7. # this is valid
  8. http://example.com?param1=1&param2=2#anchor
  9. https://www.example.com?param1=1&param2=2#anchor
  10. https://www.example.com.br
  11. https://www.example.com.gov.br
  12. [Example](https://www.example.com?param1=1&param2=2#anchor)
  13. lorem ipsum https://www.example.com?param1=1&param2=2#anchor
  14. https://www.example.com?param1=1&param2=2#anchor lorem ipsum
  15. # this not is valid
  16. example.com
  17. https:example.com
  18. https:/example.com
  19. https//example.com
  20. https//.com
  21. """
  22. links = find_links_in_text(text)
  23. self.assertIsInstance(links, list)
  24. self.assertEqual(len(links), 7)
  25. for link in links:
  26. with self.subTest():
  27. self.assertIsInstance(link, str)
  28. def test_find_link_in_text_with_invalid_argument(self):
  29. with self.assertRaises(TypeError):
  30. find_links_in_text()
  31. find_links_in_text(1)
  32. find_links_in_text(True)