Skip to content

Commit 111aef4

Browse files
committed
refactor: rename active_location to current_location
1 parent a900dd6 commit 111aef4

3 files changed

Lines changed: 14 additions & 14 deletions

File tree

db/thing.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -239,18 +239,18 @@ class Thing(Base, AutoBaseMixin, ReleaseMixin, StatusHistoryMixin, PermissionMix
239239
)
240240

241241
@property
242-
def active_location(self):
242+
def current_location(self):
243243
"""
244244
Returns the currently active Location by sorting the effective_start
245245
field. Thing eagerly loads location_association, which eagerly loads
246246
location, which will hopefully prevent N+1 query problems.
247247
"""
248-
active_location = sorted(
248+
current_location = sorted(
249249
self.location_associations, key=lambda x: x.effective_start, reverse=True
250250
)
251251
return (
252-
active_location[0].location
253-
if active_location and active_location[0].effective_end is None
252+
current_location[0].location
253+
if current_location and current_location[0].effective_end is None
254254
else None
255255
)
256256

schemas/thing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ def check_depths(self):
139139
class BaseThingResponse(BaseResponseModel):
140140
name: str
141141
thing_type: str
142-
active_location: LocationResponse | None
142+
current_location: LocationResponse | None
143143
first_visit_date: PastDate | None
144144

145145

tests/test_thing.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ def test_add_water_well(location, group):
122122
expected_location["created_at"] = (
123123
expected_location["created_at"].isoformat().replace("+00:00", "Z")
124124
)
125-
assert data["active_location"] == expected_location
125+
assert data["current_location"] == expected_location
126126

127127
cleanup_post_test(Thing, data["id"])
128128

@@ -199,7 +199,7 @@ def test_add_spring(location, group):
199199
expected_location["created_at"] = (
200200
expected_location["created_at"].isoformat().replace("+00:00", "Z")
201201
)
202-
assert data["active_location"] == expected_location
202+
assert data["current_location"] == expected_location
203203

204204
cleanup_post_test(Thing, data["id"])
205205

@@ -408,7 +408,7 @@ def test_get_water_wells(water_well_thing, location):
408408
expected_location["created_at"] = (
409409
expected_location["created_at"].isoformat().replace("+00:00", "Z")
410410
)
411-
assert data["items"][0]["active_location"] == expected_location
411+
assert data["items"][0]["current_location"] == expected_location
412412

413413

414414
def test_get_water_well_by_id(water_well_thing, location):
@@ -439,7 +439,7 @@ def test_get_water_well_by_id(water_well_thing, location):
439439
expected_location["created_at"] = (
440440
expected_location["created_at"].isoformat().replace("+00:00", "Z")
441441
)
442-
assert data["active_location"] == expected_location
442+
assert data["current_location"] == expected_location
443443

444444

445445
def test_get_water_well_by_id_404_not_found(water_well_thing):
@@ -485,7 +485,7 @@ def test_get_springs(spring_thing, location):
485485
expected_location["created_at"] = (
486486
expected_location["created_at"].isoformat().replace("+00:00", "Z")
487487
)
488-
assert data["items"][0]["active_location"] == expected_location
488+
assert data["items"][0]["current_location"] == expected_location
489489

490490

491491
def test_get_spring_by_id(spring_thing, location):
@@ -505,7 +505,7 @@ def test_get_spring_by_id(spring_thing, location):
505505
expected_location["created_at"] = (
506506
expected_location["created_at"].isoformat().replace("+00:00", "Z")
507507
)
508-
assert data["active_location"] == expected_location
508+
assert data["current_location"] == expected_location
509509

510510

511511
def test_get_spring_by_id_404_not_found(spring_thing):
@@ -710,7 +710,7 @@ def test_get_thing_by_id(water_well_thing, location):
710710
expected_location["created_at"] = (
711711
expected_location["created_at"].isoformat().replace("+00:00", "Z")
712712
)
713-
assert data["active_location"] == expected_location
713+
assert data["current_location"] == expected_location
714714

715715

716716
def test_get_thing_by_id_404_not_found(water_well_thing):
@@ -798,7 +798,7 @@ def test_patch_water_well(water_well_thing, location):
798798
expected_location["created_at"] = (
799799
expected_location["created_at"].isoformat().replace("+00:00", "Z")
800800
)
801-
assert data["active_location"] == expected_location
801+
assert data["current_location"] == expected_location
802802

803803
cleanup_patch_test(Thing, payload, water_well_thing)
804804

@@ -861,7 +861,7 @@ def test_patch_spring(spring_thing, location):
861861
expected_location["created_at"] = (
862862
expected_location["created_at"].isoformat().replace("+00:00", "Z")
863863
)
864-
assert data["active_location"] == expected_location
864+
assert data["current_location"] == expected_location
865865

866866
cleanup_patch_test(Thing, payload, spring_thing)
867867

0 commit comments

Comments
 (0)