Skip to content

Commit c2ee539

Browse files
committed
Add tests for RateLimitProvider error handling
1 parent 4b9fca0 commit c2ee539

1 file changed

Lines changed: 34 additions & 1 deletion

File tree

tests/test_ratelimits.py

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from tests.common import get_response_json
66
from xbox.webapi.api.provider.ratelimitedprovider import RateLimitedProvider
77

8-
from xbox.webapi.common.exceptions import RateLimitExceededException
8+
from xbox.webapi.common.exceptions import RateLimitExceededException, XboxException
99
from xbox.webapi.common.ratelimits import CombinedRateLimit
1010
from xbox.webapi.common.ratelimits.models import TimePeriod
1111

@@ -71,6 +71,39 @@ class sustain_diff(RateLimitedProvider):
7171
helper_test_combinedratelimit(sustain_diff_inst.rate_limit_write, 4, 6)
7272

7373

74+
def test_ratelimitedprovider_rate_limits_missing_values_correct_type(xbl_client):
75+
class child_class(RateLimitedProvider):
76+
RATE_LIMITS = {"incorrect": "values"}
77+
78+
with pytest.raises(XboxException) as exception:
79+
child_class(xbl_client)
80+
81+
ex: XboxException = exception.value
82+
assert "RATE_LIMITS object missing required keys" in ex.args[0]
83+
84+
85+
def test_ratelimitedprovider_rate_limits_not_set(xbl_client):
86+
class child_class(RateLimitedProvider):
87+
pass
88+
89+
with pytest.raises(XboxException) as exception:
90+
child_class(xbl_client)
91+
92+
ex: XboxException = exception.value
93+
assert "RateLimitedProvider as parent class but RATE_LIMITS not set!" in ex.args[0]
94+
95+
96+
def test_ratelimitedprovider_rate_limits_incorrect_key_type(xbl_client):
97+
class child_class(RateLimitedProvider):
98+
RATE_LIMITS = {"burst": True, "sustain": False}
99+
100+
with pytest.raises(XboxException) as exception:
101+
child_class(xbl_client)
102+
103+
ex: XboxException = exception.value
104+
assert "RATE_LIMITS value types not recognised." in ex.args[0]
105+
106+
74107
@pytest.mark.asyncio
75108
async def test_ratelimits_exceeded_burst_only(respx_mock, xbl_client):
76109
async def make_request():

0 commit comments

Comments
 (0)