diff options
| author | Fabian Mastenbroek <mail.fabianm@gmail.com> | 2020-07-14 21:10:56 +0200 |
|---|---|---|
| committer | Fabian Mastenbroek <mail.fabianm@gmail.com> | 2020-08-24 19:48:04 +0200 |
| commit | 02997b2522b9c66072b16f1425c02e81e0085e3c (patch) | |
| tree | eb8cb533e3ef37a11598e86736b063293f8b0e2b /web-server/opendc/api/v2/projects/projectId/topologies | |
| parent | 1a4776636bf6b585d4a19a6721d9d57b02c88ca4 (diff) | |
Rename web-server to API
This change renames the web-server component to API in order to be more
descriptive of its role. The OpenDC API bridges between the frontend on
one side and the database and simulator on the other side.
Diffstat (limited to 'web-server/opendc/api/v2/projects/projectId/topologies')
3 files changed, 0 insertions, 81 deletions
diff --git a/web-server/opendc/api/v2/projects/projectId/topologies/__init__.py b/web-server/opendc/api/v2/projects/projectId/topologies/__init__.py deleted file mode 100644 index e69de29b..00000000 --- a/web-server/opendc/api/v2/projects/projectId/topologies/__init__.py +++ /dev/null diff --git a/web-server/opendc/api/v2/projects/projectId/topologies/endpoint.py b/web-server/opendc/api/v2/projects/projectId/topologies/endpoint.py deleted file mode 100644 index 211dc15d..00000000 --- a/web-server/opendc/api/v2/projects/projectId/topologies/endpoint.py +++ /dev/null @@ -1,31 +0,0 @@ -from datetime import datetime - -from opendc.models.project import Project -from opendc.models.topology import Topology -from opendc.util.rest import Response -from opendc.util.database import Database - - -def POST(request): - """Add a new Topology to the specified project and return it""" - - request.check_required_parameters(path={'projectId': 'string'}, body={'topology': {'name': 'string'}}) - - project = Project.from_id(request.params_path['projectId']) - - project.check_exists() - project.check_user_access(request.google_id, True) - - topology = Topology({ - 'projectId': request.params_path['projectId'], - 'name': request.params_body['topology']['name'], - 'rooms': request.params_body['topology']['rooms'], - }) - - topology.insert() - - project.obj['topologyIds'].append(topology.get_id()) - project.set_property('datetimeLastEdited', Database.datetime_to_string(datetime.now())) - project.update() - - return Response(200, 'Successfully inserted topology.', topology.obj) diff --git a/web-server/opendc/api/v2/projects/projectId/topologies/test_endpoint.py b/web-server/opendc/api/v2/projects/projectId/topologies/test_endpoint.py deleted file mode 100644 index ca123a73..00000000 --- a/web-server/opendc/api/v2/projects/projectId/topologies/test_endpoint.py +++ /dev/null @@ -1,50 +0,0 @@ -from opendc.util.database import DB - - -def test_add_topology_missing_parameter(client): - assert '400' in client.post('/api/v2/projects/1/topologies').status - - -def test_add_topology(client, mocker): - mocker.patch.object(DB, - 'fetch_one', - return_value={ - '_id': '1', - 'authorizations': [{ - 'projectId': '1', - 'authorizationLevel': 'OWN' - }], - 'topologyIds': [] - }) - mocker.patch.object(DB, - 'insert', - return_value={ - '_id': '1', - 'datetimeCreated': '000', - 'datetimeLastEdited': '000', - 'topologyIds': [] - }) - mocker.patch.object(DB, 'update', return_value={}) - res = client.post('/api/v2/projects/1/topologies', json={'topology': {'name': 'test project', 'rooms': []}}) - assert 'rooms' in res.json['content'] - assert '200' in res.status - - -def test_add_topology_not_authorized(client, mocker): - mocker.patch.object(DB, - 'fetch_one', - return_value={ - '_id': '1', - 'projectId': '1', - 'authorizations': [{ - 'projectId': '1', - 'authorizationLevel': 'VIEW' - }] - }) - assert '403' in client.post('/api/v2/projects/1/topologies', - json={ - 'topology': { - 'name': 'test_topology', - 'rooms': {} - } - }).status |
