summaryrefslogtreecommitdiff
path: root/web-server/opendc/api/v2/simulations/simulationId/experiments/test_endpoint.py
diff options
context:
space:
mode:
authorjc0b <j@jc0b.computer>2020-06-30 14:12:07 +0200
committerFabian Mastenbroek <mail.fabianm@gmail.com>2020-08-24 19:43:10 +0200
commit66b2d85385d05abb590535da60341876ecdbab71 (patch)
tree0656f64a4179d419adac86e488e21def7a7fa2b8 /web-server/opendc/api/v2/simulations/simulationId/experiments/test_endpoint.py
parent88d8a9cbeae3466230db6bd13120bd4438abbc66 (diff)
parentc99ef7504a1374170f88b89faeb7e6dec6a55253 (diff)
Merge changes with upstream
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.py78
1 files changed, 78 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..1fe09b10
--- /dev/null
+++ b/web-server/opendc/api/v2/simulations/simulationId/experiments/test_endpoint.py
@@ -0,0 +1,78 @@
+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',
+ 'experimentIds': ['1'],
+ 'authorizations': [{
+ 'simulationId': '1',
+ 'authorizationLevel': 'EDIT'
+ }]
+ })
+ mocker.patch.object(DB,
+ 'insert',
+ return_value={
+ '_id': '1',
+ 'topologyId': '1',
+ 'traceId': '1',
+ 'schedulerName': 'default',
+ 'name': 'test',
+ 'state': 'QUEUED',
+ 'lastSimulatedTick': 0,
+ })
+ mocker.patch.object(DB, 'update', return_value=None)
+ 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