Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 27 additions & 14 deletions opengeodeweb_back_schemas.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"opengeodeweb_back": {
"create": {
"point": {
"$id": "opengeodeweb_back/create/point",
"route": "/point",
"point_set": {
"$id": "opengeodeweb_back/create/point_set",
"route": "/point_set",
"methods": [
"POST"
],
Expand All @@ -13,21 +13,34 @@
"type": "string",
"minLength": 1
},
"x": {
"type": "number"
},
"y": {
"type": "number"
},
"z": {
"type": "number"
"points": {
"type": "array",
"items": {
"type": "object",
"properties": {
"x": {
"type": "number"
},
"y": {
"type": "number"
},
"z": {
"type": "number"
}
},
"required": [
"x",
"y",
"z"
],
"additionalProperties": false
},
"minItems": 1
}
},
"required": [
"name",
"x",
"y",
"z"
"points"
],
"additionalProperties": false
}
Expand Down
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,3 @@ werkzeug==3.1.2
# flask
# flask-cors

opengeodeweb-microservice==1.*,>=1.1.1
18 changes: 9 additions & 9 deletions src/opengeodeweb_back/routes/create/blueprint_create.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,21 @@


@routes.route(
schemas_dict["point"]["route"],
methods=schemas_dict["point"]["methods"],
schemas_dict["point_set"]["route"],
methods=schemas_dict["point_set"]["methods"],
)
def point() -> flask.Response:
"""Endpoint to create a single point in 3D space."""
json_data = utils_functions.validate_request(flask.request, schemas_dict["point"])
params = schemas.Point.from_dict(json_data)
def point_set() -> flask.Response:
json_data = utils_functions.validate_request(
flask.request, schemas_dict["point_set"]
)
params = schemas.PointSet.from_dict(json_data)

# Create the point
pointset = GeodePointSet3D()
builder = pointset.builder()
builder.set_name(params.name)
builder.create_point(opengeode.Point3D([params.x, params.y, params.z]))
for point in params.points:
builder.create_point(opengeode.Point3D([point.x, point.y, point.z]))

# Save and get info
result = utils_functions.generate_native_viewable_and_light_viewable_from_object(
pointset
)
Expand Down
2 changes: 1 addition & 1 deletion src/opengeodeweb_back/routes/create/schemas/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from .point import *
from .point_set import *
22 changes: 0 additions & 22 deletions src/opengeodeweb_back/routes/create/schemas/point.json

This file was deleted.

27 changes: 27 additions & 0 deletions src/opengeodeweb_back/routes/create/schemas/point_set.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"route": "/point_set",
"methods": ["POST"],
"type": "object",
"properties": {
"name": {
"type": "string",
"minLength": 1
},
"points": {
"type": "array",
"items": {
"type": "object",
"properties": {
"x": { "type": "number" },
"y": { "type": "number" },
"z": { "type": "number" }
},
"required": ["x", "y", "z"],
"additionalProperties": false
},
"minItems": 1
}
},
"required": ["name", "points"],
"additionalProperties": false
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
from dataclasses_json import DataClassJsonMixin
from dataclasses import dataclass
from typing import List


@dataclass
class Point(DataClassJsonMixin):
def __post_init__(self) -> None:
print(self, flush=True)

name: str
x: float
y: float
z: float


@dataclass
class PointSet(DataClassJsonMixin):
def __post_init__(self) -> None:
print(self, flush=True)

name: str
points: List[Point]
35 changes: 26 additions & 9 deletions tests/test_create_routes.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Standard library imports
import uuid
import copy

# Third party imports
import pytest
Expand All @@ -11,12 +11,12 @@

@pytest.fixture
def point_data() -> test_utils.JsonData:
return {"name": "test_point", "x": 1.0, "y": 2.0, "z": 3.0}
return {"name": "test_point", "points": [{"x": 1.0, "y": 2.0, "z": 3.0}]}


def test_create_point(client: FlaskClient, point_data: test_utils.JsonData) -> None:
Comment thread
MaxNumerique marked this conversation as resolved.
"""Test the creation of a point with valid data."""
route: str = "/opengeodeweb_back/create/point"
route: str = "/opengeodeweb_back/create/point_set"

# Test with all required data
response = client.post(route, json=point_data)
Expand All @@ -36,24 +36,41 @@ def test_create_point(client: FlaskClient, point_data: test_utils.JsonData) -> N
assert response_data["geode_object_type"] == "PointSet3D"

# Test with missing parameters
test_utils.test_route_wrong_params(client, route, lambda: point_data.copy())
test_utils.test_route_wrong_params(client, route, lambda: copy.deepcopy(point_data))


def test_create_point_set_multiple(client: FlaskClient) -> None:
"""Test the creation of a point set with multiple points."""
route: str = "/opengeodeweb_back/create/point_set"
data = {
"name": "multiple_points",
"points": [
{"x": 1.0, "y": 2.0, "z": 3.0},
{"x": 4.0, "y": 5.0, "z": 6.0},
{"x": 7.0, "y": 8.0, "z": 9.0},
],
}
response = client.post(route, json=data)
assert response.status_code == 200

response_data = response.get_json()
assert response_data["name"] == data["name"]
assert response_data["geode_object_type"] == "PointSet3D"


def test_create_point_with_invalid_data(client: FlaskClient) -> None:
"""Test the point creation endpoint with invalid data."""
route: str = "/opengeodeweb_back/create/point"
route: str = "/opengeodeweb_back/create/point_set"

# Test with non-numeric coordinates
invalid_data: test_utils.JsonData = {
"name": "invalid_point",
"x": "not_a_number",
"y": 2.0,
"z": 3.0,
"points": [{"x": "not_a_number", "y": 2.0, "z": 3.0}],
}
response = client.post(route, json=invalid_data)
assert response.status_code == 400

# Test with missing coordinates
invalid_data = {"name": "invalid_point", "y": 2.0, "z": 3.0}
invalid_data = {"name": "invalid_point", "points": [{"y": 2.0, "z": 3.0}]}
response = client.post(route, json=invalid_data)
assert response.status_code == 400
6 changes: 2 additions & 4 deletions tests/test_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -583,12 +583,10 @@ def test_import_project_route(client: FlaskClient, tmp_path: Path) -> None:


def test_save_viewable_workflow_from_object(client: FlaskClient) -> None:
route = "/opengeodeweb_back/create/point"
route = "/opengeodeweb_back/create/point_set"
point_data = {
"name": "workflow_point_3d",
"x": 0.0,
"y": 0.0,
"z": 0.0,
"points": [{"x": 0.0, "y": 0.0, "z": 0.0}],
}

response = client.post(route, json=point_data)
Expand Down
Loading