test_rival_regions_wrapper.py 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. """Wrapper test"""
  2. from datetime import datetime, timedelta
  3. import pytest
  4. from rival_regions_wrapper.api_wrapper import Profile, Storage, Market, ResourceState, Perks, \
  5. Craft, Overview, War, Work, Article
  6. @pytest.fixture
  7. def profile_keys():
  8. """Standard key from profile"""
  9. return ['profile_id', 'name', 'level', 'level_percentage', 'strenght', 'education', 'endurance']
  10. @pytest.mark.vcr()
  11. def test_profile_info(api_wrapper, profile_keys):
  12. """Test an API call to get client info"""
  13. profile_instance = Profile(api_wrapper, 192852686)
  14. response = profile_instance.info()
  15. assert isinstance(response, dict), "The response should be a dict"
  16. assert response['profile_id'] == 192852686, "The ID should be in the response"
  17. assert set(profile_keys).issubset(response.keys()), "All keys should be in the response"
  18. assert isinstance(response['name'], str), "Name should be a string"
  19. assert isinstance(response['level'], int), "level should be a int"
  20. assert isinstance(response['level_percentage'], int), "level_percentage should be a int"
  21. assert isinstance(response['strenght'], int), "strenght should be a int"
  22. assert isinstance(response['education'], int), "education should be a int"
  23. assert isinstance(response['endurance'], int), "endurance should be a int"
  24. @pytest.fixture
  25. def storage_keys():
  26. """Standard keys for storage"""
  27. return [
  28. 'oil', 'ore', 'uranium', 'diamonds', 'liquid_oxygen',
  29. 'helium-3', 'rivalium', 'antirad', 'energy_drink',
  30. 'spacerockets', 'lss', 'tanks', 'aircrafts', 'missiles',
  31. 'bombers', 'battleships', 'laser_drones', 'moon_tanks', 'space_stations',
  32. 'oil_max', 'ore_max', 'uranium_max', 'diamonds_max', 'liquid_oxygen_max',
  33. 'helium-3_max', 'rivalium_max', 'antirad_max', 'energy_drink_max',
  34. 'spacerockets_max', 'lss_max', 'tanks_max', 'aircrafts_max', 'missiles_max',
  35. 'bombers_max', 'battleships_max', 'laser_drones_max', 'moon_tanks_max', 'space_stations'
  36. ]
  37. @pytest.mark.vcr()
  38. def test_storage_info(api_wrapper, storage_keys):
  39. """Test an API call to get storage info"""
  40. response = Storage(api_wrapper).info()
  41. assert isinstance(response, dict), "The response should be a dict"
  42. assert set(storage_keys).issubset(response.keys()), "All keys should be in the response"
  43. @pytest.fixture
  44. def market_keys():
  45. """Standard keys for storage"""
  46. return ['player_id', 'player_name', 'price', 'amount']
  47. @pytest.mark.vcr()
  48. def test_market_info(api_wrapper, market_keys):
  49. """Test an API call to get market info"""
  50. resource = 'oil'
  51. response = Market(api_wrapper).info(resource)
  52. assert isinstance(response, list), "The response should be a list"
  53. if response:
  54. assert isinstance(response[0], dict), "The first element should be a dict"
  55. assert set(market_keys).issubset(response[0].keys()), "All keys should be in the response"
  56. assert isinstance(response[0]['player_id'], int), "The player_id should be a int"
  57. assert isinstance(response[0]['player_name'], str), "The player_name should be a int"
  58. assert isinstance(response[0]['price'], int), "The price should be a int"
  59. assert isinstance(response[0]['amount'], int), "The price should be a int"
  60. @pytest.fixture
  61. def resource_keys():
  62. """Standard keys for resource"""
  63. return ['region_id', 'region_name', 'explored', 'maximum', 'deep_exploration', 'limit_left']
  64. @pytest.mark.vcr()
  65. def test_resource_state_info(api_wrapper, resource_keys):
  66. """Test an API call to get market info"""
  67. state = 3382
  68. resource = 'oil'
  69. response = ResourceState(api_wrapper, state).info(resource)
  70. assert isinstance(response, list), "The response should be a list"
  71. if response:
  72. assert isinstance(response[0], dict), "The first element should be a dict"
  73. assert set(resource_keys).issubset(response[0].keys()), "All keys should be in the response"
  74. assert isinstance(response[0]['region_id'], int), "The region_id should be a int"
  75. assert isinstance(response[0]['region_name'], str), "The region_name should be a str"
  76. assert isinstance(response[0]['explored'], float), "The explored should be a float"
  77. assert isinstance(response[0]['maximum'], int), "The maximum should be a int"
  78. assert isinstance(response[0]['deep_exploration'], int), "deep_exploration should be int"
  79. assert isinstance(response[0]['limit_left'], int), "The limit_left should be a int"
  80. @pytest.fixture
  81. def perks_keys():
  82. """Standard keys for perks"""
  83. return ['strenght', 'education', 'endurance', 'upgrade_date', 'upgrade_perk']
  84. @pytest.mark.vcr()
  85. def test_perks_info(api_wrapper, perks_keys):
  86. """Test an API call to get perks info"""
  87. response = Perks(api_wrapper).info()
  88. assert isinstance(response, dict), "The response should be a dict"
  89. assert set(perks_keys).issubset(response.keys()), "All keys should be in the response"
  90. assert isinstance(response['strenght'], int), "strengt should be an int"
  91. assert isinstance(response['education'], int), "educatino should be an int"
  92. assert isinstance(response['endurance'], int), "endurance should be an int"
  93. assert isinstance(response['upgrade_date'], datetime), "upgrade_date should be a date"
  94. assert isinstance(response['upgrade_perk'], int), "upgrade_perk should be an int"
  95. @pytest.mark.skip(reason="Update request")
  96. def test_perks_upgrade(api_wrapper):
  97. """Test an API call to upgrade perk"""
  98. perk = 'endurance'
  99. upgrade_type = 'money'
  100. Perks.upgrade(perk, upgrade_type )
  101. @pytest.fixture
  102. def craft_keys():
  103. """Standard keys for craft"""
  104. return ['market_price', 'resources']
  105. @pytest.mark.skip(reason="Update request")
  106. def test_craft_produce(api_wrapper):
  107. """Test an API call to produce new item"""
  108. item = 'energy_drink'
  109. Craft(api_wrapper).produce(item, 10)
  110. assert True
  111. @pytest.fixture
  112. def overview_info_keys():
  113. """Standard keys for overview info"""
  114. return ['perks', 'war']
  115. @pytest.mark.vcr()
  116. def test_overview_info(api_wrapper, overview_info_keys):
  117. """Test an API call for overview"""
  118. response = Overview(api_wrapper).info()
  119. assert isinstance(response, dict), "The response hould be a dict"
  120. assert set(overview_info_keys).issubset(response.keys()), "All keys should be in the response"
  121. assert isinstance(response['war'], dict), "The war key should be a dict"
  122. @pytest.fixture
  123. def overview_status_keys():
  124. """Standard kenys for overview status"""
  125. return ['profile_id', 'party_id', 'gold', 'money', 'level', 'exp']
  126. @pytest.mark.vcr()
  127. def test_overview_status(api_wrapper, overview_status_keys):
  128. """Test an API cal for status"""
  129. response = Overview(api_wrapper).status()
  130. assert isinstance(response, dict), "The response hould be a dict"
  131. assert set(overview_status_keys).issubset(response.keys()), "All keys should be in the response"
  132. @pytest.mark.vcr()
  133. def test_war_page(api_wrapper):
  134. """Test getting training war"""
  135. response = War(api_wrapper).page()
  136. assert isinstance(response, dict), "The response should be a dict"
  137. assert isinstance(response['training_war'], int), "The training_war should be an int"
  138. @pytest.mark.vcr()
  139. def test_war_info(api_wrapper):
  140. """Test war info"""
  141. war = War(api_wrapper)
  142. war_page = war.page()
  143. war_id = war_page['training_war']
  144. response = war.info(war_id)
  145. assert isinstance(response, dict), "The response should be a dict"
  146. assert isinstance(response['damage'], int), "Damage should be an int"
  147. assert isinstance(response['attack_damage'], int), "Attack damage should be an int"
  148. assert isinstance(response['defence_damage'], int), "Defence damage should be an int"
  149. assert isinstance(response['attack_hourly_available'], bool), "Attack hourly should be a bool"
  150. assert isinstance(response['energ_drinks'], int), "Energy drinks should be an int"
  151. assert isinstance(response['name'], str), "Name should be a str"
  152. assert isinstance(response['max_hero_name'], str), "max hero name should be a str"
  153. assert isinstance(response['max_hero_damage'], int), "max hero damage should be an int"
  154. if 'time_left' in response:
  155. assert isinstance(response['time_left'], timedelta), "time left should be a time delta"
  156. assert isinstance(response['finish_date'], datetime), "Finish date should be a date"
  157. assert isinstance(response['war_units'], dict), "war units should be a dict"
  158. @pytest.mark.vcr()
  159. def test_work_info(api_wrapper):
  160. """Test work info"""
  161. response = Work(api_wrapper).page()
  162. assert isinstance(response, dict), "The response should be a dict"
  163. assert isinstance(response['factory'], dict), "Factory should be a dict"
  164. assert isinstance(response['resources_left'], dict), "Resources left should be a dict"
  165. assert isinstance(response['work_exp'], dict), "Work exp should be a dict"
  166. @pytest.mark.vcr()
  167. def test_article_info(api_wrapper):
  168. """Test article info"""
  169. article_id = 2708696
  170. response = Article(api_wrapper).info(article_id)
  171. assert isinstance(response, dict), "The resonse should be a dict"
  172. assert isinstance(response['article_id'], int), "Article id should be an integer"
  173. assert isinstance(response['article_title'], str), "Article title should be a str"
  174. assert isinstance(response['newspaper_id'], int), "Newspaper id should be an integer"
  175. assert isinstance(response['newspaper_name'], str), "Newspaper name should be a string"
  176. assert isinstance(response['author_name'], str), "Author name should be a string"
  177. assert isinstance(response['author_id'], int), "Author id should be an integer"
  178. assert isinstance(response['region_name'], str), "Region name should be a string"
  179. assert isinstance(response['region_id'], int), "Region id should be an integer"
  180. assert isinstance(response['content_text'], str), "Content text should be a string"
  181. assert isinstance(response['content_html'], str), "Content html should be a string"
  182. assert isinstance(response['language'], str), "Language should be a string"