test_rival_regions_wrapper.py 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468
  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, profile_id, message):
  34. """Test an API to send message to profile"""
  35. Profile(middleware, profile_id).message(message)
  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, perk, perk_upgrade_type):
  142. """Test an API call to upgrade perk"""
  143. Perks(middleware).upgrade(perk, perk_upgrade_type)
  144. @pytest.fixture
  145. def craft_keys():
  146. """Standard keys for craft"""
  147. return ['market_price', 'resources']
  148. @pytest.mark.skip(reason="Update request")
  149. def test_craft_produce(middleware, craft_item, craft_amount):
  150. """Test an API call to craft a new item"""
  151. Craft(middleware).produce(craft_item, craft_amount)
  152. assert True
  153. @pytest.fixture
  154. def overview_info_keys():
  155. """Standard keys for overview info"""
  156. return ['perks', 'war']
  157. @pytest.mark.vcr()
  158. def test_overview_info(middleware, overview_info_keys):
  159. """Test an API call for overview"""
  160. response = Overview(middleware).info()
  161. assert isinstance(response, dict), "The response hould be a dict"
  162. assert set(overview_info_keys).issubset(response.keys()), \
  163. "All keys should be in the response"
  164. assert isinstance(response['war'], dict), "The war key should be a dict"
  165. @pytest.fixture
  166. def overview_status_keys():
  167. """Standard kenys for overview status"""
  168. return [
  169. 'profile_id', 'party_id', 'gold', 'money', 'level', 'exp'
  170. ]
  171. @pytest.mark.vcr()
  172. def test_overview_status(middleware, overview_status_keys):
  173. """Test an API cal for status"""
  174. response = Overview(middleware).status()
  175. assert isinstance(response, dict), "The response hould be a dict"
  176. assert set(overview_status_keys).issubset(response.keys()), \
  177. "All keys should be in the response"
  178. @pytest.mark.vcr()
  179. def test_war_page(middleware):
  180. """Test getting training war"""
  181. response = War(middleware).page()
  182. assert isinstance(response, dict), "The response should be a dict"
  183. if response['training_war']:
  184. assert isinstance(response['training_war'], int), \
  185. "The training_war should be an int"
  186. @pytest.mark.vcr()
  187. def test_war_info(middleware):
  188. """Test war info"""
  189. war = War(middleware)
  190. war_page = war.page()
  191. war_id = war_page['training_war']
  192. response = war.info(war_id)
  193. assert isinstance(response, dict), "The response should be a dict"
  194. assert isinstance(response['damage'], int), \
  195. "Damage should be an int"
  196. assert isinstance(response['attack_hourly_available'], bool), \
  197. "Attack hourly should be a bool"
  198. assert isinstance(response['energ_drinks'], int), \
  199. "Energy drinks should be an int"
  200. if 'max_hero_name' in response:
  201. assert isinstance(response['max_hero_name'], str), \
  202. "max hero name should be a str"
  203. if 'max_hero_damage' in response:
  204. assert isinstance(response['max_hero_damage'], int), \
  205. "max hero damage should be an int"
  206. if 'time_left' in response:
  207. assert isinstance(response['time_left'], timedelta), \
  208. "time left should be a time delta"
  209. assert isinstance(response['finish_date'], datetime), \
  210. "Finish date should be a date"
  211. assert isinstance(response['war_units'], dict), \
  212. "war units should be a dict"
  213. @pytest.mark.vcr()
  214. def test_war_info_ground_war(middleware):
  215. """Test war info"""
  216. war_id = 329541
  217. response = War(middleware).info(war_id)
  218. assert isinstance(response, dict), "The response should be a dict"
  219. assert response['type'] == 'war', "Type should be a ground war"
  220. assert isinstance(response['attack'], dict), "Attack should be a dict"
  221. assert isinstance(response['attack']['state_id'], int), \
  222. "State id should be an integer"
  223. assert isinstance(response['attack']['state_name'], str), \
  224. "State nameshould be a string"
  225. assert isinstance(response['attack']['region_id'], int), \
  226. "Region id should be an integer"
  227. assert isinstance(response['attack']['region_name'], str), \
  228. "Region name should be a string"
  229. assert isinstance(response['attack']['damage'], int), \
  230. "Damage should be an intger"
  231. assert isinstance(response['defend']['state_id'], int), \
  232. "State id should be an integer"
  233. assert isinstance(response['defend']['state_name'], str), \
  234. "State name should be a string"
  235. assert isinstance(response['defend']['region_id'], int), \
  236. "Region id should be an integer"
  237. assert isinstance(response['defend']['region_name'], str), \
  238. "Region name should be a string"
  239. assert isinstance(response['defend']['damage'], int), \
  240. "Damage should be an integer"
  241. @pytest.mark.vcr()
  242. def test_war_info_coup(middleware):
  243. """Test war info"""
  244. war_id = 329518
  245. response = War(middleware).info(war_id)
  246. assert isinstance(response, dict), "The response should be a dict"
  247. assert response['type'] == 'coup', "Type should be a coup"
  248. @pytest.mark.vcr()
  249. def test_war_info_revolution(middleware):
  250. """Test war info"""
  251. war_id = 329461
  252. response = War(middleware).info(war_id)
  253. assert isinstance(response, dict), "The response should be a dict"
  254. assert response['type'] == 'revolution', "Type should be a revolution"
  255. @pytest.mark.vcr()
  256. def test_war_info_trooper_war(middleware):
  257. """Test war info"""
  258. war_id = 329458
  259. response = War(middleware).info(war_id)
  260. assert isinstance(response, dict), "The response should be a dict"
  261. assert response['type'] == 'troopers war', "Type should be a trooper war"
  262. @pytest.mark.vcr()
  263. def test_war_info_sea_war(middleware):
  264. """Test war info"""
  265. war_id = 329618
  266. response = War(middleware).info(war_id)
  267. assert isinstance(response, dict), "The response should be a dict"
  268. assert response['type'] == 'sea war', "Type should be a sea war"
  269. @pytest.mark.vcr()
  270. def test_war_info_space_war(middleware):
  271. """Test war info"""
  272. war_id = 329531
  273. response = War(middleware).info(war_id)
  274. assert isinstance(response, dict), "The response should be a dict"
  275. assert response['type'] == 'space war', "Type should be a space war"
  276. @pytest.mark.vcr()
  277. def test_work_info(middleware):
  278. """Test work info"""
  279. response = Work(middleware).page()
  280. assert isinstance(response, dict), "The response should be a dict"
  281. assert isinstance(response['factory'], dict), "Factory should be a dict"
  282. assert isinstance(response['resources_left'], dict), \
  283. "Resources left should be a dict"
  284. assert isinstance(response['work_exp'], dict), "Work exp should be a dict"
  285. @pytest.fixture
  286. def article_keys():
  287. """Standard key fro article"""
  288. return [
  289. 'article_id', 'article_title', 'newspaper_id', 'newspaper_name',
  290. 'author_name', 'author_id', 'region_name', 'region_id',
  291. 'content_text', 'content_html', 'language', 'rating', 'comments',
  292. 'post_date'
  293. ]
  294. @pytest.mark.vcr()
  295. def test_article_info_one(middleware, article_keys):
  296. """Test article info"""
  297. article_id = 2708696
  298. response = Article(middleware).info(article_id)
  299. assert isinstance(response, dict), "The resonse should be a dict"
  300. assert set(article_keys).issubset(response.keys()), \
  301. "All keys should be in the response"
  302. assert isinstance(response['article_id'], int), \
  303. "Article id should be an integer"
  304. assert isinstance(response['article_title'], str), \
  305. "Article title should be a str"
  306. assert isinstance(response['newspaper_id'], int), \
  307. "Newspaper id should be an integer"
  308. assert isinstance(response['newspaper_name'], str), \
  309. "Newspaper name should be a string"
  310. assert isinstance(response['author_name'], str), \
  311. "Author name should be a string"
  312. assert isinstance(response['author_id'], int), \
  313. "Author id should be an integer"
  314. assert isinstance(response['region_name'], str), \
  315. "Region name should be a string"
  316. assert isinstance(response['region_id'], int), \
  317. "Region id should be an integer"
  318. assert isinstance(response['content_text'], str), \
  319. "Content text should be a string"
  320. assert isinstance(response['content_html'], str), \
  321. "Content html should be a string"
  322. assert isinstance(response['language'], str), \
  323. "Language should be a string"
  324. assert isinstance(response['rating'], int), \
  325. "Rating should be an integer"
  326. assert isinstance(response['comments'], int), \
  327. "Comments should be an integer"
  328. assert isinstance(response['post_date'], datetime), \
  329. "Post date should be a datetime"
  330. @pytest.mark.vcr()
  331. def test_article_info_two(middleware, article_keys):
  332. """Test article info"""
  333. article_id = 2862982
  334. response = Article(middleware).info(article_id)
  335. assert isinstance(response, dict), "The resonse should be a dict"
  336. assert set(article_keys).issubset(response.keys()), \
  337. "All keys should be in the response"
  338. assert isinstance(response['article_id'], int), \
  339. "Article id should be an integer"
  340. assert isinstance(response['article_title'], str), \
  341. "Article title should be a str"
  342. assert response['newspaper_id'] is None, "Newspaper id should be none"
  343. assert response['newspaper_name'] is None, "Newspaper name should be none"
  344. assert isinstance(response['author_name'], str), \
  345. "Author name should be a string"
  346. assert isinstance(response['author_id'], int), \
  347. "Author id should be an integer"
  348. assert isinstance(response['region_name'], str), \
  349. "Region name should be a string"
  350. assert isinstance(response['region_id'], int), \
  351. "Region id should be an integer"
  352. assert isinstance(response['content_text'], str), \
  353. "Content text should be a string"
  354. assert isinstance(response['content_html'], str), \
  355. "Content html should be a string"
  356. assert isinstance(response['language'], str), "Language should be a string"
  357. assert isinstance(response['rating'], int), "Rating should be an integer"
  358. assert isinstance(response['comments'], int), \
  359. "Comments should be an integer"
  360. assert isinstance(response['post_date'], datetime), \
  361. "Post date should be a datetime"
  362. @pytest.mark.skip(reason="conference message request")
  363. def test_conference_message(middleware, conference_id, message):
  364. """Test conference message"""
  365. Conference(middleware, conference_id).message(message)
  366. @pytest.mark.skip(reason="conference notification request")
  367. def test_conference_notification(middleware, conference_id, message):
  368. """Test conference notification"""
  369. Conference(middleware, conference_id).notification(message, True)
  370. @pytest.mark.skip(reason="conference title change request")
  371. def test_conference_change_title(middleware, conference_id, conference_title):
  372. """Test conference change title"""
  373. Conference(middleware, conference_id).change_title(conference_title)
  374. @pytest.mark.skip(reason="language chat message request")
  375. def test_language_chat_message(middleware, language_chat, message):
  376. """Test sending message to language chat"""
  377. LanguageChat(middleware, language_chat).message(message)