From 88deb280ea3d152295f233794de3449f60499368 Mon Sep 17 00:00:00 2001 From: Will Langdale Date: Thu, 12 Dec 2024 15:52:33 +0000 Subject: [PATCH] Unit tests passing locally --- src/matchbox/server/api.py | 13 ++++++------- test/server/test_api.py | 6 +++--- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/matchbox/server/api.py b/src/matchbox/server/api.py index b297348..5ef7d57 100644 --- a/src/matchbox/server/api.py +++ b/src/matchbox/server/api.py @@ -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 @@ -52,7 +52,7 @@ class SourceItem(BaseModel): schema: str table: str id: str - model: Optional[str] = None + resolution: str | None = None class Sources(BaseModel): @@ -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) @@ -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" diff --git a/test/server/test_api.py b/test/server/test_api.py index 7d34d61..3d25aa4 100644 --- a/test/server/test_api.py +++ b/test/server/test_api.py @@ -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]) @@ -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]) @@ -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, } }