|
5 | 5 | from tests.common import get_response_json |
6 | 6 | from xbox.webapi.api.provider.ratelimitedprovider import RateLimitedProvider |
7 | 7 |
|
8 | | -from xbox.webapi.common.exceptions import RateLimitExceededException |
| 8 | +from xbox.webapi.common.exceptions import RateLimitExceededException, XboxException |
9 | 9 | from xbox.webapi.common.ratelimits import CombinedRateLimit |
10 | 10 | from xbox.webapi.common.ratelimits.models import TimePeriod |
11 | 11 |
|
@@ -71,6 +71,39 @@ class sustain_diff(RateLimitedProvider): |
71 | 71 | helper_test_combinedratelimit(sustain_diff_inst.rate_limit_write, 4, 6) |
72 | 72 |
|
73 | 73 |
|
| 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 | + |
74 | 107 | @pytest.mark.asyncio |
75 | 108 | async def test_ratelimits_exceeded_burst_only(respx_mock, xbl_client): |
76 | 109 | async def make_request(): |
|
0 commit comments