test_rival_regions_wrapper.py 17 KB

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