test_rival_regions_wrapper.py 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474
  1. """Wrapper test"""
  2. # pylint: disable=redefined-outer-name
  3. from datetime import datetime, timedelta
  4. import pytest
  5. from rival_regions_wrapper.api_wrapper import Profile, Storage, Market, \
  6. ResourceState, Perks, Craft, Overview, War, Work, Article, Conference
  7. @pytest.fixture
  8. def profile_keys():
  9. """Standard key from profile"""
  10. return [
  11. 'profile_id', 'name', 'level', 'level_percentage', 'strenght',
  12. 'education', 'endurance'
  13. ]
  14. @pytest.mark.vcr()
  15. def test_profile_info(api_wrapper, profile_keys):
  16. """Test an API call to get client info"""
  17. profile_instance = Profile(api_wrapper, 192852686)
  18. response = profile_instance.info()
  19. assert isinstance(response, dict), "The response should be a dict"
  20. assert response['profile_id'] == 192852686, \
  21. "The ID should be in the response"
  22. assert set(profile_keys).issubset(response.keys()), \
  23. "All keys should be in the response"
  24. assert isinstance(response['name'], str), "Name should be a string"
  25. assert isinstance(response['level'], int), "level should be a int"
  26. assert isinstance(response['level_percentage'], int), \
  27. "level_percentage should be a int"
  28. assert isinstance(response['strenght'], int), "strenght should be a int"
  29. assert isinstance(response['education'], int), "education should be a int"
  30. assert isinstance(response['endurance'], int), "endurance should be a int"
  31. @pytest.mark.skip(reason="message request")
  32. def test_profile_message(api_wrapper):
  33. """Test an API to send message to profile"""
  34. Profile(api_wrapper, 2000340574).message('hi')
  35. @pytest.fixture
  36. def storage_keys():
  37. """Standard keys for storage"""
  38. return [
  39. 'oil', 'ore', 'uranium', 'diamonds', 'liquid_oxygen',
  40. 'helium-3', 'rivalium', 'antirad', 'energy_drink',
  41. 'spacerockets', 'lss', 'tanks', 'aircrafts', 'missiles',
  42. 'bombers', 'battleships', 'laser_drones', 'moon_tanks',
  43. 'space_stations', 'oil_max', 'ore_max', 'uranium_max',
  44. 'diamonds_max', 'liquid_oxygen_max', 'helium-3_max',
  45. 'rivalium_max', 'antirad_max', 'energy_drink_max',
  46. 'spacerockets_max', 'lss_max', 'tanks_max', 'aircrafts_max',
  47. 'missiles_max', 'bombers_max', 'battleships_max',
  48. 'laser_drones_max', 'moon_tanks_max', 'space_stations'
  49. ]
  50. @pytest.mark.vcr()
  51. def test_storage_info(api_wrapper, storage_keys):
  52. """Test an API call to get storage info"""
  53. response = Storage(api_wrapper).info()
  54. assert isinstance(response, dict), "The response should be a dict"
  55. assert set(storage_keys).issubset(response.keys()), \
  56. "All keys should be in the response"
  57. @pytest.fixture
  58. def market_keys():
  59. """Standard keys for storage"""
  60. return ['player_id', 'player_name', 'price', 'amount']
  61. @pytest.mark.vcr()
  62. def test_market_info(api_wrapper, market_keys):
  63. """Test an API call to get market info"""
  64. resource = 'oil'
  65. response = Market(api_wrapper).info(resource)
  66. assert isinstance(response, list), "The response should be a list"
  67. if response:
  68. assert isinstance(response[0], dict), \
  69. "The first element should be a dict"
  70. assert set(market_keys).issubset(response[0].keys()), \
  71. "All keys should be in the response"
  72. assert isinstance(response[0]['player_id'], int), \
  73. "The player_id should be a int"
  74. assert isinstance(response[0]['player_name'], str), \
  75. "The player_name should be a int"
  76. assert isinstance(response[0]['price'], int), \
  77. "The price should be a int"
  78. assert isinstance(response[0]['amount'], int), \
  79. "The price should be a int"
  80. @pytest.fixture
  81. def resource_keys():
  82. """Standard keys for resource"""
  83. return [
  84. 'region_id', 'region_name', 'explored', 'maximum',
  85. 'deep_exploration', 'limit_left'
  86. ]
  87. @pytest.mark.vcr()
  88. def test_resource_state_info(api_wrapper, resource_keys):
  89. """Test an API call to get market info"""
  90. state = 3382
  91. resource = 'oil'
  92. response = ResourceState(api_wrapper, state).info(resource)
  93. assert isinstance(response, list), "The response should be a list"
  94. if response:
  95. assert isinstance(response[0], dict), \
  96. "The first element should be a dict"
  97. assert set(resource_keys).issubset(response[0].keys()), \
  98. "All keys should be in the response"
  99. assert isinstance(response[0]['region_id'], int), \
  100. "The region_id should be a int"
  101. assert isinstance(response[0]['region_name'], str), \
  102. "The region_name should be a str"
  103. assert isinstance(response[0]['explored'], float), \
  104. "The explored should be a float"
  105. assert isinstance(response[0]['maximum'], int), \
  106. "The maximum should be a int"
  107. assert isinstance(response[0]['deep_exploration'], int), \
  108. "deep_exploration should be int"
  109. assert isinstance(response[0]['limit_left'], int), \
  110. "The limit_left should be a int"
  111. @pytest.fixture
  112. def perks_keys():
  113. """Standard keys for perks"""
  114. return [
  115. 'strenght', 'education', 'endurance', 'upgrade_date',
  116. 'upgrade_perk'
  117. ]
  118. @pytest.mark.vcr()
  119. def test_perks_info(api_wrapper, perks_keys):
  120. """Test an API call to get perks info"""
  121. response = Perks(api_wrapper).info()
  122. assert isinstance(response, dict), \
  123. "The response should be a dict"
  124. assert set(perks_keys).issubset(response.keys()), \
  125. "All keys should be in the response"
  126. assert isinstance(response['strenght'], int), "strengt should be an int"
  127. assert isinstance(response['education'], int), "educatino should be an int"
  128. assert isinstance(response['endurance'], int), "endurance should be an int"
  129. try:
  130. assert isinstance(response['upgrade_date'], datetime), \
  131. "upgrade_date should be a date"
  132. assert isinstance(response['upgrade_perk'], int), \
  133. "upgrade_perk should be an int"
  134. except AssertionError:
  135. assert isinstance(response['upgrade_date'], type(None)), \
  136. "upgrade_date should be None if not upgrading"
  137. assert isinstance(response['upgrade_perk'], type(None)), \
  138. "upgrade_perk should be an int"
  139. @pytest.mark.skip(reason="Update request")
  140. def test_perks_upgrade(api_wrapper):
  141. """Test an API call to upgrade perk"""
  142. perk = 'endurance'
  143. upgrade_type = 'money'
  144. Perks(api_wrapper).upgrade(perk, upgrade_type)
  145. @pytest.fixture
  146. def craft_keys():
  147. """Standard keys for craft"""
  148. return ['market_price', 'resources']
  149. @pytest.mark.skip(reason="Update request")
  150. def test_craft_produce(api_wrapper):
  151. """Test an API call to produce new item"""
  152. item = 'energy_drink'
  153. Craft(api_wrapper).produce(item, 10)
  154. assert True
  155. @pytest.fixture
  156. def overview_info_keys():
  157. """Standard keys for overview info"""
  158. return ['perks', 'war']
  159. @pytest.mark.vcr()
  160. def test_overview_info(api_wrapper, overview_info_keys):
  161. """Test an API call for overview"""
  162. response = Overview(api_wrapper).info()
  163. assert isinstance(response, dict), "The response hould be a dict"
  164. assert set(overview_info_keys).issubset(response.keys()), \
  165. "All keys should be in the response"
  166. assert isinstance(response['war'], dict), "The war key should be a dict"
  167. @pytest.fixture
  168. def overview_status_keys():
  169. """Standard kenys for overview status"""
  170. return [
  171. 'profile_id', 'party_id', 'gold', 'money', 'level', 'exp'
  172. ]
  173. @pytest.mark.vcr()
  174. def test_overview_status(api_wrapper, overview_status_keys):
  175. """Test an API cal for status"""
  176. response = Overview(api_wrapper).status()
  177. assert isinstance(response, dict), "The response hould be a dict"
  178. assert set(overview_status_keys).issubset(response.keys()), \
  179. "All keys should be in the response"
  180. @pytest.mark.vcr()
  181. def test_war_page(api_wrapper):
  182. """Test getting training war"""
  183. response = War(api_wrapper).page()
  184. assert isinstance(response, dict), "The response should be a dict"
  185. if response['training_war']:
  186. assert isinstance(response['training_war'], int), \
  187. "The training_war should be an int"
  188. @pytest.mark.vcr()
  189. def test_war_info(api_wrapper):
  190. """Test war info"""
  191. war = War(api_wrapper)
  192. war_page = war.page()
  193. war_id = war_page['training_war']
  194. response = war.info(war_id)
  195. assert isinstance(response, dict), "The response should be a dict"
  196. assert isinstance(response['damage'], int), \
  197. "Damage should be an int"
  198. assert isinstance(response['attack_hourly_available'], bool), \
  199. "Attack hourly should be a bool"
  200. assert isinstance(response['energ_drinks'], int), \
  201. "Energy drinks should be an int"
  202. if 'max_hero_name' in response:
  203. assert isinstance(response['max_hero_name'], str), \
  204. "max hero name should be a str"
  205. if 'max_hero_damage' in response:
  206. assert isinstance(response['max_hero_damage'], int), \
  207. "max hero damage should be an int"
  208. if 'time_left' in response:
  209. assert isinstance(response['time_left'], timedelta), \
  210. "time left should be a time delta"
  211. assert isinstance(response['finish_date'], datetime), \
  212. "Finish date should be a date"
  213. assert isinstance(response['war_units'], dict), \
  214. "war units should be a dict"
  215. @pytest.mark.vcr()
  216. def test_war_info_ground_war(api_wrapper):
  217. """Test war info"""
  218. war_id = 329541
  219. response = War(api_wrapper).info(war_id)
  220. assert isinstance(response, dict), "The response should be a dict"
  221. assert response['type'] == 'war', "Type should be a ground war"
  222. assert isinstance(response['attack'], dict), "Attack should be a dict"
  223. assert isinstance(response['attack']['state_id'], int), \
  224. "State id should be an integer"
  225. assert isinstance(response['attack']['state_name'], str), \
  226. "State nameshould be a string"
  227. assert isinstance(response['attack']['region_id'], int), \
  228. "Region id should be an integer"
  229. assert isinstance(response['attack']['region_name'], str), \
  230. "Region name should be a string"
  231. assert isinstance(response['attack']['damage'], int), \
  232. "Damage should be an intger"
  233. assert isinstance(response['defend']['state_id'], int), \
  234. "State id should be an integer"
  235. assert isinstance(response['defend']['state_name'], str), \
  236. "State name should be a string"
  237. assert isinstance(response['defend']['region_id'], int), \
  238. "Region id should be an integer"
  239. assert isinstance(response['defend']['region_name'], str), \
  240. "Region name should be a string"
  241. assert isinstance(response['defend']['damage'], int), \
  242. "Damage should be an integer"
  243. @pytest.mark.vcr()
  244. def test_war_info_coup(api_wrapper):
  245. """Test war info"""
  246. war_id = 329518
  247. response = War(api_wrapper).info(war_id)
  248. assert isinstance(response, dict), "The response should be a dict"
  249. assert response['type'] == 'coup', "Type should be a coup"
  250. @pytest.mark.vcr()
  251. def test_war_info_revolution(api_wrapper):
  252. """Test war info"""
  253. war_id = 329461
  254. response = War(api_wrapper).info(war_id)
  255. assert isinstance(response, dict), "The response should be a dict"
  256. assert response['type'] == 'revolution', "Type should be a revolution"
  257. @pytest.mark.vcr()
  258. def test_war_info_trooper_war(api_wrapper):
  259. """Test war info"""
  260. war_id = 329458
  261. response = War(api_wrapper).info(war_id)
  262. assert isinstance(response, dict), "The response should be a dict"
  263. assert response['type'] == 'troopers war', "Type should be a trooper war"
  264. @pytest.mark.vcr()
  265. def test_war_info_sea_war(api_wrapper):
  266. """Test war info"""
  267. war_id = 329618
  268. response = War(api_wrapper).info(war_id)
  269. assert isinstance(response, dict), "The response should be a dict"
  270. assert response['type'] == 'sea war', "Type should be a sea war"
  271. @pytest.mark.vcr()
  272. def test_war_info_space_war(api_wrapper):
  273. """Test war info"""
  274. war_id = 329531
  275. response = War(api_wrapper).info(war_id)
  276. assert isinstance(response, dict), "The response should be a dict"
  277. assert response['type'] == 'space war', "Type should be a space war"
  278. @pytest.mark.vcr()
  279. def test_work_info(api_wrapper):
  280. """Test work info"""
  281. response = Work(api_wrapper).page()
  282. assert isinstance(response, dict), "The response should be a dict"
  283. assert isinstance(response['factory'], dict), "Factory should be a dict"
  284. assert isinstance(response['resources_left'], dict), \
  285. "Resources left should be a dict"
  286. assert isinstance(response['work_exp'], dict), "Work exp should be a dict"
  287. @pytest.fixture
  288. def article_keys():
  289. """Standard key fro article"""
  290. return [
  291. 'article_id', 'article_title', 'newspaper_id', 'newspaper_name',
  292. 'author_name', 'author_id', 'region_name', 'region_id',
  293. 'content_text', 'content_html', 'language', 'rating', 'comments',
  294. 'post_date'
  295. ]
  296. @pytest.mark.vcr()
  297. def test_article_info_one(api_wrapper, article_keys):
  298. """Test article info"""
  299. article_id = 2708696
  300. response = Article(api_wrapper).info(article_id)
  301. assert isinstance(response, dict), "The resonse should be a dict"
  302. assert set(article_keys).issubset(response.keys()), \
  303. "All keys should be in the response"
  304. assert isinstance(response['article_id'], int), \
  305. "Article id should be an integer"
  306. assert isinstance(response['article_title'], str), \
  307. "Article title should be a str"
  308. assert isinstance(response['newspaper_id'], int), \
  309. "Newspaper id should be an integer"
  310. assert isinstance(response['newspaper_name'], str), \
  311. "Newspaper name should be a string"
  312. assert isinstance(response['author_name'], str), \
  313. "Author name should be a string"
  314. assert isinstance(response['author_id'], int), \
  315. "Author id should be an integer"
  316. assert isinstance(response['region_name'], str), \
  317. "Region name should be a string"
  318. assert isinstance(response['region_id'], int), \
  319. "Region id should be an integer"
  320. assert isinstance(response['content_text'], str), \
  321. "Content text should be a string"
  322. assert isinstance(response['content_html'], str), \
  323. "Content html should be a string"
  324. assert isinstance(response['language'], str), \
  325. "Language should be a string"
  326. assert isinstance(response['rating'], int), \
  327. "Rating should be an integer"
  328. assert isinstance(response['comments'], int), \
  329. "Comments should be an integer"
  330. assert isinstance(response['post_date'], datetime), \
  331. "Post date should be a datetime"
  332. @pytest.mark.vcr()
  333. def test_article_info_two(api_wrapper, article_keys):
  334. """Test article info"""
  335. article_id = 2862982
  336. response = Article(api_wrapper).info(article_id)
  337. assert isinstance(response, dict), "The resonse should be a dict"
  338. assert set(article_keys).issubset(response.keys()), \
  339. "All keys should be in the response"
  340. assert isinstance(response['article_id'], int), \
  341. "Article id should be an integer"
  342. assert isinstance(response['article_title'], str), \
  343. "Article title should be a str"
  344. assert response['newspaper_id'] is None, "Newspaper id should be none"
  345. assert response['newspaper_name'] is None, "Newspaper name should be none"
  346. assert isinstance(response['author_name'], str), \
  347. "Author name should be a string"
  348. assert isinstance(response['author_id'], int), \
  349. "Author id should be an integer"
  350. assert isinstance(response['region_name'], str), \
  351. "Region name should be a string"
  352. assert isinstance(response['region_id'], int), \
  353. "Region id should be an integer"
  354. assert isinstance(response['content_text'], str), \
  355. "Content text should be a string"
  356. assert isinstance(response['content_html'], str), \
  357. "Content html should be a string"
  358. assert isinstance(response['language'], str), "Language should be a string"
  359. assert isinstance(response['rating'], int), "Rating should be an integer"
  360. assert isinstance(response['comments'], int), \
  361. "Comments should be an integer"
  362. assert isinstance(response['post_date'], datetime), \
  363. "Post date should be a datetime"
  364. @pytest.mark.skip(reason="message request")
  365. def test_conference_message(api_wrapper):
  366. """Test conference message"""
  367. conference_id = 439289
  368. Conference(api_wrapper, conference_id).message('hi')
  369. @pytest.mark.skip(reason="notification request")
  370. def test_conference_notification(api_wrapper):
  371. """Test conference notification"""
  372. conference_id = 439289
  373. Conference(api_wrapper, conference_id).notification('hi', True)
  374. @pytest.mark.skip(reason="notification request")
  375. def test_conference_change_title(api_wrapper):
  376. """Test conference change title"""
  377. conference_id = 439289
  378. Conference(api_wrapper, conference_id).change_title('new title')
  379. @pytest.mark.skip(reason="message request")
  380. def test_language_chat_(api_wrapper):
  381. """Test an API to send message to profile"""
  382. Profile(api_wrapper, 2000340574).message('hi')