Skip to content

Commit

Permalink
Revert changes to semantics of nettest struct
Browse files Browse the repository at this point in the history
  • Loading branch information
hellais committed Mar 11, 2024
1 parent b03ec6b commit 72150ce
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@
),
sa.Column("date_created", sa.DateTime(), nullable=True),
sa.Column("test_name", sa.String(), nullable=True),
sa.Column("test_inputs", sa.JSON(), nullable=True),
sa.Column("test_options", sa.JSON(), nullable=True),
sa.Column("backend_config", sa.JSON(), nullable=True),
sa.Column("inputs", sa.JSON(), nullable=True),
sa.Column("options", sa.JSON(), nullable=True),
sa.Column("backend_options", sa.JSON(), nullable=True),
sa.Column(
"is_background_run_enabled_default",
sa.Boolean(),
Expand Down Expand Up @@ -67,9 +67,9 @@ def upgrade() -> None:
),
sa.Column("date_created", sa.DateTime(), nullable=True),
sa.Column("test_name", sa.String(), nullable=True),
sa.Column("test_inputs", sa.JSON(), nullable=True),
sa.Column("test_options", sa.JSON(), nullable=True),
sa.Column("backend_config", sa.JSON(), nullable=True),
sa.Column("inputs", sa.JSON(), nullable=True),
sa.Column("options", sa.JSON(), nullable=True),
sa.Column("backend_options", sa.JSON(), nullable=True),
sa.Column(
"is_background_run_enabled_default",
sa.Boolean(),
Expand Down Expand Up @@ -99,17 +99,15 @@ def upgrade() -> None:
for record in oonirun_rows:
nettests_data = record.nettests
for index, nettest in enumerate(nettests_data):
inputs = nettest.get("inputs", [])
test_inputs = list(map(lambda x: {"url": x}, inputs))
nettest = dict(
oonirun_link_id=record.oonirun_link_id,
revision=record.revision,
nettest_index=index,
date_created=record.date_created,
test_name=nettest["test_name"],
test_inputs=test_inputs,
test_options=nettest.get("options", {}),
backend_config=nettest.get("backend_options", {}),
inputs=nettest.get("inputs", []),
options=nettest.get("options", {}),
backend_options=nettest.get("backend_options", {}),
is_background_run_enabled_default=nettest.get(
"is_background_run_enabled", False
),
Expand Down
6 changes: 3 additions & 3 deletions api/fastapi/oonidataapi/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ class OONIRunLinkNettest(Base):
date_created: Mapped[datetime] = mapped_column()

test_name: Mapped[str] = mapped_column()
test_inputs: Mapped[List[str]] = mapped_column(nullable=True)
test_options: Mapped[Dict[str, Any]] = mapped_column(nullable=True)
backend_config: Mapped[Dict[str, Any]] = mapped_column(nullable=True)
inputs: Mapped[List[str]] = mapped_column(nullable=True)
options: Mapped[Dict[str, Any]] = mapped_column(nullable=True)
backend_options: Mapped[Dict[str, Any]] = mapped_column(nullable=True)

is_background_run_enabled_default: Mapped[bool] = mapped_column(default=False)
is_manual_run_enabled_default: Mapped[bool] = mapped_column(default=False)
30 changes: 15 additions & 15 deletions api/fastapi/oonidataapi/routers/oonirun.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ class OONIRunLinkNettest(BaseModel):
test_name: str = Field(
default="", title="name of the ooni nettest", min_length=2, max_length=100
)
test_inputs: List[str] = Field(
inputs: List[str] = Field(
default=[], title="list of input dictionaries for the nettest"
)
test_options: Dict = Field(default={}, title="options for the nettest")
backend_config: Dict = Field(default={}, title="options for the nettest")
options: Dict = Field(default={}, title="options for the nettest")
backend_options: Dict = Field(default={}, title="options to send to the backend")
is_background_run_enabled_default: bool = Field(
default=False,
title="if this test should be enabled by default for background runs",
Expand Down Expand Up @@ -227,9 +227,9 @@ def create_oonirun_link(
for nettest_index, nt in enumerate(create_request.nettests):
nettest = OONIRunLinkNettest(
test_name=nt.test_name,
test_inputs=nt.test_inputs,
test_options=nt.test_options,
backend_config=nt.backend_config,
inputs=nt.inputs,
options=nt.options,
backend_options=nt.backend_options,
is_background_run_enabled_default=nt.is_background_run_enabled_default,
is_manual_run_enabled_default=nt.is_manual_run_enabled_default,
)
Expand Down Expand Up @@ -305,9 +305,9 @@ def edit_oonirun_link(
latest_nettests.append(
OONIRunLinkNettest(
test_name=nt.test_name,
test_inputs=nt.test_inputs,
test_options=nt.test_options,
backend_config=nt.backend_config,
inputs=nt.inputs,
options=nt.options,
backend_options=nt.backend_options,
is_background_run_enabled_default=nt.is_background_run_enabled_default,
is_manual_run_enabled_default=nt.is_manual_run_enabled_default,
)
Expand All @@ -321,9 +321,9 @@ def edit_oonirun_link(
nettest_index=nettest_index,
date_created=now,
test_name=nt.test_name,
test_inputs=nt.test_inputs,
test_options=nt.test_options,
backend_config=nt.backend_config,
inputs=nt.inputs,
options=nt.options,
backend_options=nt.backend_options,
is_background_run_enabled_default=nt.is_background_run_enabled_default,
is_manual_run_enabled_default=nt.is_manual_run_enabled_default,
oonirun_link=oonirun_link,
Expand Down Expand Up @@ -376,9 +376,9 @@ def get_nettests(
nettests.append(
OONIRunLinkNettest(
test_name=nt.test_name,
test_inputs=nt.test_inputs,
test_options=nt.test_options,
backend_config=nt.backend_config,
inputs=nt.inputs,
options=nt.options,
backend_options=nt.backend_options,
is_background_run_enabled_default=nt.is_background_run_enabled_default,
is_manual_run_enabled_default=nt.is_manual_run_enabled_default,
)
Expand Down
22 changes: 11 additions & 11 deletions api/fastapi/oonidataapi/tests/test_oonirun.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,22 @@
"author": "integ-test author",
"nettests": [
{
"test_inputs": [
"inputs": [
"https://example.com/",
"https://ooni.org/",
],
"test_options": {
"options": {
"HTTP3Enabled": True,
},
"backend_config": {},
"backend_options": {},
"is_background_run_enabled_default": False,
"is_manual_run_enabled_default": False,
"test_name": "web_connectivity",
},
{
"test_inputs": [],
"test_options": {},
"backend_config": {},
"inputs": [],
"options": {},
"backend_options": {},
"is_background_run_enabled_default": False,
"is_manual_run_enabled_default": False,
"test_name": "dnscheck",
Expand Down Expand Up @@ -297,7 +297,7 @@ def test_oonirun_full_workflow(client, client_with_user_role, client_with_admin_
assert found == True

### "update" the oonirun by creating a new version, changing the inputs
z["nettests"][0]["test_inputs"].append("https://foo.net/")
z["nettests"][0]["inputs"].append("https://foo.net/")
r = client_with_user_role.put(f"/api/v2/oonirun-links/{oonirun_link_id}", json=z)
assert r.status_code == 200, r.json()
assert r.json()["oonirun_link_id"] == oonirun_link_id
Expand Down Expand Up @@ -424,7 +424,7 @@ def test_oonirun_expiration(client, client_with_user_role):
assert j["is_expired"] == False, r.json()

## Create new revision
j["nettests"][0]["test_inputs"].append("https://foo.net/")
j["nettests"][0]["inputs"].append("https://foo.net/")
r = client_with_user_role.put(f"/api/v2/oonirun-links/{oonirun_link_id}", json=j)
assert r.status_code == 200, r.json()

Expand Down Expand Up @@ -473,7 +473,7 @@ def test_oonirun_revisions(client, client_with_user_role):
oonirun_link_id_one = j["oonirun_link_id"]

## Create two new revisions
j["nettests"][0]["test_inputs"].append("https://foo.net/")
j["nettests"][0]["inputs"].append("https://foo.net/")
r = client_with_user_role.put(
f"/api/v2/oonirun-links/{oonirun_link_id_one}", json=j
)
Expand All @@ -482,7 +482,7 @@ def test_oonirun_revisions(client, client_with_user_role):
first_date_created = j["date_created"]

time.sleep(1)
j["nettests"][0]["test_inputs"].append("https://foo2.net/")
j["nettests"][0]["inputs"].append("https://foo2.net/")
r = client_with_user_role.put(
f"/api/v2/oonirun-links/{oonirun_link_id_one}", json=j
)
Expand Down Expand Up @@ -510,7 +510,7 @@ def test_oonirun_revisions(client, client_with_user_role):
oonirun_link_id_two = j["oonirun_link_id"]

## Create new revision
j["nettests"][0]["test_inputs"].append("https://foo.net/")
j["nettests"][0]["inputs"].append("https://foo.net/")
r = client_with_user_role.put(
f"/api/v2/oonirun-links/{oonirun_link_id_two}", json=j
)
Expand Down

0 comments on commit 72150ce

Please sign in to comment.