You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

63 lines
2.2 KiB

  1. # -*- coding: utf-8 -*-
  2. from email import message
  3. import unittest
  4. from validate.format import error_message
  5. from validate.format import get_categories_content
  6. class TestValidadeFormat(unittest.TestCase):
  7. def test_error_message_return_and_return_type(self):
  8. line_num_unity = 1
  9. line_num_ten = 10
  10. line_num_hundred = 100
  11. line_num_thousand = 1000
  12. msg = 'This is a unit test'
  13. err_msg_unity = error_message(line_num_unity, msg)
  14. err_msg_ten = error_message(line_num_ten, msg)
  15. err_msg_hundred = error_message(line_num_hundred, msg)
  16. err_msg_thousand = error_message(line_num_thousand, msg)
  17. self.assertIsInstance(err_msg_unity, str)
  18. self.assertIsInstance(err_msg_ten, str)
  19. self.assertIsInstance(err_msg_hundred, str)
  20. self.assertIsInstance(err_msg_thousand, str)
  21. self.assertEqual(err_msg_unity, '(L002) This is a unit test')
  22. self.assertEqual(err_msg_ten, '(L011) This is a unit test')
  23. self.assertEqual(err_msg_hundred, '(L101) This is a unit test')
  24. self.assertEqual(err_msg_thousand, '(L1001) This is a unit test')
  25. def test_if_get_categories_content_return_correct_data_of_categories(self):
  26. fake_contents = [
  27. '### A',
  28. 'API | Description | Auth | HTTPS | CORS |',
  29. '|---|---|---|---|---|',
  30. '| [AA](https://www.ex.com) | Desc | `apiKey` | Yes | Yes |',
  31. '| [AB](https://www.ex.com) | Desc | `apiKey` | Yes | Yes |',
  32. '',
  33. '### B',
  34. 'API | Description | Auth | HTTPS | CORS |',
  35. '|---|---|---|---|---|',
  36. '| [BA](https://www.ex.com) | Desc | `apiKey` | Yes | Yes |',
  37. '| [BB](https://www.ex.com) | Desc | `apiKey` | Yes | Yes |'
  38. ]
  39. result = get_categories_content(fake_contents)
  40. self.assertIsInstance(result, tuple)
  41. categories, category_line_num = result
  42. self.assertIsInstance(categories, dict)
  43. self.assertIsInstance(category_line_num, dict)
  44. expected_result = ({'A': ['AA', 'AB'], 'B': ['BA', 'BB']}, {'A': 0, 'B': 6})
  45. for res, ex_res in zip(result, expected_result):
  46. with self.subTest():
  47. self.assertEqual(res, ex_res)