Skip to content

Commit 9e3bcc3

Browse files
committed
add test for adding quotas
1 parent 6ea03c9 commit 9e3bcc3

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

backend/test_nightly/conftest.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
CRAWLER_USERNAME = "crawlernightly@example.com"
1414
CRAWLER_PW = "crawlerPASSWORD!"
1515

16+
PRESHARED_SECRET_PW = "PASSWORD!"
17+
1618

1719
@pytest.fixture(scope="session")
1820
def admin_auth_headers():
@@ -33,6 +35,11 @@ def admin_auth_headers():
3335
time.sleep(5)
3436

3537

38+
@pytest.fixture(scope="session")
39+
def preshared_secret_auth_headers():
40+
return {"Authorization": f"Bearer {PRESHARED_SECRET_PW}"}
41+
42+
3643
@pytest.fixture(scope="session")
3744
def default_org_id(admin_auth_headers):
3845
while True:

backend/test_nightly/test_execution_minutes_quota.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
GIFTED_SECS_QUOTA = GIFTED_MINS_QUOTA * 60
1616
EXTRA_MINS_QUOTA = 5
1717
EXTRA_SECS_QUOTA = EXTRA_MINS_QUOTA * 60
18+
EXTRA_MINS_ADDED_QUOTA = 7
19+
EXTRA_SECS_ADDED_QUOTA = EXTRA_MINS_ADDED_QUOTA * 60
1820

1921
config_id = None
2022

@@ -107,6 +109,43 @@ def test_set_execution_mins_extra_quotas(org_with_quotas, admin_auth_headers):
107109
assert update["update"]
108110

109111

112+
def test_add_execution_mins_extra_quotas(
113+
org_with_quotas, admin_auth_headers, preshared_secret_auth_headers
114+
):
115+
r = requests.post(
116+
f"{API_PREFIX}/orgs/{org_with_quotas}/quotas/add",
117+
headers=preshared_secret_auth_headers,
118+
json={
119+
"extraExecMinutes": EXTRA_MINS_ADDED_QUOTA,
120+
"context": "test context 123",
121+
},
122+
)
123+
data = r.json()
124+
assert data.get("updated") == True
125+
126+
# Ensure org data looks as we expect
127+
r = requests.get(
128+
f"{API_PREFIX}/orgs/{org_with_quotas}",
129+
headers=admin_auth_headers,
130+
)
131+
data = r.json()
132+
assert (
133+
data["extraExecSecondsAvailable"] == EXTRA_SECS_QUOTA + EXTRA_SECS_ADDED_QUOTA
134+
)
135+
assert data["giftedExecSecondsAvailable"] == GIFTED_SECS_QUOTA
136+
assert data["extraExecSeconds"] == {}
137+
assert data["giftedExecSeconds"] == {}
138+
assert (
139+
get_total_exec_seconds(data["crawlExecSeconds"])
140+
>= EXEC_SECS_QUOTA + EXTRA_SECS_ADDED_QUOTA
141+
)
142+
assert len(data["quotaUpdates"])
143+
for update in data["quotaUpdates"]:
144+
assert update["modified"]
145+
assert update["update"]
146+
assert data["quotaUpdates"][-1]["context"] == "test context 123"
147+
148+
110149
@pytest.mark.timeout(1200)
111150
def test_crawl_stopped_when_quota_reached_with_extra(
112151
org_with_quotas, admin_auth_headers

0 commit comments

Comments
 (0)