Skip to content

Commit

Permalink
Unit tests passing locally
Browse files Browse the repository at this point in the history
  • Loading branch information
wpfl-dbt committed Dec 12, 2024
1 parent 6f6332f commit 88deb28
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
13 changes: 6 additions & 7 deletions src/matchbox/server/api.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from binascii import hexlify
from enum import StrEnum
from typing import Annotated, Optional
from typing import Annotated

from dotenv import find_dotenv, load_dotenv
from fastapi import Depends, FastAPI, Form, HTTPException, UploadFile
Expand Down Expand Up @@ -52,7 +52,7 @@ class SourceItem(BaseModel):
schema: str
table: str
id: str
model: Optional[str] = None
resolution: str | None = None


class Sources(BaseModel):
Expand Down Expand Up @@ -98,13 +98,12 @@ async def list_sources(
datasets = backend.datasets.list()
result = []
for dataset in datasets:
print(dataset)
result.append(
SourceItem(
table=dataset.table,
id=dataset.id,
schema=dataset.schema,
model=hexlify(dataset.model).decode("ascii"),
resolution=hexlify(dataset.resolution).decode("ascii"),
)
)
return Sources(sources=result)
Expand All @@ -116,13 +115,13 @@ async def get_source(
) -> dict[str, SourceItem] | str:
datasets = backend.datasets.list()
for dataset in datasets:
model = hexlify(dataset.model).decode("ascii")
if model == hash:
resolution = hexlify(dataset.resolution).decode("ascii")
if resolution == hash:
result_obj = SourceItem(
table=dataset.table,
id=dataset.id,
schema=dataset.schema,
model=model,
resolution=resolution,
)
return {"source": result_obj}
return "Source not found"
Expand Down
6 changes: 3 additions & 3 deletions test/server/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def test_list_sources(self, get_backend):
hash_hex = "5eb63bbbe01eeed093cb22bb8f5acdc3"
byte_arr = bytearray.fromhex(hash_hex)
obj_mock = Sources(
table="mock table", schema="mock_schema", id="mock_id", model=byte_arr
table="mock table", schema="mock_schema", id="mock_id", resolution=byte_arr
)
mock_backend = Mock()
mock_backend.datasets.list = Mock(return_value=[obj_mock])
Expand All @@ -70,7 +70,7 @@ def test_get_source(self, get_backend):
hash_hex = "5eb63bbbe01eeed093cb22bb8f5acdc3"
byte_arr = bytearray.fromhex(hash_hex)
obj_mock = Sources(
table="mock_table", schema="mock_schema", id="mock_id", model=byte_arr
table="mock_table", schema="mock_schema", id="mock_id", resolution=byte_arr
)
mock_backend = Mock()
mock_backend.datasets.list = Mock(return_value=[obj_mock])
Expand All @@ -83,7 +83,7 @@ def test_get_source(self, get_backend):
"schema": "mock_schema",
"table": "mock_table",
"id": "mock_id",
"model": hash_hex,
"resolution": hash_hex,
}
}

Expand Down

0 comments on commit 88deb28

Please sign in to comment.