Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion db/sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class Sample(Base, AutoBaseMixin, ReleaseMixin):
)
sensor_id: Mapped[Optional[int]] = mapped_column(
ForeignKey("sensor.id"),
unique=True,
# unique=True,
comment="Foreign key for the specific equipment used.",
)

Expand Down
12 changes: 4 additions & 8 deletions schemas_v2/asset.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@ class BaseAsset(BaseModel):
storage_path: str
mime_type: str
size: int
url: str
thing_id: int | None = None


# -------- CREATE ----------
class CreateAsset(BaseAsset):
url: str
pass


# -------- RESPONSE --------
Expand All @@ -40,19 +42,13 @@ class AssetResponse(BaseAsset):
# storage_path: str
# mime_type: str
# size: int
url: str
created_at: datetime
storage_service: str


# -------- UPDATE ----------
class UpdateAsset(BaseAsset):
label: str | None = None
url: str | None = None
name: str | None = None
storage_path: str | None = None
mime_type: str | None = None
size: int | None = None
pass


# ============= EOF =============================================
13 changes: 12 additions & 1 deletion schemas_v2/sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,18 @@ class CreateGeothermalSample(BaseModel):
class SampleResponse(BaseModel):
id: int
sample_date: datetime
sample_method: str
sample_method: str | None = None
sample_type: str
field_sample_id: str
sample_matrix: str | None = None
sampler_name: str | None = None
qc_sample: str | None = None
duplicate_sample_number: int | None = None
sample_top: float | None = None
sample_bottom: float | None = None
sensor_id: int | None = None
release_status: str
created_at: datetime
thing_id: int


Expand Down
55 changes: 24 additions & 31 deletions tests/test_sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def test_patch_sample(sample):
original_timestamp_patch = sample.sample_date

sample_method_patch = "continuous"
sample_date_patch = "2025-01-02T00:00:00+00:00"
sample_date_patch = "2025-01-02T00:00:00Z"
response = client.patch(
f"/sample/{sample.id}",
json={
Expand All @@ -103,12 +103,9 @@ def test_patch_sample(sample):
)
assert response.status_code == 200
data = response.json()
assert data == {
"id": sample.id,
"sample_date": sample_date_patch.split("+")[0],
"sample_method": sample_method_patch,
"thing_id": sample.thing_id,
}
assert data["id"] == sample.id
assert data["sample_date"] == sample_date_patch[:-1]
assert data["sample_method"] == sample_method_patch

# cleanup after patching the sample
with session_ctx() as session:
Expand Down Expand Up @@ -147,23 +144,23 @@ def test_patch_sample_422_thing_id_not_found(sample):
)
assert response.status_code == 422
data = response.json()
assert data["detail"] == [
{
"type": "value_error",
"loc": ["body", "thing_id"],
"msg": f"Value error, Thing with ID {bad_thing_id} does not exist.",
"input": bad_thing_id,
"ctx": {"error": {}},
}
]

assert "detail" in data
assert isinstance(data["detail"], list)
assert len(data["detail"]) == 1
assert data["detail"][0]["type"] == "value_error"
assert data["detail"][0]["loc"] == ["body", "thing_id"]
assert (
data["detail"][0]["msg"]
== f"Value error, Thing with ID {bad_thing_id} does not exist."
)


def test_patch_sample_422_invalid_timestamp(sample):
"""
Test updating a sample with an invalid collection timestamp.
"""
bad_sample_date = "3500-01-01T00:00:00Z"
bad_sample_date_dt = datetime.fromisoformat(bad_sample_date.replace("Z", "+00:00"))
response = client.patch(
f"/sample/{sample.id}",
json={
Expand All @@ -188,14 +185,12 @@ def test_get_samples(sample):
response = client.get("/sample")
assert response.status_code == 200
data = response.json()
assert data["items"] == [
{
"id": sample.id,
"sample_date": sample.sample_date,
"sample_method": sample.sample_method,
"thing_id": sample.thing_id,
}
]
assert "items" in data
assert len(data["items"]) == 1
assert data["items"][0]["id"] == sample.id
assert data["items"][0]["sample_date"] == sample.sample_date
assert data["items"][0]["sample_method"] == sample.sample_method
assert data["items"][0]["thing_id"] == sample.thing_id


@pytest.mark.skip(reason="Geochemical samples endpoint not implemented yet")
Expand Down Expand Up @@ -229,12 +224,10 @@ def test_get_sample_by_id(sample):
response = client.get(f"/sample/{sample.id}")
assert response.status_code == 200
data = response.json()
assert data == {
"id": sample.id,
"sample_date": sample.sample_date,
"sample_method": sample.sample_method,
"thing_id": sample.thing_id,
}
assert data["id"] == sample.id
assert data["sample_date"] == sample.sample_date
assert data["sample_method"] == sample.sample_method
assert data["thing_id"] == sample.thing_id


def test_get_sample_by_id_404_not_found(sample):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def test_search_api(thing, sample):
data = response.json()

assert isinstance(data, list)
assert len(data) == 2
assert len(data) == 3


@pytest.mark.skip(reason="This test is not working .")
Expand Down