summaryrefslogtreecommitdiff
path: root/web-server/opendc
diff options
context:
space:
mode:
authorGeorgios Andreadis <info@gandreadis.com>2020-06-30 14:04:11 +0200
committerFabian Mastenbroek <mail.fabianm@gmail.com>2020-08-24 19:42:29 +0200
commite1b29eafbd0b6285b7bea2e24709c7622d41173d (patch)
tree5f923cdf2a3ff2fc271a73a03c6513d06853f6bb /web-server/opendc
parent1c58ae3b25120ac670b897665bac7d8f18156220 (diff)
Fix all violations
Diffstat (limited to 'web-server/opendc')
-rw-r--r--web-server/opendc/api/v2/simulations/simulationId/endpoint.py7
-rw-r--r--web-server/opendc/api/v2/simulations/simulationId/test_endpoint.py3
-rw-r--r--web-server/opendc/api/v2/simulations/simulationId/topologies/endpoint.py1
-rw-r--r--web-server/opendc/models/topology.py4
-rw-r--r--web-server/opendc/util/database.py4
5 files changed, 11 insertions, 8 deletions
diff --git a/web-server/opendc/api/v2/simulations/simulationId/endpoint.py b/web-server/opendc/api/v2/simulations/simulationId/endpoint.py
index 282e3291..05b38686 100644
--- a/web-server/opendc/api/v2/simulations/simulationId/endpoint.py
+++ b/web-server/opendc/api/v2/simulations/simulationId/endpoint.py
@@ -1,5 +1,6 @@
from datetime import datetime
+from opendc.models.experiment import Experiment
from opendc.models.simulation import Simulation
from opendc.models.topology import Topology
from opendc.util.database import Database
@@ -50,8 +51,10 @@ def DELETE(request):
topology = Topology.from_id(topology_id)
topology.delete()
- # TODO remove all experiments
+ for experiment_id in simulation.obj['experimentIds']:
+ experiment = Experiment.from_id(experiment_id)
+ experiment.delete()
simulation.delete()
- return Response(200, f'Successfully deleted simulation.', simulation.obj)
+ return Response(200, 'Successfully deleted simulation.', simulation.obj)
diff --git a/web-server/opendc/api/v2/simulations/simulationId/test_endpoint.py b/web-server/opendc/api/v2/simulations/simulationId/test_endpoint.py
index 7038f1b0..7aa7ebfc 100644
--- a/web-server/opendc/api/v2/simulations/simulationId/test_endpoint.py
+++ b/web-server/opendc/api/v2/simulations/simulationId/test_endpoint.py
@@ -110,7 +110,8 @@ def test_delete_simulation(client, mocker):
'simulationId': '1',
'authorizationLevel': 'OWN'
}],
- 'topologyIds': []
+ 'topologyIds': [],
+ 'experimentIds': [],
})
mocker.patch.object(DB, 'delete_one', return_value={'googleId': 'test'})
res = client.delete('/api/v2/simulations/1')
diff --git a/web-server/opendc/api/v2/simulations/simulationId/topologies/endpoint.py b/web-server/opendc/api/v2/simulations/simulationId/topologies/endpoint.py
index ab7b7006..0ad7e4bf 100644
--- a/web-server/opendc/api/v2/simulations/simulationId/topologies/endpoint.py
+++ b/web-server/opendc/api/v2/simulations/simulationId/topologies/endpoint.py
@@ -2,7 +2,6 @@ from datetime import datetime
from opendc.models.simulation import Simulation
from opendc.models.topology import Topology
-from opendc.util import exceptions
from opendc.util.rest import Response
from opendc.util.database import Database
diff --git a/web-server/opendc/models/topology.py b/web-server/opendc/models/topology.py
index 1447af98..1c717221 100644
--- a/web-server/opendc/models/topology.py
+++ b/web-server/opendc/models/topology.py
@@ -18,7 +18,7 @@ class Topology(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['simulationId']) == str(self.obj['simulationId']),
- user.obj['authorizations']))
+ authorizations = list(
+ filter(lambda x: str(x['simulationId']) == str(self.obj['simulationId']), user.obj['authorizations']))
if len(authorizations) == 0 or (edit_access and authorizations[0]['authorizationLevel'] == 'VIEW'):
raise ClientError(Response(403, "Forbidden from retrieving topology."))
diff --git a/web-server/opendc/util/database.py b/web-server/opendc/util/database.py
index 09d241b5..12d6afc9 100644
--- a/web-server/opendc/util/database.py
+++ b/web-server/opendc/util/database.py
@@ -17,8 +17,8 @@ class Database:
def init_database(self, user, password, database, host):
"""Initializes the database connection."""
- user = urllib.parse.quote_plus(user) # TODO: replace this with environment variable
- password = urllib.parse.quote_plus(password) # TODO: same as above
+ user = urllib.parse.quote_plus(user)
+ password = urllib.parse.quote_plus(password)
database = urllib.parse.quote_plus(database)
host = urllib.parse.quote_plus(host)