Skip to content

Commit

Permalink
Remove dead code and reach 100% coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
hellais committed Oct 11, 2024
1 parent 1887f36 commit ab4289d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
10 changes: 0 additions & 10 deletions ooniapi/services/oonifindings/src/oonifindings/routers/v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,16 +307,6 @@ class OONIFindingsUpdateResponse(OONIFindingId):
)


def validate_time(incident: OONIFinding) -> bool:
incident.start_time = incident.start_time.replace(microsecond=0)
if incident.end_time is not None:
incident.end_time = incident.end_time.replace(microsecond=0)
delta = incident.end_time - incident.start_time
if delta.total_seconds() < 0:
raise HTTPException(status_code=400, detail="invalid query paramters")
return True


def generate_finding_slug(create_time: datetime, title: str):
ts = create_time.strftime("%Y")
text_slug = re.sub("[^0-9a-zA-Z-]+", "", title.lower().replace(" ", "-"))
Expand Down
17 changes: 17 additions & 0 deletions ooniapi/services/oonifindings/tests/test_oonifindings.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,10 @@ def test_oonifinding_delete(client, client_with_hashed_email):
incident_id = r.json()["id"]
assert incident_id

z["id"] = "not-exist"
r = client_with_admin_role.post("api/v1/incidents/delete", json=z)
assert r.status_code == 404

z["id"] = incident_id
r = client_with_admin_role.post("api/v1/incidents/delete", json=z)
assert r.status_code == 200
Expand Down Expand Up @@ -234,6 +238,11 @@ def test_oonifinding_update(client, client_with_hashed_email):
r = client_with_admin_role.get(f"api/v1/incidents/show/{incident_id}")
incident_payload = r.json()["incident"]

not_exist = deepcopy(incident_payload)
not_exist["id"] = "does-not-exist"
r = client_with_admin_role.post("api/v1/incidents/update", json=not_exist)
assert r.status_code == 404

sample_replacement_text = "sample replacement text for update"
incident_payload["text"] = sample_replacement_text
r = client_with_admin_role.post("api/v1/incidents/update", json=incident_payload)
Expand Down Expand Up @@ -438,6 +447,7 @@ def test_oonifinding_create(client, client_with_hashed_email, client_with_user_r
z["CCs"] = ["IT", "GR"]
z["domains"] = ["www.facebook.com"]
z["slug"] = "this-is-my-slug"
z["ASNs"] = [1234]
z["published"] = True

r = client_with_admin_role.post("api/v1/incidents/create", json=z)
Expand Down Expand Up @@ -484,3 +494,10 @@ def test_oonifinding_create(client, client_with_hashed_email, client_with_user_r
assert r.status_code == 200
j = r.json()
assert len(j["incidents"]) == 0

r = client.get(f"api/v1/incidents/search?asn=1234")
assert r.status_code == 200
j = r.json()
assert len(j["incidents"]) == 1

assert j["incidents"][0]["themes"] == ["social_media"]

0 comments on commit ab4289d

Please sign in to comment.