diff options
| author | jc0b <j@jc0b.computer> | 2020-07-07 16:55:22 +0200 |
|---|---|---|
| committer | Fabian Mastenbroek <mail.fabianm@gmail.com> | 2020-08-24 19:47:51 +0200 |
| commit | 223e916997eb641a1662110b6de630a4cdfdf479 (patch) | |
| tree | 90ca4364461f676db45f25e03d8f22fc32f9fdd8 /web-server/opendc/api/v2/experiments | |
| parent | 9ff1e3c6bae253372a468dbdc9b8369ab8dd2c6f (diff) | |
| parent | b810c4413079bf5aeb5374f1cd20e151a83530d0 (diff) | |
Merge branch 'feature/mongodb-migration' of github.com:atlarge-research/opendc-dev into feature/mongodb-migration
Diffstat (limited to 'web-server/opendc/api/v2/experiments')
| -rw-r--r-- | web-server/opendc/api/v2/experiments/experimentId/endpoint.py | 21 | ||||
| -rw-r--r-- | web-server/opendc/api/v2/experiments/experimentId/test_endpoint.py | 62 |
2 files changed, 38 insertions, 45 deletions
diff --git a/web-server/opendc/api/v2/experiments/experimentId/endpoint.py b/web-server/opendc/api/v2/experiments/experimentId/endpoint.py index 1611f889..6706dc57 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.models.simulation import Simulation +from opendc.models.project import Project from opendc.util.rest import Response @@ -19,12 +19,9 @@ def GET(request): def PUT(request): """Update this Experiments name.""" - request.check_required_parameters(path={'experimentId': 'string'}, - body={ - 'experiment': { - 'name': 'string', - } - }) + request.check_required_parameters(path={'experimentId': 'string'}, body={'experiment': { + 'name': 'string', + }}) experiment = Experiment.from_id(request.params_path['experimentId']) @@ -48,11 +45,11 @@ 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() + project = Project.from_id(experiment.obj['projectId']) + project.check_exists() + if request.params_path['experimentId'] in project.obj['experimentIds']: + project.obj['experimentIds'].remove(request.params_path['experimentId']) + project.update() old_object = experiment.delete() 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 f3aa111c..a284cf32 100644 --- a/web-server/opendc/api/v2/experiments/experimentId/test_endpoint.py +++ b/web-server/opendc/api/v2/experiments/experimentId/test_endpoint.py @@ -7,7 +7,7 @@ def test_get_experiment_non_existing(client, mocker): def test_get_experiment_no_authorizations(client, mocker): - mocker.patch.object(DB, 'fetch_one', return_value={'simulationId': '1', 'authorizations': []}) + mocker.patch.object(DB, 'fetch_one', return_value={'projectId': '1', 'authorizations': []}) res = client.get('/api/v2/experiments/1') assert '403' in res.status @@ -16,10 +16,10 @@ def test_get_experiment_not_authorized(client, mocker): mocker.patch.object(DB, 'fetch_one', return_value={ - 'simulationId': '1', + 'projectId': '1', '_id': '1', 'authorizations': [{ - 'simulationId': '2', + 'projectId': '2', 'authorizationLevel': 'OWN' }] }) @@ -31,10 +31,10 @@ def test_get_experiment(client, mocker): mocker.patch.object(DB, 'fetch_one', return_value={ - 'simulationId': '1', + 'projectId': '1', '_id': '1', 'authorizations': [{ - 'simulationId': '1', + 'projectId': '1', 'authorizationLevel': 'EDIT' }] }) @@ -48,12 +48,11 @@ def test_update_experiment_missing_parameter(client): def test_update_experiment_non_existing(client, mocker): mocker.patch.object(DB, 'fetch_one', return_value=None) - assert '404' in client.put('/api/v2/experiments/1', - json={ - 'experiment': { - 'name': 'test', - } - }).status + assert '404' in client.put('/api/v2/experiments/1', json={ + 'experiment': { + 'name': 'test', + } + }).status def test_update_experiment_not_authorized(client, mocker): @@ -61,19 +60,18 @@ def test_update_experiment_not_authorized(client, mocker): 'fetch_one', return_value={ '_id': '1', - 'simulationId': '1', + 'projectId': '1', 'authorizations': [{ - 'simulationId': '1', + 'projectId': '1', 'authorizationLevel': 'VIEW' }] }) mocker.patch.object(DB, 'update', return_value={}) - assert '403' in client.put('/api/v2/experiments/1', - json={ - 'experiment': { - 'name': 'test', - } - }).status + assert '403' in client.put('/api/v2/experiments/1', json={ + 'experiment': { + 'name': 'test', + } + }).status def test_update_experiment(client, mocker): @@ -81,36 +79,34 @@ def test_update_experiment(client, mocker): 'fetch_one', return_value={ '_id': '1', - 'simulationId': '1', + 'projectId': '1', 'authorizations': [{ - 'simulationId': '1', + 'projectId': '1', 'authorizationLevel': 'OWN' }] }) mocker.patch.object(DB, 'update', return_value={}) - res = client.put( - '/api/v2/experiments/1', - json={'experiment': { - 'name': 'test', - }}) + res = client.put('/api/v2/experiments/1', json={'experiment': { + 'name': 'test', + }}) assert '200' in res.status -def test_delete_simulation_non_existing(client, mocker): +def test_delete_project_non_existing(client, mocker): mocker.patch.object(DB, 'fetch_one', return_value=None) assert '404' in client.delete('/api/v2/experiments/1').status -def test_delete_simulation_different_user(client, mocker): +def test_delete_project_different_user(client, mocker): mocker.patch.object(DB, 'fetch_one', return_value={ '_id': '1', - 'simulationId': '1', + 'projectId': '1', 'googleId': 'other_test', 'authorizations': [{ - 'simulationId': '1', + 'projectId': '1', 'authorizationLevel': 'VIEW' }] }) @@ -118,16 +114,16 @@ def test_delete_simulation_different_user(client, mocker): assert '403' in client.delete('/api/v2/experiments/1').status -def test_delete_simulation(client, mocker): +def test_delete_project(client, mocker): mocker.patch.object(DB, 'fetch_one', return_value={ '_id': '1', - 'simulationId': '1', + 'projectId': '1', 'googleId': 'test', 'experimentIds': ['1'], 'authorizations': [{ - 'simulationId': '1', + 'projectId': '1', 'authorizationLevel': 'OWN' }] }) |
