summaryrefslogtreecommitdiff
path: root/web-server/opendc/api/v2/experiments
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/v2/experiments
parentb9dcda0fb4bbb52ebd8a15acf324561a6d687eba (diff)
Fix more violations and ensure experimentIds handling
Diffstat (limited to 'web-server/opendc/api/v2/experiments')
-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
2 files changed, 10 insertions, 2 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