Skip to content

Add fix and test for priority calculation #958

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion api/ooniapi/prio.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def match_prio_rule(cz, pr: dict) -> bool:
if pr[k] not in ("", "*", cz[k]):
return False

if cz["cc"] != "ZZ" and pr["cc"] not in ("", "*", cz["cc"]):
if cz["cc"] != "ZZ" and pr["cc"].upper() not in ("", "*", cz["cc"].upper()):
return False

return True
Expand Down
40 changes: 40 additions & 0 deletions api/tests/unit/test_prio.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,43 @@ def test_compute_priorities():
"weight": -4.7368421052631575,
}
]


def test_compute_priorities_country_list():
entries = [
{
"category_code": "HUMR",
"domain": "ooni.org",
"url": "https://ooni.org/",
"cc": "it",
"msmt_cnt": 38,
}
]
prio_rules = [
{
"category_code": "*",
"cc": "IT",
"domain": "ooni.org",
"priority": 20,
"url": "*",
},
{
"category_code": "*",
"cc": "IT",
"domain": "ooni.org",
"priority": 400,
"url": "*",
},
]
out = prio.compute_priorities(entries, prio_rules)
assert out == [
{
"category_code": "HUMR",
"cc": "it",
"domain": "ooni.org",
"msmt_cnt": 38,
"priority": 420,
"url": "https://ooni.org/",
"weight": 11.052631578947368,
}
]
Loading