diff --git a/api/debian/changelog b/api/debian/changelog index b52649db8..35e3c4a2f 100644 --- a/api/debian/changelog +++ b/api/debian/changelog @@ -1,3 +1,9 @@ +ooni-api (1.0.59) unstable; urgency=medium + + * Add update time to URL priorities + + -- Federico Ceratto Wed, 14 Jun 2023 18:20:00 +0100 + ooni-api (1.0.58) unstable; urgency=medium * Add incident management CRUD diff --git a/api/ooniapi/citizenlab.py b/api/ooniapi/citizenlab.py index 1ccaeea24..15f921e31 100644 --- a/api/ooniapi/citizenlab.py +++ b/api/ooniapi/citizenlab.py @@ -33,6 +33,7 @@ It contains rules on category_code, cc, domain and url to assign priorities. Values can be wildcards "*". A citizenlab entry can match multiple rules. """ +# The tables creation is in tests/integ/clickhouse_1_schema.sql log = logging.getLogger() # overridden by current_app.logger @@ -703,7 +704,7 @@ def list_url_priorities() -> Response: global log log = current_app.logger log.debug("listing URL prio rules") - query = """SELECT category_code, cc, domain, url, priority + query = """SELECT category_code, cc, domain, url, priority, update_time FROM url_priorities FINAL ORDER BY category_code, cc, domain, url, priority """ diff --git a/api/tests/integ/clickhouse_1_schema.sql b/api/tests/integ/clickhouse_1_schema.sql index 961f9627d..b64033085 100644 --- a/api/tests/integ/clickhouse_1_schema.sql +++ b/api/tests/integ/clickhouse_1_schema.sql @@ -59,7 +59,8 @@ CREATE TABLE default.url_priorities ( `cc` String, `domain` String, `url` String, - `priority` Int32 + `priority` Int32, + `update_time` DateTime DEFAULT now() ) ENGINE = CollapsingMergeTree(sign) ORDER BY (category_code, cc, domain, url, priority) diff --git a/api/tests/integ/test_citizenlab.py b/api/tests/integ/test_citizenlab.py index 7d598fcc9..a5bc3e118 100644 --- a/api/tests/integ/test_citizenlab.py +++ b/api/tests/integ/test_citizenlab.py @@ -360,9 +360,13 @@ def match(url): assert r.status_code == 200, r.json for x in r.json["rules"]: for k, v in x.items(): - assert v != '', f"Empty value in {x}" - match = [x for x in r.json["rules"] if x == exp] - return len(match) + assert v != "", f"Empty value in {x}" + for ru in r.json["rules"]: + ru.pop("update_time") + if ru == exp: + return True # found + + return False assert match("INTEG-TEST") == 0 assert match("INTEG-TEST2") == 0 @@ -376,7 +380,7 @@ def match(url): assert r.status_code == 400, r.json # Create - xxx = dict(category_code="NEWS", priority=100, cc='', url="INTEG-TEST") + xxx = dict(category_code="NEWS", priority=100, cc="", url="INTEG-TEST") d = dict(new_entry=xxx) r = adminsession.post("/api/_/url-priorities/update", json=d) assert r.status_code == 200, r.json