Skip to content

Commit ab5f07f

Browse files
committed
all fieldsite and object tests pass
1 parent 7503e14 commit ab5f07f

File tree

5 files changed

+313
-183
lines changed

5 files changed

+313
-183
lines changed

services/api-v3/Makefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,10 @@ test-fieldsite:
2424
--confcutdir=api/tests \
2525
api/tests/test_fieldsite.py
2626

27+
test-object:
28+
uv run pytest -q \
29+
--confcutdir=api/tests \
30+
api/tests/test_object.py
31+
32+
2733

services/api-v3/api/settings.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from pydantic import Field
22
from pydantic_settings import BaseSettings, SettingsConfigDict
3+
from typing import Optional
34

45
class Settings(BaseSettings):
56
model_config = SettingsConfigDict(
@@ -21,4 +22,5 @@ class Settings(BaseSettings):
2122
jwt_secret_key: str = Field(alias="SECRET_KEY")
2223
jwt_algorithm: str = Field(default="HS256", alias="JWT_ENCRYPTION_ALGORITHM")
2324

25+
2426
settings = Settings()

services/api-v3/api/tests/test_database.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,17 @@ class TEST_SOURCE_TABLE:
3030
to_filter = {"PTYPE": "eq.Qff"}
3131

3232

33-
@pytest.fixture
33+
@pytest.fixture(scope="module")
3434
def api_client() -> TestClient:
35-
with TestClient(app) as api_client:
36-
yield api_client
35+
headers = {}
36+
test_token = os.environ.get("TEST_ACCESS_TOKEN")
37+
if test_token:
38+
headers["access_token"] = f"Bearer {test_token}"
39+
40+
with TestClient(app, headers=headers) as client:
41+
yield client
42+
43+
3744

3845

3946
@pytest.fixture

services/api-v3/api/tests/test_fieldsite.py

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -189,38 +189,40 @@ def test_spot_to_checkin_from_featurecollection(self, api_client):
189189
assert resp.status_code == 200
190190

191191
out = resp.json()
192-
assert isinstance(out, list)
193-
assert len(out) == 1
192+
assert isinstance(out, dict)
194193

195-
c = out[0]
196-
# Rockd checkin-ish keys
194+
c = out
197195
assert c["checkin_id"] == 10
198196
assert c["spot_id"] == 10
199197
assert c["lat"] == pytest.approx(43.0)
200198
assert c["lng"] == pytest.approx(-89.0)
199+
201200
assert "created" in c and isinstance(c["created"], str)
202-
assert "added" in c and isinstance(c["added"], str)
203-
assert "observations" in c and isinstance(c["observations"], list)
201+
assert "updated" in c and isinstance(c["updated"], str)
202+
assert c["created"].endswith("Z")
203+
assert c["updated"].endswith("Z")
204204

205-
# orientation passed through
205+
assert "observations" in c and isinstance(c["observations"], list)
206206
assert len(c["observations"]) == 1
207207
assert "orientation" in c["observations"][0]
208208
assert c["observations"][0]["orientation"]["strike"] == pytest.approx(123.0)
209209
assert c["observations"][0]["orientation"]["dip"] == pytest.approx(45.0)
210210

211+
211212
def test_spot_to_checkin_accepts_single_fieldsite_dict(self, api_client):
212213
# your spot_to_checkin treats dict with "location" as already-FieldSite-shaped
213214
payload = _fieldsite_dict(fs_id=501)
214215
resp = api_client.post(
215216
"/dev/convert/field-site?in=spot&out=checkin", json=payload
216217
)
217218
assert resp.status_code == 200
218-
219219
out = resp.json()
220-
assert isinstance(out, list)
221-
assert len(out) == 1
222-
assert out[0]["checkin_id"] == 501
223-
assert out[0]["spot_id"] == 501
220+
assert isinstance(out, dict)
221+
assert out["checkin_id"] == 501
222+
assert out["spot_id"] == 501
223+
assert "created" in out and isinstance(out["created"], str)
224+
assert "updated" in out and isinstance(out["updated"], str)
225+
224226

225227
def test_checkin_to_fieldsite_single(self, api_client):
226228
payload = _checkin(checkin_id=77)
@@ -262,29 +264,29 @@ def test_fieldsite_to_checkin_list(self, api_client):
262264
"/dev/convert/field-site?in=fieldsite&out=checkin", json=payload
263265
)
264266
assert resp.status_code == 200
265-
266267
out = resp.json()
267268
assert isinstance(out, list)
268269
assert len(out) == 2
269-
270270
c0 = out[0]
271271
assert c0["checkin_id"] == 900
272272
assert c0["spot_id"] == 900
273273
assert "created" in c0 and isinstance(c0["created"], str)
274-
assert "added" in c0 and isinstance(c0["added"], str)
274+
assert "updated" in c0 and isinstance(c0["updated"], str)
275+
275276

276277
def test_fieldsite_to_checkin_single_returns_list_of_one(self, api_client):
277278
payload = _fieldsite_dict(fs_id=999)
278279
resp = api_client.post(
279280
"/dev/convert/field-site?in=fieldsite&out=checkin", json=payload
280281
)
281282
assert resp.status_code == 200
282-
283283
out = resp.json()
284-
assert isinstance(out, list)
285-
assert len(out) == 1
286-
assert out[0]["checkin_id"] == 999
287-
assert out[0]["spot_id"] == 999
284+
assert isinstance(out, dict)
285+
assert out["checkin_id"] == 999
286+
assert out["spot_id"] == 999
287+
assert "created" in out and isinstance(out["created"], str)
288+
assert "updated" in out and isinstance(out["updated"], str)
289+
288290

289291
def test_fieldsite_to_spot_single(self, api_client):
290292
payload = _fieldsite_dict(fs_id=1234)

0 commit comments

Comments
 (0)