test_rival_regions_wrapper.py 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. """Wrapper test"""
  2. from datetime import datetime
  3. import pytest
  4. from rival_regions_wrapper.api_wrapper import Profile, Storage, Market, ResourceState, Perks, Craft
  5. @pytest.fixture
  6. def profile_keys():
  7. """Standard key from profile"""
  8. return ['profile_id', 'name', 'level', 'level_percentage', 'strenght', 'education', 'endurance']
  9. @pytest.mark.vcr()
  10. def test_profile_info(profile_keys):
  11. """Test an API call to get client info"""
  12. profile_instance = Profile(192852686)
  13. response = profile_instance.info()
  14. assert isinstance(response, dict), "The response should be a dict"
  15. assert response['profile_id'] == 192852686, "The ID should be in the response"
  16. assert set(profile_keys).issubset(response.keys()), "All keys should be in the response"
  17. assert isinstance(response['name'], str), "Name should be a string"
  18. assert isinstance(response['level'], int), "level should be a int"
  19. assert isinstance(response['level_percentage'], int), "level_percentage should be a int"
  20. assert isinstance(response['strenght'], int), "strenght should be a int"
  21. assert isinstance(response['education'], int), "education should be a int"
  22. assert isinstance(response['endurance'], int), "endurance should be a int"
  23. @pytest.fixture
  24. def storage_keys():
  25. """Standard keys for storage"""
  26. return [
  27. 'oil', 'ore', 'uranium', 'diamonds', 'liquid_oxygen',
  28. 'helium-3', 'rivalium', 'antirad', 'energy_drink',
  29. 'spacerockets', 'lss', 'tanks', 'aircrafts', 'missiles',
  30. 'bombers', 'battleships', 'laser_drones', 'moon_tanks', 'space_stations',
  31. 'oil_max', 'ore_max', 'uranium_max', 'diamonds_max', 'liquid_oxygen_max',
  32. 'helium-3_max', 'rivalium_max', 'antirad_max', 'energy_drink_max',
  33. 'spacerockets_max', 'lss_max', 'tanks_max', 'aircrafts_max', 'missiles_max',
  34. 'bombers_max', 'battleships_max', 'laser_drones_max', 'moon_tanks_max', 'space_stations'
  35. ]
  36. @pytest.mark.vcr()
  37. def test_storage_info(storage_keys):
  38. """Test an API call to get storage info"""
  39. response = Storage.info()
  40. assert isinstance(response, dict), "The response should be a dict"
  41. assert set(storage_keys).issubset(response.keys()), "All keys should be in the response"
  42. @pytest.fixture
  43. def market_keys():
  44. """Standard keys for storage"""
  45. return ['player_id', 'player_name', 'price', 'amount']
  46. @pytest.mark.vcr()
  47. def test_market_info(market_keys):
  48. """Test an API call to get market info"""
  49. resource = 'oil'
  50. response = Market.info(resource)
  51. assert isinstance(response, list), "The response should be a list"
  52. if response:
  53. assert isinstance(response[0], dict), "The first element should be a dict"
  54. assert set(market_keys).issubset(response[0].keys()), "All keys should be in the response"
  55. assert isinstance(response[0]['player_id'], int), "The player_id should be a int"
  56. assert isinstance(response[0]['player_name'], str), "The player_name should be a int"
  57. assert isinstance(response[0]['price'], int), "The price should be a int"
  58. assert isinstance(response[0]['amount'], int), "The price should be a int"
  59. @pytest.fixture
  60. def resource_keys():
  61. """Standard keys for resource"""
  62. return ['region_id', 'region_name', 'explored', 'maximum', 'deep_exploration', 'limit_left']
  63. @pytest.mark.vcr()
  64. def test_resource_state_info(resource_keys):
  65. """Test an API call to get market info"""
  66. state = 3382
  67. resource = 'oil'
  68. response = ResourceState.info(state, resource)
  69. assert isinstance(response, list), "The response should be a list"
  70. if response:
  71. assert isinstance(response[0], dict), "The first element should be a dict"
  72. assert set(resource_keys).issubset(response[0].keys()), "All keys should be in the response"
  73. assert isinstance(response[0]['region_id'], int), "The region_id should be a int"
  74. assert isinstance(response[0]['region_name'], str), "The region_name should be a str"
  75. assert isinstance(response[0]['explored'], float), "The explored should be a float"
  76. assert isinstance(response[0]['maximum'], int), "The maximum should be a int"
  77. assert isinstance(response[0]['deep_exploration'], int), "deep_exploration should be int"
  78. assert isinstance(response[0]['limit_left'], int), "The limit_left should be a int"
  79. @pytest.fixture
  80. def perks_keys():
  81. """Standard keys for perks"""
  82. return ['strenght', 'education', 'endurance', 'upgrade_date', 'upgrade_perk']
  83. @pytest.mark.vcr()
  84. def test_perks_info(perks_keys):
  85. """Test an API call to get perks info"""
  86. response = Perks.info()
  87. assert isinstance(response, dict), "The response should be a dict"
  88. assert set(perks_keys).issubset(response.keys()), "All keys should be in the response"
  89. assert isinstance(response['strenght'], int), "strengt should be an int"
  90. assert isinstance(response['education'], int), "educatino should be an int"
  91. assert isinstance(response['endurance'], int), "endurance should be an int"
  92. assert isinstance(response['upgrade_date'], datetime), "upgrade_date should be a date"
  93. assert isinstance(response['upgrade_perk'], int), "upgrade_perk should be an int"
  94. @pytest.fixture
  95. def craft_keys():
  96. """Standard keys for craft"""
  97. return ['market_price', 'resources']
  98. @pytest.mark.vcr()
  99. def test_craft_info(craft_keys):
  100. """Test an API call to get craft info"""
  101. item = 'bombers'
  102. response = Craft.info(item)
  103. assert isinstance(response, dict), "The response should be a dict"
  104. assert isinstance(response['market_price'], int), "The market_price should be an int"
  105. assert isinstance(response['resources'], dict), "The resources should be a dict"
  106. assert isinstance(response['resources']['cash'], int), "The cash should be an int"
  107. assert isinstance(response['resources']['oil'], int), "The oil should be an int"
  108. assert isinstance(response['resources']['ore'], int), "The ore should be an int"
  109. assert isinstance(response['resources']['diamond'], int), "The diamond should be an int"