summaryrefslogtreecommitdiff
path: root/web-server/opendc/api/v2/simulations/simulationId/experiments/test_endpoint.py
diff options
context:
space:
mode:
authorGeorgios Andreadis <info@gandreadis.com>2020-06-30 11:43:07 +0200
committerFabian Mastenbroek <mail.fabianm@gmail.com>2020-08-24 19:42:27 +0200
commit676ccde281841005e3f318bf267ea1dbcdf6fc87 (patch)
tree53c9257ada1cffeb0cba4f0079e2cad679e0990e /web-server/opendc/api/v2/simulations/simulationId/experiments/test_endpoint.py
parent9b910a49270311fd6f099f0f0674a1fd0ab48a20 (diff)
Add experiment POST
Diffstat (limited to 'web-server/opendc/api/v2/simulations/simulationId/experiments/test_endpoint.py')
-rw-r--r--web-server/opendc/api/v2/simulations/simulationId/experiments/test_endpoint.py75
1 files changed, 75 insertions, 0 deletions
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
new file mode 100644
index 00000000..6a459a3c
--- /dev/null
+++ b/web-server/opendc/api/v2/simulations/simulationId/experiments/test_endpoint.py
@@ -0,0 +1,75 @@
+from opendc.util.database import DB
+
+
+def test_add_experiment_missing_parameter(client):
+ assert '400' in client.post('/api/v2/simulations/1/experiments').status
+
+
+def test_add_experiment_non_existing_simulation(client, mocker):
+ mocker.patch.object(DB, 'fetch_one', return_value=None)
+ assert '404' in client.post('/api/v2/simulations/1/experiments',
+ json={
+ 'experiment': {
+ 'topologyId': '1',
+ 'traceId': '1',
+ 'schedulerName': 'default',
+ 'name': 'test',
+ }
+ }).status
+
+
+def test_add_experiment_not_authorized(client, mocker):
+ mocker.patch.object(DB,
+ 'fetch_one',
+ return_value={
+ '_id': '1',
+ 'simulationId': '1',
+ 'authorizations': [{
+ 'simulationId': '1',
+ 'authorizationLevel': 'VIEW'
+ }]
+ })
+ assert '403' in client.post('/api/v2/simulations/1/experiments',
+ json={
+ 'experiment': {
+ 'topologyId': '1',
+ 'traceId': '1',
+ 'schedulerName': 'default',
+ 'name': 'test',
+ }
+ }).status
+
+
+def test_add_experiment(client, mocker):
+ mocker.patch.object(DB,
+ 'fetch_one',
+ return_value={
+ '_id': '1',
+ 'simulationId': '1',
+ 'authorizations': [{
+ 'simulationId': '1',
+ 'authorizationLevel': 'EDIT'
+ }]
+ })
+ mocker.patch.object(DB,
+ 'insert',
+ return_value={
+ 'topologyId': '1',
+ 'traceId': '1',
+ 'schedulerName': 'default',
+ 'name': 'test',
+ 'state': 'QUEUED',
+ 'lastSimulatedTick': 0,
+ })
+ res = client.post(
+ '/api/v2/simulations/1/experiments',
+ json={'experiment': {
+ 'topologyId': '1',
+ 'traceId': '1',
+ 'schedulerName': 'default',
+ 'name': 'test',
+ }})
+ assert 'topologyId' in res.json['content']
+ assert 'state' in res.json['content']
+ assert 'lastSimulatedTick' in res.json['content']
+ assert '200' in res.status