Skip to content

Commit

Permalink
Add version filtering to list_measurements
Browse files Browse the repository at this point in the history
  • Loading branch information
FedericoCeratto authored and Federico Ceratto committed Sep 7, 2023
1 parent a59a47f commit 3b1902c
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 0 deletions.
31 changes: 31 additions & 0 deletions api/ooniapi/measurements.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
from ooniapi.urlparams import (
param_asn,
param_bool,
param_commasplit,
param_date,
param_input_or_none,
param_report_id,
Expand Down Expand Up @@ -644,6 +645,21 @@ def list_measurements() -> Response:
Set "true" for failed measurements (the control request failed, there was a bug, etc.).
Default: both true and false
- name: software_version
in: query
type: string
description: Filter measurements by software version. Comma-separated.
- name: test_version
in: query
type: string
description: Filter measurements by test version. Comma-separated.
- name: engine_version
in: query
type: string
description: Filter measurements by engine version. Comma-separated.
- name: order_by
in: query
type: string
Expand Down Expand Up @@ -698,6 +714,9 @@ def list_measurements() -> Response:
anomaly = param_bool("anomaly")
confirmed = param_bool("confirmed")
category_code = param("category_code")
software_versions = param_commasplit("software_version")
test_versions = param_commasplit("test_version")
engine_versions = param_commasplit("engine_version")

# Workaround for https://github.com/ooni/probe/issues/1034
user_agent = request.headers.get("User-Agent", "")
Expand Down Expand Up @@ -788,6 +807,18 @@ def list_measurements() -> Response:
query_params["test_name"] = test_name
fpwhere.append(sql.text("test_name = :test_name"))

if software_versions is not None:
query_params["software_versions"] = software_versions
fpwhere.append(sql.text("software_version IN :software_versions"))

if test_versions is not None:
query_params["test_versions"] = test_versions
fpwhere.append(sql.text("test_version IN :test_versions"))

if engine_versions is not None:
query_params["engine_versions"] = engine_versions
fpwhere.append(sql.text("engine_version IN :engine_versions"))

# Filter on anomaly, confirmed and failure:
# The database stores anomaly and confirmed as boolean + NULL and stores
# failures in different columns. This leads to many possible combinations
Expand Down
7 changes: 7 additions & 0 deletions api/ooniapi/urlparams.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,13 @@ def commasplit(p: str) -> List[str]:
return sorted(out)


def param_commasplit(name) -> Optional[List[str]]:
p = request.args.get(name)
if not p:
return None
return commasplit(p)


def param_domain_m(name="domain") -> List[str]:
p = request.args.get(name)
if not p:
Expand Down
28 changes: 28 additions & 0 deletions api/tests/integ/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -773,6 +773,34 @@ def test_list_measurements_ZZ(client):
assert resp.status_code == 403


def test_list_measurements_filter_software_version_nomatch(client):
# https://github.com/ooni/backend/issues/15
url = "measurements?since=2021-07-09&until=2021-07-10&software_version=9.9.9"
resp = api(client, url)
assert len(resp["results"]) == 0


def test_list_measurements_filter_software_version(client):
# https://github.com/ooni/backend/issues/15
url = "measurements?since=2021-07-09&until=2021-07-10&software_version=3.9.2"
resp = api(client, url)
assert len(resp["results"]) == 100


def test_list_measurements_filter_test_version(client):
# https://github.com/ooni/backend/issues/15
url = "measurements?since=2021-07-09&until=2021-07-10&test_version=0.4.0"
resp = api(client, url)
assert len(resp["results"]) == 100


def test_list_measurements_filter_engine_version(client):
# https://github.com/ooni/backend/issues/15
url = "measurements?since=2021-07-09&until=2021-07-10&engine_version=3.9.2"
resp = api(client, url)
assert len(resp["results"]) == 100


## get_measurement ##


Expand Down

0 comments on commit 3b1902c

Please sign in to comment.