1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
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
|