summaryrefslogtreecommitdiff
path: root/web-server/opendc/api/v2/topologies/topologyId/test_endpoint.py
blob: d16f7ee24b3ad8e8c9057820281383537b843440 (plain)
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
from opendc.util.database import DB
'''
GET /topologies/{topologyId}
'''


def test_get_topology(client, mocker):
    mocker.patch.object(DB,
                        'fetch_one',
                        return_value={
                            '_id': '1',
                            'authorizations': [{
                                'topologyId': '1',
                                'authorizationLevel': 'EDIT'
                            }]
                        })
    res = client.get('/api/v2/topologies/1')
    assert '200' in res.status


def test_get_topology_non_existing(client, mocker):
    mocker.patch.object(DB, 'fetch_one', return_value=None)
    assert '404' in client.get('/api/v2/topologies/1').status


def test_get_topology_not_authorized(client, mocker):
    mocker.patch.object(DB,
                        'fetch_one',
                        return_value={
                            '_id': '1',
                            'authorizations': [{
                                'topologyId': '2',
                                'authorizationLevel': 'OWN'
                            }]
                        })
    res = client.get('/api/v2/topologies/1')
    assert '403' in res.status


def test_get_topology_no_authorizations(client, mocker):
    mocker.patch.object(DB, 'fetch_one', return_value={'authorizations': []})
    res = client.get('/api/v2/topologies/1')
    assert '403' in res.status


'''
PUT /topologies/{topologyId}
'''
'''
DELETE /topologies/{topologyId}
'''