summaryrefslogtreecommitdiff
path: root/opendc/api/v2/simulations/simulationId/topologies
diff options
context:
space:
mode:
authorGeorgios Andreadis <info@gandreadis.com>2020-06-26 14:11:49 +0200
committerGeorgios Andreadis <info@gandreadis.com>2020-06-26 14:11:49 +0200
commit3ad26793527bf077e296d652d22a0e4234a9b98d (patch)
tree1b64fd6105a8e3515b2a9c42b5a301b2834eb3d2 /opendc/api/v2/simulations/simulationId/topologies
parentf1017676a150de60b13ff2b33ca83079d87aebfc (diff)
Implement DELETE and fix tests
Diffstat (limited to 'opendc/api/v2/simulations/simulationId/topologies')
-rw-r--r--opendc/api/v2/simulations/simulationId/topologies/endpoint.py16
-rw-r--r--opendc/api/v2/simulations/simulationId/topologies/test_endpoint.py2
2 files changed, 4 insertions, 14 deletions
diff --git a/opendc/api/v2/simulations/simulationId/topologies/endpoint.py b/opendc/api/v2/simulations/simulationId/topologies/endpoint.py
index ee60e5b4..ab7b7006 100644
--- a/opendc/api/v2/simulations/simulationId/topologies/endpoint.py
+++ b/opendc/api/v2/simulations/simulationId/topologies/endpoint.py
@@ -10,21 +10,12 @@ from opendc.util.database import Database
def POST(request):
"""Add a new Topology to the specified simulation and return it"""
- # Make sure required parameters are there
-
- try:
- request.check_required_parameters(path={'simulationId': 'string'}, body={'topology': {'name': 'string'}})
- except exceptions.ParameterError as e:
- return Response(400, str(e))
+ request.check_required_parameters(path={'simulationId': 'string'}, body={'topology': {'name': 'string'}})
simulation = Simulation.from_id(request.params_path['simulationId'])
- validation_error = simulation.validate()
- if validation_error is not None:
- return validation_error
- access_error = simulation.validate_user_access(request.google_id, False)
- if access_error is not None:
- return access_error
+ simulation.check_exists()
+ simulation.check_user_access(request.google_id, True)
topology = Topology({'name': request.params_body['topology']['name']})
topology.set_property('datetimeCreated', Database.datetime_to_string(datetime.now()))
@@ -34,6 +25,5 @@ def POST(request):
simulation.obj['topologyIds'].append(topology.obj['_id'])
simulation.set_property('datetimeLastEdited', Database.datetime_to_string(datetime.now()))
simulation.update()
- # Instantiate the user from the request, and add this topology object to their authorizations
return Response(200, 'Successfully inserted topology.', topology.obj)
diff --git a/opendc/api/v2/simulations/simulationId/topologies/test_endpoint.py b/opendc/api/v2/simulations/simulationId/topologies/test_endpoint.py
index 09f20568..10b5e3c9 100644
--- a/opendc/api/v2/simulations/simulationId/topologies/test_endpoint.py
+++ b/opendc/api/v2/simulations/simulationId/topologies/test_endpoint.py
@@ -6,7 +6,7 @@ def test_add_topology_missing_parameter(client):
def test_add_topology(client, mocker):
- mocker.patch.object(DB, 'fetch_one', return_value={'_id': '1', 'authorizations': []})
+ mocker.patch.object(DB, 'fetch_one', return_value={'_id': '1', 'authorizations': [{'simulationId': '1', 'authorizationLevel': 'OWN'}], 'topologyIds': []})
mocker.patch.object(DB,
'insert',
return_value={