-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add E2E tests to aggregate observations endpoint and refactor with fi…
…xture
- Loading branch information
Showing
6 changed files
with
193 additions
and
122 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
ooniapi/services/oonimeasurements/tests/test_oonidata_aggregate_observations.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import pytest | ||
|
||
route = "api/v1/aggregation/observations" | ||
|
||
|
||
def test_oonidata_aggregation_observations(client): | ||
response = client.get(route) | ||
|
||
json = response.json() | ||
assert isinstance(json["results"], list), json | ||
assert len(json["results"]) == 0 | ||
|
||
|
||
def test_oonidata_aggregation_observations_with_since_and_until(client, params_since_and_until_with_two_days): | ||
response = client.get(route, params=params_since_and_until_with_two_days) | ||
|
||
json = response.json() | ||
assert isinstance(json["results"], list), json | ||
assert len(json["results"]) > 0 | ||
|
||
for result in json["results"]: | ||
assert "observation_count" in result, result | ||
assert "failure" in result, result | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"filter_name, filter_value", | ||
[ | ||
("probe_cc", "IT"), | ||
("probe_asn", 45758), | ||
("test_name", "whatsapp"), | ||
("hostname", "www.on-instant.com"), | ||
("ip", "64.233.190.139"), | ||
] | ||
) | ||
def test_oonidata_aggregation_observations_with_filters(client, filter_name, filter_value, params_since_and_until_with_ten_days): | ||
params = params_since_and_until_with_ten_days | ||
params[filter_name] = filter_value | ||
|
||
response = client.get(route, params=params) | ||
|
||
json = response.json() | ||
assert isinstance(json["results"], list), json | ||
assert len(json["results"]) > 0 | ||
for result in json["results"]: | ||
assert result[filter_name] == filter_value, result | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"time_grain, total", | ||
[ | ||
("hour", 215), | ||
("day", 9), | ||
("week", 2), | ||
("month", 1), | ||
("year", 1), | ||
("auto", 9), | ||
] | ||
) | ||
def test_oonidata_aggregation_observations_time_grain(client, time_grain, total, params_since_and_until_with_ten_days): | ||
params = params_since_and_until_with_ten_days | ||
params["group_by"] = "timestamp" | ||
params["time_grain"] = time_grain | ||
|
||
response = client.get(route, params=params) | ||
|
||
json = response.json() | ||
assert len(json["results"]) == total |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.