Skip to content

Commit c2fb833

Browse files
author
Paul Duncan
committed
tests ensure saved_location_id is sent as expected where relevant.
Beam location now handles either a Location or a location_id
1 parent e045a0a commit c2fb833

File tree

3 files changed

+76
-2
lines changed

3 files changed

+76
-2
lines changed

predicthq/endpoints/v1/beam/schemas.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from pydantic import BaseModel, Field, ConfigDict
22
from datetime import datetime
33
from predicthq.endpoints.schemas import ArgKwargResultSet
4-
from typing import Optional, List
4+
from typing import Optional, List, Union
55

66
# Python < 3.11 does not have StrEnum in the enum module
77
import sys
@@ -61,6 +61,10 @@ class Location(BaseModel):
6161
google_place_id: Optional[str] = None
6262

6363

64+
class LocationId(BaseModel):
65+
saved_location_id: str
66+
67+
6468
class RankLevel(BaseModel):
6569
model_config: ConfigDict = ConfigDict(extra="allow")
6670

@@ -192,7 +196,7 @@ class Analysis(BaseModel):
192196

193197
analysis_id: Optional[str] = None
194198
name: str
195-
location: Location
199+
location: Union[Location, LocationId]
196200
rank: Rank
197201
user_id: Optional[str] = None
198202
access_type: str

tests/endpoints/v1/test_events.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ def test_search_params_underscores(self, client):
4444
updated__gte="2016-03-01",
4545
updated__lt="2016-04-01",
4646
updated__tz="Pacific/Auckland",
47+
saved_location__location_id="UVel7RGxM7U2ISE1AQOwJQ",
4748
)
4849

4950
client.request.assert_called_once_with(
@@ -80,6 +81,7 @@ def test_search_params_underscores(self, client):
8081
"updated.gte": "2016-03-01",
8182
"updated.lt": "2016-04-01",
8283
"updated.tz": "Pacific/Auckland",
84+
"saved_location.location_id": "UVel7RGxM7U2ISE1AQOwJQ",
8385
},
8486
verify=True,
8587
)
@@ -165,6 +167,7 @@ def test_search_params_dicts(self, client):
165167
end={"gte": "2016-05-01", "lt": "2016-06-01", "tz": "Pacific/Auckland"},
166168
active={"gte": "2016-03-01", "lt": "2016-04-01", "tz": "Pacific/Auckland"},
167169
updated={"gte": "2016-03-01", "lt": "2016-04-01", "tz": "Pacific/Auckland"},
170+
saved_location={"location_id": "UVel7RGxM7U2ISE1AQOwJQ"},
168171
)
169172

170173
client.request.assert_called_once_with(
@@ -200,6 +203,7 @@ def test_search_params_dicts(self, client):
200203
"updated.gte": "2016-03-01",
201204
"updated.lt": "2016-04-01",
202205
"updated.tz": "Pacific/Auckland",
206+
"saved_location.location_id": "UVel7RGxM7U2ISE1AQOwJQ",
203207
},
204208
verify=True,
205209
)

tests/endpoints/v1/test_features.py

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -865,3 +865,69 @@ def test_spend_request_params_dicts(self, client):
865865
verify=True,
866866
params=None,
867867
)
868+
869+
@with_mock_client(
870+
request_returns=load_fixture(
871+
"requests_responses/features_test/test_empty_search"
872+
)
873+
)
874+
def test_saved_location_ids_params_dicts(self, client):
875+
client.features.obtain_features(
876+
active={"gte": "2017-12-31", "lte": "2018-01-02"},
877+
location={
878+
"saved_location_id": [
879+
"BN7ZSw8xza9FviPVfyCycd",
880+
"X3uyTFbDOUaX2q_Qh5i31b",
881+
"X3uyTFbDOUhrfq_Qh5i31A",
882+
]
883+
},
884+
)
885+
886+
client.request.assert_called_once_with(
887+
"post",
888+
"/v1/features/",
889+
json={
890+
"active": {"gte": "2017-12-31", "lte": "2018-01-02"},
891+
"location": {
892+
"saved_location_id": [
893+
"BN7ZSw8xza9FviPVfyCycd",
894+
"X3uyTFbDOUaX2q_Qh5i31b",
895+
"X3uyTFbDOUhrfq_Qh5i31A",
896+
]
897+
},
898+
},
899+
verify=True,
900+
params=None,
901+
)
902+
903+
@with_mock_client(
904+
request_returns=load_fixture(
905+
"requests_responses/features_test/test_empty_search"
906+
)
907+
)
908+
def test_saved_location_ids_params_undersores(self, client):
909+
client.features.obtain_features(
910+
active={"gte": "2017-12-31", "lte": "2018-01-02"},
911+
location__saved_location_id=[
912+
"BN7ZSw8xza9FviPVfyCycd",
913+
"X3uyTFbDOUaX2q_Qh5i31b",
914+
"X3uyTFbDOUhrfq_Qh5i31A",
915+
],
916+
)
917+
918+
client.request.assert_called_once_with(
919+
"post",
920+
"/v1/features/",
921+
json={
922+
"active": {"gte": "2017-12-31", "lte": "2018-01-02"},
923+
"location": {
924+
"saved_location_id": [
925+
"BN7ZSw8xza9FviPVfyCycd",
926+
"X3uyTFbDOUaX2q_Qh5i31b",
927+
"X3uyTFbDOUhrfq_Qh5i31A",
928+
]
929+
},
930+
},
931+
verify=True,
932+
params=None,
933+
)

0 commit comments

Comments
 (0)