test_vboo_info_bot_functions.py 4.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. """Wrapper test"""
  2. from rival_regions_wrapper.api_wrapper import Article, War
  3. from telegram import ParseMode
  4. import pytest
  5. from vboo_info_bot import functions
  6. @pytest.fixture
  7. def article_keys():
  8. """Standard key fro article"""
  9. return ['article_id', 'article_title', 'newspaper_id', 'newspaper_name', \
  10. 'author_name', 'author_id', 'region_name', 'region_id', 'content_text', 'content_html', \
  11. 'language']
  12. @pytest.mark.vcr()
  13. def test_article_info_one(api_wrapper, article_keys):
  14. """Test article info"""
  15. article_id = 2708696
  16. response = Article(api_wrapper).info(article_id)
  17. assert isinstance(response, dict), "The resonse should be a dict"
  18. assert set(article_keys).issubset(response.keys()), "All keys should be in the response"
  19. assert isinstance(response['article_id'], int), "Article id should be an integer"
  20. assert isinstance(response['article_title'], str), "Article title should be a str"
  21. assert isinstance(response['newspaper_id'], int), "Newspaper id should be an integer"
  22. assert isinstance(response['newspaper_name'], str), "Newspaper name should be a string"
  23. assert isinstance(response['author_name'], str), "Author name should be a string"
  24. assert isinstance(response['author_id'], int), "Author id should be an integer"
  25. assert isinstance(response['region_name'], str), "Region name should be a string"
  26. assert isinstance(response['region_id'], int), "Region id should be an integer"
  27. assert isinstance(response['content_text'], str), "Content text should be a string"
  28. assert isinstance(response['content_html'], str), "Content html should be a string"
  29. assert isinstance(response['language'], str), "Language should be a string"
  30. assert isinstance(response['content_html'], str), "Content html should be a string"
  31. assert isinstance(response['language'], str), "Language should be a string"
  32. assert isinstance(response['rating'], int), "Rating should be an integer"
  33. @pytest.mark.vcr()
  34. def test_article_info_two(api_wrapper, article_keys):
  35. """Test article info"""
  36. article_id = 2862982
  37. response = Article(api_wrapper).info(article_id)
  38. assert isinstance(response, dict), "The resonse should be a dict"
  39. assert set(article_keys).issubset(response.keys()), "All keys should be in the response"
  40. assert isinstance(response['article_id'], int), "Article id should be an integer"
  41. assert isinstance(response['article_title'], str), "Article title should be a str"
  42. assert response['newspaper_id'] is None, "Newspaper id should be none"
  43. assert response['newspaper_name'] is None, "Newspaper name should be none"
  44. assert isinstance(response['author_name'], str), "Author name should be a string"
  45. assert isinstance(response['author_id'], int), "Author id should be an integer"
  46. assert isinstance(response['region_name'], str), "Region name should be a string"
  47. assert isinstance(response['region_id'], int), "Region id should be an integer"
  48. assert isinstance(response['content_text'], str), "Content text should be a string"
  49. assert isinstance(response['content_html'], str), "Content html should be a string"
  50. assert isinstance(response['language'], str), "Language should be a string"
  51. assert isinstance(response['content_html'], str), "Content html should be a string"
  52. assert isinstance(response['language'], str), "Language should be a string"
  53. assert isinstance(response['rating'], int), "Rating should be an integer"
  54. @pytest.mark.vcr()
  55. def test_formatting_war_ground(api_wrapper, telegram_bot, telegram_channel):
  56. """Test format war"""
  57. war_id = 329541
  58. response = War(api_wrapper).info(war_id)
  59. assert isinstance(response, dict), "The response should be a dict"
  60. formatted_war = functions.telegram_format_war(response)
  61. if telegram_channel:
  62. telegram_bot.sendMessage(telegram_channel, formatted_war, parse_mode=ParseMode.MARKDOWN_V2)
  63. @pytest.mark.vcr()
  64. def test_formatting_war_coup(api_wrapper, telegram_bot, telegram_channel):
  65. """Test format war"""
  66. war_id = 329518
  67. response = War(api_wrapper).info(war_id)
  68. assert isinstance(response, dict), "The response should be a dict"
  69. formatted_war = functions.telegram_format_war(response)
  70. if telegram_channel:
  71. telegram_bot.sendMessage(telegram_channel, formatted_war, parse_mode=ParseMode.MARKDOWN_V2)