25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

test_validate_links.py 1.2 KiB

2 yıl önce
1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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)