Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

test_validate_links.py 1.3 KiB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. # -*- coding: utf-8 -*-
  2. import unittest
  3. from validate.links import find_links_in_text
  4. class TestValidateLinks(unittest.TestCase):
  5. def setUp(self):
  6. self.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. def test_find_link_in_text(self):
  23. links = find_links_in_text(self.text)
  24. self.assertIsInstance(links, list)
  25. self.assertEqual(len(links), 7)
  26. for link in links:
  27. with self.subTest():
  28. self.assertIsInstance(link, str)
  29. def test_find_link_in_text_with_invalid_argument(self):
  30. with self.assertRaises(TypeError):
  31. find_links_in_text()
  32. find_links_in_text(1)
  33. find_links_in_text(True)