Skip to content

Commit 8361d4e

Browse files
committed
fixup! feat(validate): add queries to test object counts
1 parent 8e934ee commit 8361d4e

File tree

4 files changed

+34
-24
lines changed

4 files changed

+34
-24
lines changed

apps/project/graphql/queries.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import logging
2+
13
import strawberry
24
import strawberry_django
35
from django.db.models import QuerySet
@@ -12,6 +14,7 @@
1214
TestValidateTaskingManagerProjectResponse,
1315
)
1416
from apps.project.models import Organization, Project, ProjectAsset, ProjectTypeEnum
17+
from project_types.base.project import ValidationException
1518
from project_types.validate.project import ValidateProject
1619
from utils import fields
1720
from utils.geo.raster_tile_server.config import RasterConfig, RasterTileServerNameEnum, RasterTileServerNameEnumWithoutCustom
@@ -31,6 +34,8 @@
3134
ProjectType,
3235
)
3336

37+
logger = logging.getLogger(__name__)
38+
3439

3540
def get_tile_servers() -> RasterTileServersType:
3641
def _get_raster_tile_server_type(enum: RasterTileServerNameEnumWithoutCustom):
@@ -116,8 +121,10 @@ def test_aoi_objects(
116121

117122
response.object_count = object_count
118123
return response
119-
except Exception as e:
124+
except ValidationException as e:
120125
return response.generate_error(str(e))
126+
except Exception as e:
127+
raise GraphQLError(str(e)) from e
121128

122129
@strawberry.field(extensions=[IsAuthenticated()])
123130
def test_tasking_manager_project(
@@ -145,8 +152,10 @@ def test_tasking_manager_project(
145152
response.object_count = object_count
146153

147154
return response
148-
except Exception as e:
155+
except ValidationException as e:
149156
return response.generate_error(str(e))
157+
except Exception as e:
158+
raise GraphQLError(str(e)) from e
150159

151160
tile_servers: RasterTileServersType = strawberry.field(resolver=get_tile_servers, extensions=[IsAuthenticated()])
152161

project_types/validate/api_calls.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,8 @@ def get_object_count_from_ohsome(area: str, ohsome_filter: PydanticLongText) ->
194194
raise ValidateApiCallError
195195
logger.info("Query successful.")
196196

197-
response = response.json()
198-
results = response.get("result", None)
197+
response_json = response.json()
198+
results = response_json.get("result", None)
199199
if results is None:
200200
return None
201201

@@ -204,14 +204,10 @@ def get_object_count_from_ohsome(area: str, ohsome_filter: PydanticLongText) ->
204204
return None
205205

206206
value = first_result.get("value", None)
207-
if value is not None and not isinstance(value, int):
208-
logger.warning(
209-
"unexpected type received from ohsome element count request",
210-
extra=log_extra_response(response=response),
211-
)
212-
raise ValidateApiCallError
207+
if value is None:
208+
return None
213209

214-
return value
210+
return int(value)
215211

216212

217213
def ohsome(request: dict[str, Any], area: str, properties: str | None = None) -> dict[str, Any]:

project_types/validate/project.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -184,10 +184,13 @@ def test_ohsome_objects_from_aoi_asset(project_id: strawberry.ID, asset_id: stra
184184

185185
feature_collection = PydanticFeatureCollection.model_validate(aoi_geojson)
186186

187-
object_count = get_object_count_from_ohsome(
188-
feature_collection.model_dump_json(),
189-
ohsome_filter,
190-
)
187+
try:
188+
object_count = get_object_count_from_ohsome(
189+
feature_collection.model_dump_json(),
190+
ohsome_filter,
191+
)
192+
except Exception as e:
193+
raise base_project.ValidationException("Failed to get object_count from ohsome") from e
191194

192195
return ValidateProject.validate_object_count(object_count)
193196

@@ -230,11 +233,13 @@ def test_tasking_manager_project(
230233
}
231234

232235
feature_collection = ValidateProject.validate_geojson_aoi(aoi_geojson)
233-
234-
object_count = get_object_count_from_ohsome(
235-
feature_collection.model_dump_json(),
236-
ohsome_filter,
237-
)
236+
try:
237+
object_count = get_object_count_from_ohsome(
238+
feature_collection.model_dump_json(),
239+
ohsome_filter,
240+
)
241+
except Exception as e:
242+
raise base_project.ValidationException("Failed to get object_count from ohsome") from e
238243

239244
return ValidateProject.validate_object_count(object_count)
240245

schema.graphql

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2053,8 +2053,8 @@ type Query {
20532053
publicOrganizations(filters: OrganizationFilter, order: OrganizationOrder, pagination: OffsetPaginationInput): OrganizationTypeOffsetPaginated!
20542054
publicProject(id: ID!): ProjectType!
20552055
publicProjects(filters: ProjectFilter, order: ProjectOrder, pagination: OffsetPaginationInput): ProjectTypeOffsetPaginated!
2056-
testAoiObjects(projectId: ID, assetId: ID, ohsomeFilter: String): TestAoiObjectsResponse! @isAuthenticated
2057-
testTaskingManagerProject(hotTmId: String, ohsomeFilter: String): TestTaskingManagerProjectResponse! @isAuthenticated
2056+
testAoiObjects(projectId: ID, assetId: ID, ohsomeFilter: String): TestValidateAoiObjectsResponse! @isAuthenticated
2057+
testTaskingManagerProject(hotTmId: String, ohsomeFilter: String): TestValidateTaskingManagerProjectResponse! @isAuthenticated
20582058
tileServers: RasterTileServersType! @isAuthenticated
20592059
tutorial(id: ID!): TutorialType! @isAuthenticated
20602060
tutorialAsset(id: ID!): TutorialAssetType! @isAuthenticated
@@ -2190,7 +2190,7 @@ type StreetTutorialTaskPropertyType {
21902190
mapillaryImageId: String!
21912191
}
21922192

2193-
type TestAoiObjectsResponse {
2193+
type TestValidateAoiObjectsResponse {
21942194
assetId: ID
21952195
error: String
21962196
objectCount: Int
@@ -2199,7 +2199,7 @@ type TestAoiObjectsResponse {
21992199
projectId: ID
22002200
}
22012201

2202-
type TestTaskingManagerProjectResponse {
2202+
type TestValidateTaskingManagerProjectResponse {
22032203
error: String
22042204
hotTmId: String
22052205
objectCount: Int

0 commit comments

Comments
 (0)