Skip to content

Commit

Permalink
feat: A/B test oonifindings with new and legacy deployments
Browse files Browse the repository at this point in the history
  • Loading branch information
DecFox committed Aug 14, 2024
1 parent ab26179 commit 53a25cf
Showing 1 changed file with 30 additions and 12 deletions.
42 changes: 30 additions & 12 deletions testshift/tests/test_oonifindings.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,49 @@

import httpx

LEGACY_HOST = "https://backend-hel.ooni.org"
LEGACY_HOST = "https://api.ooni.io"
ACTIVE_HOST = "https://api.dev.ooni.io"


def check_response_keys(legacy_response: Dict, active_response: Dict):
return legacy_response.keys() == active_response.keys()
# NOTE: The new API has been updated to include one new response
# field which we do not use and hence default to an empty value.
#
# `creator_account_id`: ""
def check_search_response_keys(legacy_response: Dict, active_response: Dict):
legacy_keys = list(legacy_response.keys())
active_keys = list(active_response.keys())

assert len(active_keys) == len(legacy_keys) + 1

active_keys.remove("creator_account_id")
return sorted(active_keys) == sorted(legacy_keys)


def test_oonifindings():
with httpx.Client(base_url=LEGACY_HOST) as legacy_client, httpx.Client(base_url=ACTIVE_HOST) as active_client:
legacy_response = legacy_client.get("api/v1/incidents/search?only_mine=false")
active_response = active_client.get("api/v1/incidents/search?only_mine=false")
legacy_incidents, active_incidents = legacy_response.json(), active_response.json()
legacy_incidents, active_incidents = legacy_response.json()["incidents"], active_response.json()["incidents"]

assert len(legacy_incidents) == len(active_incidents)

for idx in range(len(legacy_incidents)):
assert check_response_keys(legacy_incidents[idx], active_incidents[idx])
assert check_search_response_keys(legacy_incidents[idx], active_incidents[idx])

legacy_response = legacy_client.get("api/v1/incidents/search?only_mine=true")
active_response = active_client.get("api/v1/incidents/search?only_mine=true")
legacy_incidents, active_incidents = legacy_response.json(), active_response.json()
legacy_incidents, active_incidents = legacy_response.json()["incidents"], active_response.json()["incidents"]

assert len(legacy_incidents) == len(active_incidents)

for idx in range(len(legacy_incidents)):
assert check_response_keys(legacy_incidents[idx], active_incidents[idx])

sample_incident = ""
legacy_response = legacy_client.get(f"api/v1/incidents/show/{sample_incident}")
active_response = legacy_client.get(f"api/v1/incidents/show/{sample_incident}")
assert check_response_keys(legacy_response.json(), active_response.json())
assert check_search_response_keys(legacy_incidents[idx], active_incidents[idx])

incident_id = "330022197701"
legacy_response = legacy_client.get(f"api/v1/incidents/show/{incident_id}")
active_response = active_client.get(f"api/v1/incidents/show/{incident_id}")

legacy_incident = legacy_response.json()["incident"]
active_incident = active_response.json()["incident"]

assert check_search_response_keys(legacy_incident, active_incident)

0 comments on commit 53a25cf

Please sign in to comment.