Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
79 commits
Select commit Hold shift + click to select a range
db64003
Improve type checking in oonirun
LDiazN May 16, 2025
b98c9c0
Added targets_name and inputs_extra parameters
LDiazN May 21, 2025
5bcc9ee
Moved fields to right model
LDiazN May 21, 2025
d1c610c
Add migration for targets_name and input_extra
LDiazN May 21, 2025
6083adc
Add more tests to the sample oonirun link
LDiazN May 22, 2025
018cda1
Test insert of new nettests
LDiazN May 22, 2025
4267822
Add targets_name and inputs_extra to oonirun
LDiazN May 22, 2025
f041939
Add tests to check consistency of inputs_extra
LDiazN May 22, 2025
b0c9792
Add inputs_extra validation
LDiazN May 22, 2025
0ab1cae
Fixed broken test
LDiazN May 22, 2025
69f33b4
Add TODO comment
LDiazN May 22, 2025
e39a125
Removed useless comment
LDiazN May 22, 2025
d6fce79
Add filter by revision and test
LDiazN May 23, 2025
cd9fab9
Removed unused imports
LDiazN May 23, 2025
a2613c5
Added missing arguments to engine-descriptor and tests
LDiazN May 23, 2025
e784589
Add headers for dynamic test lists calculation
LDiazN May 23, 2025
1e79ef4
Add arguments for dynamic targets list generation
LDiazN May 23, 2025
cd4e6c3
Rename postgres session dependency
LDiazN May 26, 2025
1868336
Fix typo
LDiazN May 26, 2025
9f92981
Prevent both of targets_name and inputs to be present at the same time
LDiazN May 27, 2025
bf1a695
Remove unused import
LDiazN May 27, 2025
800753d
Drop backend options parameter
LDiazN May 27, 2025
631c61a
Drop backend options parameter
LDiazN May 27, 2025
60f8775
Working on headers parsing
LDiazN May 27, 2025
402c899
Merge branch 'master' into oonirun-v2-1
LDiazN May 27, 2025
2d701fa
Add tests for header parsing; moving arguments out of headers to post
LDiazN May 28, 2025
0f50f7a
Skip user agent parsing tests for now
LDiazN May 28, 2025
5645e77
Move prio to common
LDiazN May 28, 2025
af5bbf3
Move prio to common
LDiazN May 28, 2025
4c02b03
Move prio to common
LDiazN May 28, 2025
aba48e4
Changed priority list type
LDiazN May 28, 2025
3219604
Added clickhouse to oonirun
LDiazN May 29, 2025
9d92042
Add clickhouse to clients for testing
LDiazN May 29, 2025
06e1d0e
Set up get_nettest for dynamic lists calculation
LDiazN May 29, 2025
ea6cafb
Enforce targets_name/inputs validation only on write ops
LDiazN May 29, 2025
62b7864
Rename function to dynamically compute test lists
LDiazN May 29, 2025
0c9ddf6
Add dynamic test lists calculation to engine-descriptor endpoint
LDiazN May 29, 2025
32d524b
Improve validation of inputs_extra field
LDiazN May 29, 2025
8e4279f
Add todo
LDiazN May 29, 2025
80db37a
Fix bad creation of oonirun links with targets_name
LDiazN May 29, 2025
2705195
Fix bug assigning None to targets_name when not needed
LDiazN May 29, 2025
f2ebdc1
Add header parsing for engine-descriptor endpoint
LDiazN May 30, 2025
09515db
Fix broken test
LDiazN May 30, 2025
ec9f7b3
Fix broken test
LDiazN May 30, 2025
22a4eb8
Add integration test for dynamic lists calculation
LDiazN May 30, 2025
d0062c2
Remove useless prints
LDiazN May 30, 2025
673c907
Fix broken tests
LDiazN May 30, 2025
1a1f203
Remove print
LDiazN May 30, 2025
083e286
Add test for filtering with category codes
LDiazN Jun 2, 2025
b9ec631
Add setup for creating measurements for testing url priorization
LDiazN Jun 2, 2025
ec10d06
Add test for prioritization with measurements
LDiazN Jun 3, 2025
e2b2280
Add url basic url priorities tests
LDiazN Jun 3, 2025
8769092
Remove useless print
LDiazN Jun 3, 2025
b507c99
Simplify header format
LDiazN Jun 3, 2025
248a89b
Simplify get_nettests function
LDiazN Jun 3, 2025
f389bd6
Revert "Simplify get_nettests function"
LDiazN Jun 3, 2025
b5f4308
black reformat
LDiazN Jun 4, 2025
279c0b6
fix bad ooni domain
LDiazN Jun 4, 2025
5f41fca
Move fixtures to conftest; root fixtures dir to THIS_DIR
LDiazN Jun 4, 2025
e25e053
Add network type validation and some tests
LDiazN Jun 4, 2025
f3a9147
Improve ASN validation
LDiazN Jun 4, 2025
54f8f0f
rename header for anonymous credentials
LDiazN Jun 4, 2025
c823315
Remove only_latest parameter
LDiazN Jun 4, 2025
a3f1a8d
Simplify user agent header parsing
LDiazN Jun 4, 2025
70240f3
Changed default value of inputs field
LDiazN Jun 4, 2025
59f47dd
Add flag to compute dynamic lists in get_nettest function
LDiazN Jun 4, 2025
f53a30a
Remove backend_options and options, even from the DB
LDiazN Jun 4, 2025
0d28ee7
Split dynamic test list calculation from nettest db fetch
LDiazN Jun 4, 2025
eeb9743
drop backend_options and options column
LDiazN Jun 5, 2025
3d09989
Add backend_options and options on downgrade
LDiazN Jun 5, 2025
a7bf78f
Restor options field in nettest
LDiazN Jun 10, 2025
6868ab9
trigger CI
LDiazN Jun 10, 2025
48e60d9
Add bluetooth and usb as valid network types
LDiazN Jun 18, 2025
34f0c3e
Fix conflicts oonirun v2 1 (#1056)
aagbsn Jan 22, 2026
e2281f8
merge conflict
LDiazN Jan 22, 2026
819eff9
refactor tests
LDiazN Jan 22, 2026
0ab5f3e
refactor tests
LDiazN Jan 22, 2026
b5db96f
Remove merge conflict
LDiazN Jan 22, 2026
884306b
trigger ci
LDiazN Jan 29, 2026
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
Prev Previous commit
Next Next commit
Move fixtures to conftest; root fixtures dir to THIS_DIR
  • Loading branch information
LDiazN committed Jun 4, 2025
commit 5f41fca5a466752c720fc8644b07a3e15afe51bb
74 changes: 74 additions & 0 deletions ooniapi/services/oonirun/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
import pathlib
from pathlib import Path
import pytest
import json
import random
from datetime import datetime, timedelta, UTC

import time
import jwt

from fastapi.testclient import TestClient

from oonirun.common.config import Settings
from oonirun.common.clickhouse_utils import insert_click
from oonirun.common.dependencies import get_settings
from oonirun.main import app
from clickhouse_driver import Client as ClickhouseClient

THIS_DIR = Path(__file__).parent.resolve()


def make_override_get_settings(**kw):
def override_get_settings():
Expand Down Expand Up @@ -120,3 +127,70 @@ def clickhouse_server(docker_ip, docker_services):
@pytest.fixture(scope="session")
def clickhouse_db(clickhouse_server):
yield ClickhouseClient.from_url(clickhouse_server)


@pytest.fixture(scope="module")
def fixtures_data_dir():
yield Path(THIS_DIR, "fixtures/data")


@pytest.fixture(scope="module")
def url_priorities(clickhouse_db, fixtures_data_dir):
filename = "url_priorities_us.json"
file = Path(fixtures_data_dir, filename)

with file.open("r") as f:
j = json.load(f)

# 'sign' is created with default value 0, causing a db error.
# use 1 to prevent it
for row in j:
row["sign"] = 1

query = "INSERT INTO url_priorities (sign, category_code, cc, domain, url, priority) VALUES"
insert_click(clickhouse_db, query, j)
yield
clickhouse_db.execute("TRUNCATE TABLE url_priorities")


def generate_random_date_last_7_days() -> datetime:
start = datetime.now(tz=UTC) - timedelta(days=7)

# return a random date between 7 days ago and now
return start + timedelta(
seconds=random.randrange(3600 * 24, 3600 * 24 * 7 - 3600 * 24)
)


@pytest.fixture(scope="module")
def measurements(clickhouse_db, fixtures_data_dir):
msmnts_dir = Path(fixtures_data_dir, "measurements.json")
with open(msmnts_dir, "r") as f:
measurements = json.load(f)

for ms in measurements:
date = generate_random_date_last_7_days()
ms["measurement_start_time"] = date
ms["test_start_time"] = date

query = "INSERT INTO fastpath VALUES"
insert_click(clickhouse_db, query, measurements)

yield
clickhouse_db.execute("TRUNCATE TABLE url_priorities")


@pytest.fixture
def super_prioritized_website(clickhouse_db):
values = {
"category_code": "*",
"cc": "*",
"domain": "ooni.org",
"priority": 99999,
"url": "*",
"sign": 1,
}
query = "INSERT INTO url_priorities (sign, category_code, cc, domain, url, priority) VALUES"
insert_click(clickhouse_db, query, [values])
yield
clickhouse_db.execute("DELETE FROM url_priorities WHERE domain='ooni.org'")
71 changes: 0 additions & 71 deletions ooniapi/services/oonirun/tests/integ/test_dynamic_lists.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
from copy import deepcopy
import json
from pathlib import Path
from oonirun.common.clickhouse_utils import insert_click
import pytest
from ..test_oonirun import SAMPLE_OONIRUN, SAMPLE_META
from datetime import datetime, timedelta, UTC
import random


def postj(client, url, **kw):
Expand All @@ -14,57 +10,6 @@ def postj(client, url, **kw):
return response.json()


@pytest.fixture(scope="module")
def fixtures_data_dir():
yield Path("tests/fixtures/data")


@pytest.fixture(scope="module")
def url_priorities(clickhouse_db, fixtures_data_dir):
filename = "url_priorities_us.json"
file = Path(fixtures_data_dir, filename)

with file.open("r") as f:
j = json.load(f)

# 'sign' is created with default value 0, causing a db error.
# use 1 to prevent it
for row in j:
row["sign"] = 1

query = "INSERT INTO url_priorities (sign, category_code, cc, domain, url, priority) VALUES"
insert_click(clickhouse_db, query, j)
yield
clickhouse_db.execute("TRUNCATE TABLE url_priorities")


def generate_random_date_last_7_days() -> datetime:
start = datetime.now(tz=UTC) - timedelta(days=7)

# return a random date between 7 days ago and now
return start + timedelta(
seconds=random.randrange(3600 * 24, 3600 * 24 * 7 - 3600 * 24)
)


@pytest.fixture(scope="module")
def measurements(clickhouse_db, fixtures_data_dir):
msmnts_dir = Path(fixtures_data_dir, "measurements.json")
with open(msmnts_dir, "r") as f:
measurements = json.load(f)

for ms in measurements:
date = generate_random_date_last_7_days()
ms["measurement_start_time"] = date
ms["test_start_time"] = date

query = "INSERT INTO fastpath VALUES"
insert_click(clickhouse_db, query, measurements)

yield
clickhouse_db.execute("TRUNCATE TABLE url_priorities")


def test_engine_descriptor_basic(client, client_with_user_role, url_priorities):
z = deepcopy(SAMPLE_OONIRUN)
z["name"] = "Testing simple prioritizationpri"
Expand Down Expand Up @@ -160,22 +105,6 @@ def test_prioritization_with_measurements(
assert "facebook.com" in inputs[-1], "Facebook should be the last one"


@pytest.fixture
def super_prioritized_website(clickhouse_db):
values = {
"category_code": "*",
"cc": "*",
"domain": "ooni.org",
"priority": 99999,
"url": "*",
"sign": 1,
}
query = "INSERT INTO url_priorities (sign, category_code, cc, domain, url, priority) VALUES"
insert_click(clickhouse_db, query, [values])
yield
clickhouse_db.execute("DELETE FROM url_priorities WHERE domain='ooni.org'")


def test_priorities_basic(
client,
client_with_user_role,
Expand Down
3 changes: 0 additions & 3 deletions ooniapi/services/oonirun/tests/test_oonirun.py
Original file line number Diff line number Diff line change
Expand Up @@ -836,10 +836,7 @@ def test_dynamic_test_lists_calculation(client_with_user_role):
j = r.json()
assert j["nettests"][0]["targets_name"] == "websites_list_prioritized"

# TODO(luis) Finish this test


# TODO(luis) finish this test for checking the parsing of user agent headers
def test_x_user_agent_header_parsing(client_with_user_role, client):
z = deepcopy(SAMPLE_OONIRUN)
z["name"] = "Testing header parsing"
Expand Down