test_vboo_info_bot_functions.py 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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.message
  55. @pytest.mark.vcr()
  56. def test_send_article_message(api_wrapper, telegram_bot, telegram_channel):
  57. """Test format war"""
  58. article_id = 2867567
  59. response = Article(api_wrapper).info(article_id)
  60. assert isinstance(response, dict), "The response should be a dict"
  61. formatted_article = functions.telegram_format_article(response)
  62. if telegram_channel:
  63. telegram_bot.sendMessage(
  64. telegram_channel,
  65. formatted_article,
  66. parse_mode=ParseMode.MARKDOWN_V2
  67. )
  68. @pytest.mark.message
  69. @pytest.mark.vcr()
  70. def test_send_war_ground_message(api_wrapper, telegram_bot, telegram_channel):
  71. """Test format war"""
  72. war_id = 329541
  73. response = War(api_wrapper).info(war_id)
  74. assert isinstance(response, dict), "The response should be a dict"
  75. formatted_war = functions.telegram_format_war(response)
  76. if telegram_channel:
  77. telegram_bot.sendMessage(telegram_channel, formatted_war, parse_mode=ParseMode.MARKDOWN_V2)
  78. @pytest.mark.message
  79. @pytest.mark.vcr()
  80. def test_send_war_coup_message(api_wrapper, telegram_bot, telegram_channel):
  81. """Test format war"""
  82. war_id = 329518
  83. response = War(api_wrapper).info(war_id)
  84. assert isinstance(response, dict), "The response should be a dict"
  85. formatted_war = functions.telegram_format_war(response)
  86. if telegram_channel:
  87. telegram_bot.sendMessage(telegram_channel, formatted_war, parse_mode=ParseMode.MARKDOWN_V2)