test_rival_regions_wrapper.py 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  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. try:
  94. assert isinstance(response['upgrade_date'], datetime), "upgrade_date should be a date"
  95. assert isinstance(response['upgrade_perk'], int), "upgrade_perk should be an int"
  96. except AssertionError:
  97. assert isinstance(response['upgrade_date'], type(None)), "upgrade_date should be None if not upgrading"
  98. assert isinstance(response['upgrade_perk'], type(None)), "upgrade_perk should be an int"
  99. @pytest.mark.skip(reason="Update request")
  100. def test_perks_upgrade(api_wrapper):
  101. """Test an API call to upgrade perk"""
  102. perk = 'endurance'
  103. upgrade_type = 'money'
  104. Perks.upgrade(perk, upgrade_type)
  105. @pytest.fixture
  106. def craft_keys():
  107. """Standard keys for craft"""
  108. return ['market_price', 'resources']
  109. @pytest.mark.skip(reason="Update request")
  110. def test_craft_produce(api_wrapper):
  111. """Test an API call to produce new item"""
  112. item = 'energy_drink'
  113. Craft(api_wrapper).produce(item, 10)
  114. assert True
  115. @pytest.fixture
  116. def overview_info_keys():
  117. """Standard keys for overview info"""
  118. return ['perks', 'war']
  119. @pytest.mark.vcr()
  120. def test_overview_info(api_wrapper, overview_info_keys):
  121. """Test an API call for overview"""
  122. response = Overview(api_wrapper).info()
  123. assert isinstance(response, dict), "The response hould be a dict"
  124. assert set(overview_info_keys).issubset(response.keys()), "All keys should be in the response"
  125. assert isinstance(response['war'], dict), "The war key should be a dict"
  126. @pytest.fixture
  127. def overview_status_keys():
  128. """Standard kenys for overview status"""
  129. return ['profile_id', 'party_id', 'gold', 'money', 'level', 'exp']
  130. @pytest.mark.vcr()
  131. def test_overview_status(api_wrapper, overview_status_keys):
  132. """Test an API cal for status"""
  133. response = Overview(api_wrapper).status()
  134. assert isinstance(response, dict), "The response hould be a dict"
  135. assert set(overview_status_keys).issubset(response.keys()), "All keys should be in the response"
  136. @pytest.mark.vcr()
  137. def test_war_page(api_wrapper):
  138. """Test getting training war"""
  139. response = War(api_wrapper).page()
  140. assert isinstance(response, dict), "The response should be a dict"
  141. if response['training_war']:
  142. assert isinstance(response['training_war'], int), "The training_war should be an int"
  143. @pytest.mark.vcr()
  144. def test_war_info(api_wrapper):
  145. """Test war info"""
  146. war = War(api_wrapper)
  147. war_page = war.page()
  148. war_id = war_page['training_war']
  149. response = war.info(war_id)
  150. assert isinstance(response, dict), "The response should be a dict"
  151. assert isinstance(response['damage'], int), "Damage should be an int"
  152. assert isinstance(response['attack_hourly_available'], bool), "Attack hourly should be a bool"
  153. assert isinstance(response['energ_drinks'], int), "Energy drinks should be an int"
  154. if 'max_hero_name' in response:
  155. assert isinstance(response['max_hero_name'], str), "max hero name should be a str"
  156. if 'max_hero_damage' in response:
  157. assert isinstance(response['max_hero_damage'], int), "max hero damage should be an int"
  158. if 'time_left' in response:
  159. assert isinstance(response['time_left'], timedelta), "time left should be a time delta"
  160. assert isinstance(response['finish_date'], datetime), "Finish date should be a date"
  161. assert isinstance(response['war_units'], dict), "war units should be a dict"
  162. @pytest.mark.vcr()
  163. def test_war_info_ground_war(api_wrapper):
  164. """Test war info"""
  165. war_id = 329541
  166. response = War(api_wrapper).info(war_id)
  167. assert isinstance(response, dict), "The response should be a dict"
  168. assert response['type'] == 'war', "Type should be a ground war"
  169. assert isinstance(response['attack'], dict), "Attack should be a dict"
  170. assert isinstance(response['attack']['state_id'], int), "State id should be an integer"
  171. assert isinstance(response['attack']['state_name'], str), "State nameshould be a string"
  172. assert isinstance(response['attack']['region_id'], int), "Region id should be an integer"
  173. assert isinstance(response['attack']['region_name'], str), "Region name should be a string"
  174. assert isinstance(response['attack']['damage'], int), "Damage should be an intger"
  175. assert isinstance(response['defend']['state_id'], int), "State id should be an integer"
  176. assert isinstance(response['defend']['state_name'], str), "State name should be a string"
  177. assert isinstance(response['defend']['region_id'], int), "Region id should be an integer"
  178. assert isinstance(response['defend']['region_name'], str), "Region name should be a string"
  179. assert isinstance(response['defend']['damage'], int), "Damage should be an integer"
  180. @pytest.mark.vcr()
  181. def test_war_info_coup(api_wrapper):
  182. """Test war info"""
  183. war_id = 329518
  184. response = War(api_wrapper).info(war_id)
  185. assert isinstance(response, dict), "The response should be a dict"
  186. assert response['type'] == 'coup', "Type should be a coup"
  187. @pytest.mark.vcr()
  188. def test_war_info_revolution(api_wrapper):
  189. """Test war info"""
  190. war_id = 329461
  191. response = War(api_wrapper).info(war_id)
  192. assert isinstance(response, dict), "The response should be a dict"
  193. assert response['type'] == 'revolution', "Type should be a revolution"
  194. @pytest.mark.vcr()
  195. def test_war_info_trooper_war(api_wrapper):
  196. """Test war info"""
  197. war_id = 329458
  198. response = War(api_wrapper).info(war_id)
  199. assert isinstance(response, dict), "The response should be a dict"
  200. assert response['type'] == 'troopers war', "Type should be a trooper war"
  201. @pytest.mark.vcr()
  202. def test_war_info_sea_war(api_wrapper):
  203. """Test war info"""
  204. war_id = 329618
  205. response = War(api_wrapper).info(war_id)
  206. assert isinstance(response, dict), "The response should be a dict"
  207. assert response['type'] == 'sea war', "Type should be a sea war"
  208. @pytest.mark.vcr()
  209. def test_war_info_space_war(api_wrapper):
  210. """Test war info"""
  211. war_id = 329531
  212. response = War(api_wrapper).info(war_id)
  213. assert isinstance(response, dict), "The response should be a dict"
  214. assert response['type'] == 'space war', "Type should be a space war"
  215. @pytest.mark.vcr()
  216. def test_work_info(api_wrapper):
  217. """Test work info"""
  218. response = Work(api_wrapper).page()
  219. assert isinstance(response, dict), "The response should be a dict"
  220. assert isinstance(response['factory'], dict), "Factory should be a dict"
  221. assert isinstance(response['resources_left'], dict), "Resources left should be a dict"
  222. assert isinstance(response['work_exp'], dict), "Work exp should be a dict"
  223. @pytest.mark.vcr()
  224. def test_work_do_work(api_wrapper):
  225. response = Work(api_wrapper).work()
  226. if not response:
  227. assert isinstance(response ,bool), "Should be False if can't work"
  228. else:
  229. assert isinstance(response['factory'], str), "The factory should be a string with name"
  230. assert isinstance(response['factory_type'], str), "The factory type should be a string of factory type"
  231. assert isinstance(response['income'][0], int), "The income first index should be a integer"
  232. assert isinstance(response['income'][1], str), "The income second index should be a string of units"
  233. @pytest.fixture
  234. def article_keys():
  235. """Standard key fro article"""
  236. return ['article_id', 'article_title', 'newspaper_id', 'newspaper_name', \
  237. 'author_name', 'author_id', 'region_name', 'region_id', 'content_text', 'content_html', \
  238. 'language', 'rating', 'comments', 'post_date']
  239. @pytest.mark.vcr()
  240. def test_article_info_one(api_wrapper, article_keys):
  241. """Test article info"""
  242. article_id = 2708696
  243. response = Article(api_wrapper).info(article_id)
  244. assert isinstance(response, dict), "The resonse should be a dict"
  245. assert set(article_keys).issubset(response.keys()), "All keys should be in the response"
  246. assert isinstance(response['article_id'], int), "Article id should be an integer"
  247. assert isinstance(response['article_title'], str), "Article title should be a str"
  248. assert isinstance(response['newspaper_id'], int), "Newspaper id should be an integer"
  249. assert isinstance(response['newspaper_name'], str), "Newspaper name should be a string"
  250. assert isinstance(response['author_name'], str), "Author name should be a string"
  251. assert isinstance(response['author_id'], int), "Author id should be an integer"
  252. assert isinstance(response['region_name'], str), "Region name should be a string"
  253. assert isinstance(response['region_id'], int), "Region id should be an integer"
  254. assert isinstance(response['content_text'], str), "Content text should be a string"
  255. assert isinstance(response['content_html'], str), "Content html should be a string"
  256. assert isinstance(response['language'], str), "Language should be a string"
  257. assert isinstance(response['rating'], int), "Rating should be an integer"
  258. assert isinstance(response['comments'], int), "Comments should be an integer"
  259. assert isinstance(response['post_date'], datetime), "Post date should be a datetime"
  260. @pytest.mark.vcr()
  261. def test_article_info_two(api_wrapper, article_keys):
  262. """Test article info"""
  263. article_id = 2862982
  264. response = Article(api_wrapper).info(article_id)
  265. assert isinstance(response, dict), "The resonse should be a dict"
  266. assert set(article_keys).issubset(response.keys()), "All keys should be in the response"
  267. assert isinstance(response['article_id'], int), "Article id should be an integer"
  268. assert isinstance(response['article_title'], str), "Article title should be a str"
  269. assert response['newspaper_id'] is None, "Newspaper id should be none"
  270. assert response['newspaper_name'] is None, "Newspaper name should be none"
  271. assert isinstance(response['author_name'], str), "Author name should be a string"
  272. assert isinstance(response['author_id'], int), "Author id should be an integer"
  273. assert isinstance(response['region_name'], str), "Region name should be a string"
  274. assert isinstance(response['region_id'], int), "Region id should be an integer"
  275. assert isinstance(response['content_text'], str), "Content text should be a string"
  276. assert isinstance(response['content_html'], str), "Content html should be a string"
  277. assert isinstance(response['language'], str), "Language should be a string"
  278. assert isinstance(response['rating'], int), "Rating should be an integer"
  279. assert isinstance(response['comments'], int), "Comments should be an integer"
  280. assert isinstance(response['post_date'], datetime), "Post date should be a datetime"