summaryrefslogtreecommitdiff
path: root/web-server/opendc/api
diff options
context:
space:
mode:
authorGeorgios Andreadis <info@gandreadis.com>2020-06-30 14:01:17 +0200
committerFabian Mastenbroek <mail.fabianm@gmail.com>2020-08-24 19:42:28 +0200
commit1c58ae3b25120ac670b897665bac7d8f18156220 (patch)
tree71f8b0bbd8a3044ccb1a8c61b8ed9cc1d4e7fa99 /web-server/opendc/api
parentb9dcda0fb4bbb52ebd8a15acf324561a6d687eba (diff)
Fix more violations and ensure experimentIds handling
Diffstat (limited to 'web-server/opendc/api')
-rw-r--r--web-server/opendc/api/v2/experiments/experimentId/endpoint.py10
-rw-r--r--web-server/opendc/api/v2/experiments/experimentId/test_endpoint.py2
-rw-r--r--web-server/opendc/api/v2/simulations/endpoint.py3
-rw-r--r--web-server/opendc/api/v2/simulations/simulationId/experiments/endpoint.py3
-rw-r--r--web-server/opendc/api/v2/simulations/simulationId/experiments/test_endpoint.py3
-rw-r--r--web-server/opendc/api/v2/topologies/topologyId/endpoint.py1
-rw-r--r--web-server/opendc/api/v2/users/endpoint.py6
-rw-r--r--web-server/opendc/api/v2/users/userId/endpoint.py6
8 files changed, 22 insertions, 12 deletions
diff --git a/web-server/opendc/api/v2/experiments/experimentId/endpoint.py b/web-server/opendc/api/v2/experiments/experimentId/endpoint.py
index 7dacdf48..103c24ac 100644
--- a/web-server/opendc/api/v2/experiments/experimentId/endpoint.py
+++ b/web-server/opendc/api/v2/experiments/experimentId/endpoint.py
@@ -1,5 +1,5 @@
from opendc.models.experiment import Experiment
-from opendc.util import exceptions
+from opendc.models.simulation import Simulation
from opendc.util.rest import Response
@@ -13,7 +13,7 @@ def GET(request):
experiment.check_exists()
experiment.check_user_access(request.google_id, False)
- return Response(200, f'Successfully retrieved Experiment.', experiment.obj)
+ return Response(200, 'Successfully retrieved Experiment.', experiment.obj)
def PUT(request):
@@ -54,6 +54,12 @@ def DELETE(request):
experiment.check_exists()
experiment.check_user_access(request.google_id, True)
+ simulation = Simulation.from_id(experiment.obj['simulationId'])
+ simulation.check_exists()
+ if request.params_path['experimentId'] in simulation.obj['experimentIds']:
+ simulation.obj['experimentIds'].remove(request.params_path['experimentId'])
+ simulation.update()
+
experiment.delete()
return Response(200, 'Successfully deleted experiment.', experiment.obj)
diff --git a/web-server/opendc/api/v2/experiments/experimentId/test_endpoint.py b/web-server/opendc/api/v2/experiments/experimentId/test_endpoint.py
index 35b8b762..c460585f 100644
--- a/web-server/opendc/api/v2/experiments/experimentId/test_endpoint.py
+++ b/web-server/opendc/api/v2/experiments/experimentId/test_endpoint.py
@@ -134,11 +134,13 @@ def test_delete_simulation(client, mocker):
'_id': '1',
'simulationId': '1',
'googleId': 'test',
+ 'experimentIds': ['1'],
'authorizations': [{
'simulationId': '1',
'authorizationLevel': 'OWN'
}]
})
mocker.patch.object(DB, 'delete_one', return_value={})
+ mocker.patch.object(DB, 'update', return_value=None)
res = client.delete('/api/v2/experiments/1')
assert '200' in res.status
diff --git a/web-server/opendc/api/v2/simulations/endpoint.py b/web-server/opendc/api/v2/simulations/endpoint.py
index 232df2ff..b48ad71b 100644
--- a/web-server/opendc/api/v2/simulations/endpoint.py
+++ b/web-server/opendc/api/v2/simulations/endpoint.py
@@ -3,7 +3,6 @@ from datetime import datetime
from opendc.models.simulation import Simulation
from opendc.models.topology import Topology
from opendc.models.user import User
-from opendc.util import exceptions
from opendc.util.database import Database
from opendc.util.rest import Response
@@ -13,7 +12,7 @@ def POST(request):
request.check_required_parameters(body={'simulation': {'name': 'string'}})
- topology = Topology({'name': 'Default topology'})
+ topology = Topology({'name': 'Default topology', 'rooms': []})
topology.insert()
simulation = Simulation({'simulation': request.params_body['simulation']})
diff --git a/web-server/opendc/api/v2/simulations/simulationId/experiments/endpoint.py b/web-server/opendc/api/v2/simulations/simulationId/experiments/endpoint.py
index 2b8aac4d..637b8011 100644
--- a/web-server/opendc/api/v2/simulations/simulationId/experiments/endpoint.py
+++ b/web-server/opendc/api/v2/simulations/simulationId/experiments/endpoint.py
@@ -29,4 +29,7 @@ def POST(request):
experiment.insert()
+ simulation.obj['experimentIds'].append(experiment.obj['_id'])
+ simulation.update()
+
return Response(200, 'Successfully added Experiment.', experiment.obj)
diff --git a/web-server/opendc/api/v2/simulations/simulationId/experiments/test_endpoint.py b/web-server/opendc/api/v2/simulations/simulationId/experiments/test_endpoint.py
index 6a459a3c..1fe09b10 100644
--- a/web-server/opendc/api/v2/simulations/simulationId/experiments/test_endpoint.py
+++ b/web-server/opendc/api/v2/simulations/simulationId/experiments/test_endpoint.py
@@ -46,6 +46,7 @@ def test_add_experiment(client, mocker):
return_value={
'_id': '1',
'simulationId': '1',
+ 'experimentIds': ['1'],
'authorizations': [{
'simulationId': '1',
'authorizationLevel': 'EDIT'
@@ -54,6 +55,7 @@ def test_add_experiment(client, mocker):
mocker.patch.object(DB,
'insert',
return_value={
+ '_id': '1',
'topologyId': '1',
'traceId': '1',
'schedulerName': 'default',
@@ -61,6 +63,7 @@ def test_add_experiment(client, mocker):
'state': 'QUEUED',
'lastSimulatedTick': 0,
})
+ mocker.patch.object(DB, 'update', return_value=None)
res = client.post(
'/api/v2/simulations/1/experiments',
json={'experiment': {
diff --git a/web-server/opendc/api/v2/topologies/topologyId/endpoint.py b/web-server/opendc/api/v2/topologies/topologyId/endpoint.py
index 6c6ab9c2..a8061d69 100644
--- a/web-server/opendc/api/v2/topologies/topologyId/endpoint.py
+++ b/web-server/opendc/api/v2/topologies/topologyId/endpoint.py
@@ -1,5 +1,4 @@
from opendc.models.topology import Topology
-from opendc.util import exceptions
from opendc.util.rest import Response
diff --git a/web-server/opendc/api/v2/users/endpoint.py b/web-server/opendc/api/v2/users/endpoint.py
index c6041756..c597732f 100644
--- a/web-server/opendc/api/v2/users/endpoint.py
+++ b/web-server/opendc/api/v2/users/endpoint.py
@@ -1,6 +1,4 @@
from opendc.models.user import User
-from opendc.util import exceptions
-from opendc.util.database import DB
from opendc.util.rest import Response
@@ -13,7 +11,7 @@ def GET(request):
user.check_exists()
- return Response(200, f'Successfully retrieved user.', user.obj)
+ return Response(200, 'Successfully retrieved user.', user.obj)
def POST(request):
@@ -28,4 +26,4 @@ def POST(request):
user.check_already_exists()
user.insert()
- return Response(200, f'Successfully created user.', user.obj)
+ return Response(200, 'Successfully created user.', user.obj)
diff --git a/web-server/opendc/api/v2/users/userId/endpoint.py b/web-server/opendc/api/v2/users/userId/endpoint.py
index 86975e85..660083b6 100644
--- a/web-server/opendc/api/v2/users/userId/endpoint.py
+++ b/web-server/opendc/api/v2/users/userId/endpoint.py
@@ -11,7 +11,7 @@ def GET(request):
user.check_exists()
- return Response(200, f'Successfully retrieved user.', user.obj)
+ return Response(200, 'Successfully retrieved user.', user.obj)
def PUT(request):
@@ -33,7 +33,7 @@ def PUT(request):
user.update()
- return Response(200, f'Successfully updated user.', user.obj)
+ return Response(200, 'Successfully updated user.', user.obj)
def DELETE(request):
@@ -48,4 +48,4 @@ def DELETE(request):
user.delete()
- return Response(200, f'Successfully deleted user.', user.obj)
+ return Response(200, 'Successfully deleted user.', user.obj)