Skip to content

Commit 2c2633e

Browse files
committed
Test parsing of RATE_LIMITS in different formats
1 parent 76c1760 commit 2c2633e

1 file changed

Lines changed: 64 additions & 0 deletions

File tree

tests/test_ratelimits.py

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,72 @@
33
import pytest
44

55
from tests.common import get_response_json
6+
from xbox.webapi.api.provider.ratelimitedprovider import RateLimitedProvider
67

78
from xbox.webapi.common.exceptions import RateLimitExceededException
9+
from xbox.webapi.common.ratelimits import CombinedRateLimit
10+
from xbox.webapi.common.ratelimits.models import TimePeriod
11+
12+
13+
def helper_test_combinedratelimit(
14+
crl: CombinedRateLimit, burstLimit: int, sustainLimit: int
15+
):
16+
burst = crl.get_limits_by_period(TimePeriod.BURST)
17+
sustain = crl.get_limits_by_period(TimePeriod.SUSTAIN)
18+
19+
# These functions should return a list with one element
20+
assert type(burst) == list
21+
assert type(sustain) == list
22+
23+
assert len(burst) == 1
24+
assert len(sustain) == 1
25+
26+
# Check that their limits are what we expect
27+
assert burst[0].get_limit() == burstLimit
28+
assert sustain[0].get_limit() == sustainLimit
29+
30+
31+
def test_ratelimitedprovider_rate_limits_same_rw_values(xbl_client):
32+
class child_class(RateLimitedProvider):
33+
RATE_LIMITS = {"burst": 1, "sustain": 2}
34+
35+
instance = child_class(xbl_client)
36+
37+
helper_test_combinedratelimit(instance.rate_limit_read, 1, 2)
38+
helper_test_combinedratelimit(instance.rate_limit_write, 1, 2)
39+
40+
41+
def test_ratelimitedprovider_rate_limits_diff_rw_values(xbl_client):
42+
class child_class(RateLimitedProvider):
43+
RATE_LIMITS = {
44+
"burst": {"read": 1, "write": 2},
45+
"sustain": {"read": 3, "write": 4},
46+
}
47+
48+
instance = child_class(xbl_client)
49+
50+
helper_test_combinedratelimit(instance.rate_limit_read, 1, 3)
51+
helper_test_combinedratelimit(instance.rate_limit_write, 2, 4)
52+
53+
54+
def test_ratelimitedprovider_rate_limits_mixed(xbl_client):
55+
class burst_diff(RateLimitedProvider):
56+
RATE_LIMITS = {"burst": {"read": 1, "write": 2}, "sustain": 3}
57+
58+
burst_diff_inst = burst_diff(xbl_client)
59+
60+
# Sustain values are the same (third paramater)
61+
helper_test_combinedratelimit(burst_diff_inst.rate_limit_read, 1, 3)
62+
helper_test_combinedratelimit(burst_diff_inst.rate_limit_write, 2, 3)
63+
64+
class sustain_diff(RateLimitedProvider):
65+
RATE_LIMITS = {"burst": 4, "sustain": {"read": 5, "write": 6}}
66+
67+
sustain_diff_inst = sustain_diff(xbl_client)
68+
69+
# Burst values are the same (second paramater)
70+
helper_test_combinedratelimit(sustain_diff_inst.rate_limit_read, 4, 5)
71+
helper_test_combinedratelimit(sustain_diff_inst.rate_limit_write, 4, 6)
872

973

1074
@pytest.mark.asyncio

0 commit comments

Comments
 (0)