-
Notifications
You must be signed in to change notification settings - Fork 522
Expand file tree
/
Copy pathtest_influx_query_throttle.py
More file actions
35 lines (29 loc) · 1.04 KB
/
test_influx_query_throttle.py
File metadata and controls
35 lines (29 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
from django.urls import reverse
from pytest_mock import MockerFixture
from rest_framework import status
from rest_framework.test import APIClient
def test_influx_data_endpoint_is_throttled( # noqa: FT003
admin_client: APIClient,
organisation: int,
mocker: MockerFixture,
reset_cache: None,
) -> None:
# Given
mocker.patch(
"app_analytics.throttles.InfluxQueryThrottle.get_rate", return_value="1/minute"
)
mocker.patch(
"organisations.views.get_multiple_event_list_for_organisation", return_value=[]
)
url = reverse(
"api-v1:organisations:organisation-get-influx-data",
args=[organisation],
)
# When - first request should be successful
first_response = admin_client.get(url)
second_response = admin_client.get(url)
# Then
# The first response should have been successful
assert first_response.status_code == status.HTTP_200_OK
# But the second request should have been throttled
assert second_response.status_code == status.HTTP_429_TOO_MANY_REQUESTS