summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorgios Andreadis <info@gandreadis.com>2020-07-06 08:43:42 +0200
committerFabian Mastenbroek <mail.fabianm@gmail.com>2020-08-24 19:47:24 +0200
commit7331e9baf2cfe7bdfb24effcf0a4801da1e7ea4d (patch)
tree5e999ef6007f89d2e06a26f65b0e37b9ce6e9bc4
parente254f4cc4fa6e2446fd4689cc7cabf3abbc24af6 (diff)
Make tests consistent
-rw-r--r--web-server/opendc/api/v2/experiments/experimentId/endpoint.py9
-rw-r--r--web-server/opendc/api/v2/experiments/experimentId/test_endpoint.py30
-rw-r--r--web-server/opendc/api/v2/topologies/topologyId/test_endpoint.py13
-rw-r--r--web-server/opendc/models/prefab.py3
4 files changed, 17 insertions, 38 deletions
diff --git a/web-server/opendc/api/v2/experiments/experimentId/endpoint.py b/web-server/opendc/api/v2/experiments/experimentId/endpoint.py
index 1611f889..dc056454 100644
--- a/web-server/opendc/api/v2/experiments/experimentId/endpoint.py
+++ b/web-server/opendc/api/v2/experiments/experimentId/endpoint.py
@@ -19,12 +19,9 @@ def GET(request):
def PUT(request):
"""Update this Experiments name."""
- request.check_required_parameters(path={'experimentId': 'string'},
- body={
- 'experiment': {
- 'name': 'string',
- }
- })
+ request.check_required_parameters(path={'experimentId': 'string'}, body={'experiment': {
+ 'name': 'string',
+ }})
experiment = Experiment.from_id(request.params_path['experimentId'])
diff --git a/web-server/opendc/api/v2/experiments/experimentId/test_endpoint.py b/web-server/opendc/api/v2/experiments/experimentId/test_endpoint.py
index f3aa111c..3532f9ae 100644
--- a/web-server/opendc/api/v2/experiments/experimentId/test_endpoint.py
+++ b/web-server/opendc/api/v2/experiments/experimentId/test_endpoint.py
@@ -48,12 +48,11 @@ def test_update_experiment_missing_parameter(client):
def test_update_experiment_non_existing(client, mocker):
mocker.patch.object(DB, 'fetch_one', return_value=None)
- assert '404' in client.put('/api/v2/experiments/1',
- json={
- 'experiment': {
- 'name': 'test',
- }
- }).status
+ assert '404' in client.put('/api/v2/experiments/1', json={
+ 'experiment': {
+ 'name': 'test',
+ }
+ }).status
def test_update_experiment_not_authorized(client, mocker):
@@ -68,12 +67,11 @@ def test_update_experiment_not_authorized(client, mocker):
}]
})
mocker.patch.object(DB, 'update', return_value={})
- assert '403' in client.put('/api/v2/experiments/1',
- json={
- 'experiment': {
- 'name': 'test',
- }
- }).status
+ assert '403' in client.put('/api/v2/experiments/1', json={
+ 'experiment': {
+ 'name': 'test',
+ }
+ }).status
def test_update_experiment(client, mocker):
@@ -89,11 +87,9 @@ def test_update_experiment(client, mocker):
})
mocker.patch.object(DB, 'update', return_value={})
- res = client.put(
- '/api/v2/experiments/1',
- json={'experiment': {
- 'name': 'test',
- }})
+ res = client.put('/api/v2/experiments/1', json={'experiment': {
+ 'name': 'test',
+ }})
assert '200' in res.status
diff --git a/web-server/opendc/api/v2/topologies/topologyId/test_endpoint.py b/web-server/opendc/api/v2/topologies/topologyId/test_endpoint.py
index ffdce74e..d3c20de3 100644
--- a/web-server/opendc/api/v2/topologies/topologyId/test_endpoint.py
+++ b/web-server/opendc/api/v2/topologies/topologyId/test_endpoint.py
@@ -1,7 +1,4 @@
from opendc.util.database import DB
-'''
-GET /topologies/{topologyId}
-'''
def test_get_topology(client, mocker):
@@ -45,11 +42,6 @@ def test_get_topology_no_authorizations(client, mocker):
assert '403' in res.status
-'''
-PUT /topologies/{topologyId}
-'''
-
-
def test_update_topology_missing_parameter(client):
assert '400' in client.put('/api/v2/topologies/1').status
@@ -100,11 +92,6 @@ def test_update_topology(client, mocker):
}).status
-'''
-DELETE /topologies/{topologyId}
-'''
-
-
def test_delete_topology(client, mocker):
mocker.patch.object(DB,
'fetch_one',
diff --git a/web-server/opendc/models/prefab.py b/web-server/opendc/models/prefab.py
index a3611a11..ca9f0b3a 100644
--- a/web-server/opendc/models/prefab.py
+++ b/web-server/opendc/models/prefab.py
@@ -17,8 +17,7 @@ class Prefab(Model):
:param edit_access: True when edit access should be checked, otherwise view access.
"""
user = User.from_google_id(google_id)
- authorizations = list(filter(lambda x: str(x['prefabId']) == str(self.get_id()),
- user.obj['authorizations']))
+ authorizations = list(filter(lambda x: str(x['prefabId']) == str(self.get_id()), user.obj['authorizations']))
if len(authorizations) == 0 or (edit_access and authorizations[0]['authorizationLevel'] == 'VIEW'):
raise ClientError(Response(403, "Forbidden from retrieving prefab."))