Skip to content

Commit

Permalink
Fix tests and add more tests related to filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
hellais committed Oct 11, 2024
1 parent 92ecab5 commit 1887f36
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 58 deletions.
17 changes: 10 additions & 7 deletions ooniapi/services/oonifindings/src/oonifindings/models.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from datetime import datetime
from typing import List
import sqlalchemy as sa
from sqlalchemy import String
from sqlalchemy.orm import Mapped
from sqlalchemy.orm import mapped_column
Expand Down Expand Up @@ -32,10 +33,12 @@ class OONIFinding(Base):
published: Mapped[int] = mapped_column()
deleted: Mapped[int] = mapped_column(default=0)

country_codes: Mapped[List[str]] = mapped_column(nullable=True)
asns: Mapped[List[str]] = mapped_column(nullable=True)
domains: Mapped[List[str]] = mapped_column(nullable=True)
themes: Mapped[List[str]] = mapped_column(nullable=True)
tags: Mapped[List[str]] = mapped_column(nullable=True)
links: Mapped[List[str]] = mapped_column(nullable=True)
test_names: Mapped[List[str]] = mapped_column(nullable=True)
country_codes: Mapped[List[str]] = mapped_column(
sa.ARRAY(sa.String()), nullable=True
)
asns: Mapped[List[str]] = mapped_column(sa.ARRAY(sa.INT), nullable=True)
domains: Mapped[List[str]] = mapped_column(sa.ARRAY(sa.String()), nullable=True)
themes: Mapped[List[str]] = mapped_column(sa.ARRAY(sa.String()), nullable=True)
tags: Mapped[List[str]] = mapped_column(sa.ARRAY(sa.String()), nullable=True)
links: Mapped[List[str]] = mapped_column(sa.ARRAY(sa.String()), nullable=True)
test_names: Mapped[List[str]] = mapped_column(sa.ARRAY(sa.String()), nullable=True)
15 changes: 6 additions & 9 deletions ooniapi/services/oonifindings/src/oonifindings/routers/v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,8 +319,8 @@ def validate_time(incident: OONIFinding) -> bool:

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(" ", "-"))
finding_slug = f"{ts}-{text_slug}"
text_slug = re.sub("[^0-9a-zA-Z-]+", "", title.lower().replace(" ", "-"))
finding_slug = f"{ts}-{text_slug}"[:64]
return finding_slug


Expand All @@ -345,12 +345,6 @@ def create_oonifinding(
status_code=400, detail="Invalid email address for creator account"
)

# assert create_request
if create_request.published:
raise HTTPException(
status_code=400, detail="Invalid publish parameter on create request"
)

# TODO(decfox): evaluate if we can replace this with a simple getter
account_id = get_account_id_or_raise(
authorization, jwt_encryption_key=settings.jwt_encryption_key
Expand All @@ -362,10 +356,11 @@ def create_oonifinding(
finding_slug = create_request.slug

log.info(f"Creating incident {finding_id}")
log.info(create_request)

db_oonifinding = models.OONIFinding(
finding_id=finding_id,
slug=finding_slug,
finding_slug=finding_slug,
create_time=now,
update_time=now,
start_time=create_request.start_time,
Expand All @@ -382,6 +377,7 @@ def create_oonifinding(
asns=create_request.ASNs,
domains=create_request.domains,
tags=create_request.tags,
themes=create_request.themes,
links=create_request.links,
test_names=create_request.test_names,
)
Expand Down Expand Up @@ -452,6 +448,7 @@ def update_oonifinding(
oonifinding.asns = update_request.ASNs
oonifinding.domains = update_request.domains
oonifinding.tags = update_request.tags
oonifinding.themes = update_request.themes
oonifinding.links = update_request.links
oonifinding.test_names = update_request.test_names
oonifinding.short_description = update_request.short_description
Expand Down
Loading

0 comments on commit 1887f36

Please sign in to comment.