-
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 support for passing a list to filters in list_measurements (#929)
* Add support for passing a list to filters in list_measurements * Fix bug with input response and improve test to validate it * Fix error testing with multiple values in domain filter
- Loading branch information
Showing
2 changed files
with
148 additions
and
68 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
98 changes: 98 additions & 0 deletions
98
ooniapi/services/oonimeasurements/tests/test_measurements.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,98 @@ | ||
import pytest | ||
|
||
|
||
route = "api/v1/measurements" | ||
|
||
|
||
def test_list_measurements(client): | ||
response = client.get(route) | ||
json = response.json() | ||
|
||
assert isinstance(json["results"], list), json | ||
assert len(json["results"]) == 100 | ||
|
||
|
||
def test_list_measurements_with_since_and_until(client): | ||
params = { | ||
"since": "2024-01-01", | ||
"until": "2024-01-02", | ||
} | ||
|
||
response = client.get(route, params=params) | ||
json = response.json() | ||
|
||
assert isinstance(json["results"], list), json | ||
assert len(json["results"]) == 100 | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"filter_param, filter_value", | ||
[ | ||
("test_name", "web_connectivity"), | ||
("probe_cc", "IT"), | ||
("probe_asn", "AS30722"), | ||
] | ||
) | ||
def test_list_measurements_with_one_value_to_filters(client, filter_param, filter_value): | ||
params = {} | ||
params[filter_param] = 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_param] == filter_value, result | ||
|
||
|
||
def test_list_measurements_with_one_value_to_filters_not_present_in_the_result(client): | ||
domain = "cloudflare-dns.com" | ||
params = { | ||
"domain": domain, | ||
} | ||
|
||
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 domain in result["input"], result | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"filter_param, filter_value", | ||
[ | ||
("test_name", "web_connectivity,dnscheck,stunreachability,tor"), | ||
("probe_cc", "IT,US,RU"), | ||
("probe_asn", "AS30722,3269,7738,55430"), | ||
] | ||
) | ||
def test_list_measurements_with_multiple_values_to_filters(client, filter_param, filter_value): | ||
params = {} | ||
params[filter_param] = 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_param] in filter_value, result | ||
|
||
|
||
def test_list_measurements_with_multiple_values_to_filters_not_in_the_result(client): | ||
domainCollection = "cloudflare-dns.com, adblock.doh.mullvad.net, 1.1.1.1" | ||
params = { | ||
"domain": domainCollection | ||
} | ||
|
||
response = client.get(route, params=params) | ||
|
||
json = response.json() | ||
assert isinstance(json["results"], list), json | ||
assert len(json["results"]) > 0 | ||
domain_list = domainCollection.split(", ") | ||
for result in json["results"]: | ||
assert any(domain in result["input"] for domain in domain_list), result |