Skip to content

Commit

Permalink
test(custom-yaml): adds example request body and relevant test case f…
Browse files Browse the repository at this point in the history
…or fmtm project extracts
  • Loading branch information
kshitijrajsharma committed Jul 21, 2024
1 parent b47fbb9 commit b724e5e
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 2 deletions.
22 changes: 21 additions & 1 deletion API/custom_exports.py
Original file line number Diff line number Diff line change
Expand Up @@ -852,4 +852,24 @@ async def process_custom_requests_yaml(
validated_data = DynamicCategoriesModel.model_validate(data)
except ValidationError as e:
raise HTTPException(status_code=422, detail=e.errors(include_url=False))
return validated_data

queue_name = validated_data.queue
if validated_data.queue != DEFAULT_QUEUE_NAME and user.role != UserRole.ADMIN.value:
raise HTTPException(
status_code=403,
detail=[{"msg": "Insufficient Permission to choose queue"}],
)
validated_data.categories = [
category for category in validated_data.categories if category
]
if len(validated_data.categories) == 0:
raise HTTPException(
status_code=400, detail=[{"msg": "Categories can't be empty"}]
)
task = process_custom_request.apply_async(
args=(validated_data.model_dump(),),
queue=queue_name,
track_started=True,
kwargs={"user": user.model_dump()},
)
return JSONResponse({"task_id": task.id, "track_link": f"/tasks/status/{task.id}/"})
2 changes: 1 addition & 1 deletion src/validation/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,7 @@ class CategoriesBase(BaseModel):
},
"types": ["lines", "polygons"],
"select": ["name", "highway"],
"where": "highway IS NOT NULL",
"where": "tags['highway'] IS NOT NULL",
"formats": ["geojson"],
}
}
Expand Down
42 changes: 42 additions & 0 deletions tests/test_API.py
Original file line number Diff line number Diff line change
Expand Up @@ -1320,6 +1320,48 @@ def test_full_hdx_set_iso():
wait_for_task_completion(track_link)


### Custom Snapshot Using YAML


def test_custom_yaml_normal_fmtm_request():
headers = {"access-token": access_token}
payload = """
dataset:
dataset_folder: FMTM
dataset_prefix: hotosm_fmtm_project_1
dataset_title: Field Mapping Tasking Manger Project 1
categories:
- Buildings:
formats:
- geojson
- fgb
select:
- name
- name:en
types:
- polygons
where: tags['building'] IS NOT NULL
geometry: {
"type": "Polygon",
"coordinates": [
[
[83.96919250488281, 28.194446860487773],
[83.99751663208006, 28.194446860487773],
[83.99751663208006, 28.214869548073377],
[83.96919250488281, 28.214869548073377],
[83.96919250488281, 28.194446860487773],
]
],
}"""

response = client.post("/v1/custom/snapshot/", json=payload, headers=headers)

assert response.status_code == 200
res = response.json()
track_link = res["track_link"]
wait_for_task_completion(track_link)


# ## Tasks connection


Expand Down

0 comments on commit b724e5e

Please sign in to comment.