summaryrefslogtreecommitdiff
path: root/opendc/api/v2
diff options
context:
space:
mode:
Diffstat (limited to 'opendc/api/v2')
-rw-r--r--opendc/api/v2/__init__.py0
-rw-r--r--opendc/api/v2/experiments/__init__.py0
-rw-r--r--opendc/api/v2/experiments/experimentId/__init__.py0
-rw-r--r--opendc/api/v2/experiments/experimentId/endpoint.py113
-rw-r--r--opendc/api/v2/experiments/experimentId/last-simulated-tick/__init__.py0
-rw-r--r--opendc/api/v2/experiments/experimentId/last-simulated-tick/endpoint.py32
-rw-r--r--opendc/api/v2/experiments/experimentId/machine-states/__init__.py0
-rw-r--r--opendc/api/v2/experiments/experimentId/machine-states/endpoint.py42
-rw-r--r--opendc/api/v2/experiments/experimentId/rack-states/__init__.py0
-rw-r--r--opendc/api/v2/experiments/experimentId/rack-states/endpoint.py42
-rw-r--r--opendc/api/v2/experiments/experimentId/room-states/__init__.py0
-rw-r--r--opendc/api/v2/experiments/experimentId/room-states/endpoint.py42
-rw-r--r--opendc/api/v2/experiments/experimentId/statistics/__init__.py0
-rw-r--r--opendc/api/v2/experiments/experimentId/statistics/task-durations/__init__.py0
-rw-r--r--opendc/api/v2/experiments/experimentId/statistics/task-durations/endpoint.py37
-rw-r--r--opendc/api/v2/experiments/experimentId/task-states/__init__.py0
-rw-r--r--opendc/api/v2/experiments/experimentId/task-states/endpoint.py42
-rw-r--r--opendc/api/v2/paths.json19
-rw-r--r--opendc/api/v2/schedulers/__init__.py0
-rw-r--r--opendc/api/v2/schedulers/endpoint.py10
-rw-r--r--opendc/api/v2/schedulers/test_endpoint.py2
-rw-r--r--opendc/api/v2/simulations/__init__.py0
-rw-r--r--opendc/api/v2/simulations/endpoint.py30
-rw-r--r--opendc/api/v2/simulations/simulationId/__init__.py0
-rw-r--r--opendc/api/v2/simulations/simulationId/authorizations/__init__.py0
-rw-r--r--opendc/api/v2/simulations/simulationId/authorizations/endpoint.py37
-rw-r--r--opendc/api/v2/simulations/simulationId/authorizations/userId/__init__.py0
-rw-r--r--opendc/api/v2/simulations/simulationId/authorizations/userId/endpoint.py178
-rw-r--r--opendc/api/v2/simulations/simulationId/endpoint.py57
-rw-r--r--opendc/api/v2/simulations/simulationId/experiments/__init__.py0
-rw-r--r--opendc/api/v2/simulations/simulationId/experiments/endpoint.py97
-rw-r--r--opendc/api/v2/simulations/simulationId/test_endpoint.py97
-rw-r--r--opendc/api/v2/simulations/simulationId/topologies/__init__.py0
-rw-r--r--opendc/api/v2/simulations/simulationId/topologies/endpoint.py29
-rw-r--r--opendc/api/v2/simulations/simulationId/topologies/test_endpoint.py26
-rw-r--r--opendc/api/v2/simulations/test_endpoint.py23
-rw-r--r--opendc/api/v2/topologies/__init__.py0
-rw-r--r--opendc/api/v2/topologies/topologyId/__init__.py0
-rw-r--r--opendc/api/v2/topologies/topologyId/endpoint.py16
-rw-r--r--opendc/api/v2/topologies/topologyId/rooms/__init__.py0
-rw-r--r--opendc/api/v2/topologies/topologyId/rooms/endpoint.py93
-rw-r--r--opendc/api/v2/topologies/topologyId/test_endpoint.py46
-rw-r--r--opendc/api/v2/traces/__init__.py0
-rw-r--r--opendc/api/v2/traces/endpoint.py14
-rw-r--r--opendc/api/v2/traces/traceId/__init__.py0
-rw-r--r--opendc/api/v2/traces/traceId/endpoint.py26
-rw-r--r--opendc/api/v2/users/__init__.py0
-rw-r--r--opendc/api/v2/users/endpoint.py31
-rw-r--r--opendc/api/v2/users/test_endpoint.py34
-rw-r--r--opendc/api/v2/users/userId/__init__.py0
-rw-r--r--opendc/api/v2/users/userId/endpoint.py52
-rw-r--r--opendc/api/v2/users/userId/test_endpoint.py53
52 files changed, 0 insertions, 1320 deletions
diff --git a/opendc/api/v2/__init__.py b/opendc/api/v2/__init__.py
deleted file mode 100644
index e69de29b..00000000
--- a/opendc/api/v2/__init__.py
+++ /dev/null
diff --git a/opendc/api/v2/experiments/__init__.py b/opendc/api/v2/experiments/__init__.py
deleted file mode 100644
index e69de29b..00000000
--- a/opendc/api/v2/experiments/__init__.py
+++ /dev/null
diff --git a/opendc/api/v2/experiments/experimentId/__init__.py b/opendc/api/v2/experiments/experimentId/__init__.py
deleted file mode 100644
index e69de29b..00000000
--- a/opendc/api/v2/experiments/experimentId/__init__.py
+++ /dev/null
diff --git a/opendc/api/v2/experiments/experimentId/endpoint.py b/opendc/api/v2/experiments/experimentId/endpoint.py
deleted file mode 100644
index bc2b139e..00000000
--- a/opendc/api/v2/experiments/experimentId/endpoint.py
+++ /dev/null
@@ -1,113 +0,0 @@
-from opendc.models_old.experiment import Experiment
-from opendc.util import exceptions
-from opendc.util.rest import Response
-
-
-def GET(request):
- """Get this Experiment."""
-
- try:
- request.check_required_parameters(path={'experimentId': 'int'})
-
- except exceptions.ParameterError as e:
- return Response(400, str(e))
-
- # Instantiate an Experiment from the database
-
- experiment = Experiment.from_primary_key((request.params_path['experimentId'], ))
-
- # Make sure this Experiment exists
-
- if not experiment.exists():
- return Response(404, '{} not found.'.format(experiment))
-
- # Make sure this user is authorized to view this Experiment
-
- if not experiment.google_id_has_at_least(request.google_id, 'VIEW'):
- return Response(403, 'Forbidden from retrieving {}.'.format(experiment))
-
- # Return this Experiment
-
- experiment.read()
-
- return Response(200, 'Successfully retrieved {}.'.format(experiment), experiment.to_JSON())
-
-
-def PUT(request):
- """Update this Experiment's Path, Trace, Scheduler, and/or name."""
-
- # Make sure required parameters are there
-
- try:
- request.check_required_parameters(
- path={'experimentId': 'int'},
- body={'experiment': {
- 'pathId': 'int',
- 'traceId': 'int',
- 'schedulerName': 'string',
- 'name': 'string'
- }})
-
- except exceptions.ParameterError as e:
- return Response(400, str(e))
-
- # Instantiate an Experiment from the database
-
- experiment = Experiment.from_primary_key((request.params_path['experimentId'], ))
-
- # Make sure this Experiment exists
-
- if not experiment.exists():
- return Response(404, '{} not found.'.format(experiment))
-
- # Make sure this user is authorized to edit this Experiment
-
- if not experiment.google_id_has_at_least(request.google_id, 'EDIT'):
- return Response(403, 'Forbidden from updating {}.'.format(experiment))
-
- # Update this Experiment
-
- experiment.path_id = request.params_body['experiment']['pathId']
- experiment.trace_id = request.params_body['experiment']['traceId']
- experiment.scheduler_name = request.params_body['experiment']['schedulerName']
- experiment.name = request.params_body['experiment']['name']
-
- try:
- experiment.update()
-
- except exceptions.ForeignKeyError:
- return Response(400, 'Foreign key error.')
-
- # Return this Experiment
-
- return Response(200, 'Successfully updated {}.'.format(experiment), experiment.to_JSON())
-
-
-def DELETE(request):
- """Delete this Experiment."""
-
- # Make sure required parameters are there
-
- try:
- request.check_required_parameters(path={'experimentId': 'int'})
-
- except exceptions.ParameterError as e:
- return Response(400, str(e))
-
- # Instantiate an Experiment and make sure it exists
-
- experiment = Experiment.from_primary_key((request.params_path['experimentId'], ))
-
- if not experiment.exists():
- return Response(404, '{} not found.'.format(experiment))
-
- # Make sure this user is authorized to delete this Experiment
-
- if not experiment.google_id_has_at_least(request.google_id, 'EDIT'):
- return Response(403, 'Forbidden from deleting {}.'.format(experiment))
-
- # Delete and return this Experiment
-
- experiment.delete()
-
- return Response(200, 'Successfully deleted {}.'.format(experiment), experiment.to_JSON())
diff --git a/opendc/api/v2/experiments/experimentId/last-simulated-tick/__init__.py b/opendc/api/v2/experiments/experimentId/last-simulated-tick/__init__.py
deleted file mode 100644
index e69de29b..00000000
--- a/opendc/api/v2/experiments/experimentId/last-simulated-tick/__init__.py
+++ /dev/null
diff --git a/opendc/api/v2/experiments/experimentId/last-simulated-tick/endpoint.py b/opendc/api/v2/experiments/experimentId/last-simulated-tick/endpoint.py
deleted file mode 100644
index 3309502c..00000000
--- a/opendc/api/v2/experiments/experimentId/last-simulated-tick/endpoint.py
+++ /dev/null
@@ -1,32 +0,0 @@
-from opendc.models_old.experiment import Experiment
-from opendc.util import exceptions
-from opendc.util.rest import Response
-
-
-def GET(request):
- """Get this Experiment's last simulated tick."""
-
- # Make sure required parameters are there
-
- try:
- request.check_required_parameters(path={'experimentId': 'int'})
-
- except exceptions.ParameterError as e:
- return Response(400, str(e))
-
- # Instantiate an Experiment from the database
-
- experiment = Experiment.from_primary_key((request.params_path['experimentId'], ))
-
- # Make sure this Experiment exists
-
- if not experiment.exists():
- return Response(404, '{} not found.'.format(experiment))
-
- # Make sure this user is authorized to view this Experiment's last simulated tick
-
- if not experiment.google_id_has_at_least(request.google_id, 'VIEW'):
- return Response(403, 'Forbidden from viewing last simulated tick for {}.'.format(experiment))
-
- return Response(200, 'Successfully retrieved last simulated tick for {}.'.format(experiment),
- {'lastSimulatedTick': experiment.last_simulated_tick})
diff --git a/opendc/api/v2/experiments/experimentId/machine-states/__init__.py b/opendc/api/v2/experiments/experimentId/machine-states/__init__.py
deleted file mode 100644
index e69de29b..00000000
--- a/opendc/api/v2/experiments/experimentId/machine-states/__init__.py
+++ /dev/null
diff --git a/opendc/api/v2/experiments/experimentId/machine-states/endpoint.py b/opendc/api/v2/experiments/experimentId/machine-states/endpoint.py
deleted file mode 100644
index c7dcad9a..00000000
--- a/opendc/api/v2/experiments/experimentId/machine-states/endpoint.py
+++ /dev/null
@@ -1,42 +0,0 @@
-from opendc.models_old.experiment import Experiment
-from opendc.models_old.machine_state import MachineState
-from opendc.util import exceptions
-from opendc.util.rest import Response
-
-
-def GET(request):
- """Get this Experiment's Machine States."""
-
- # Make sure required parameters are there
-
- try:
- request.check_required_parameters(path={'experimentId': 'int'})
-
- except exceptions.ParameterError as e:
- return Response(400, str(e))
-
- # Instantiate an Experiment from the database
-
- experiment = Experiment.from_primary_key((request.params_path['experimentId'], ))
-
- # Make sure this Experiment exists
-
- if not experiment.exists():
- return Response(404, '{} not found.'.format(experiment))
-
- # Make sure this user is authorized to view this Experiment's Machine States
-
- if not experiment.google_id_has_at_least(request.google_id, 'VIEW'):
- return Response(403, 'Forbidden from viewing Machine States for {}.'.format(experiment))
-
- # Get and return the Machine States
-
- if 'tick' in request.params_query:
- machine_states = MachineState.from_experiment_id_and_tick(request.params_path['experimentId'],
- request.params_query['tick'])
-
- else:
- machine_states = MachineState.from_experiment_id(request.params_path['experimentId'])
-
- return Response(200, 'Successfully retrieved Machine States for {}.'.format(experiment),
- [x.to_JSON() for x in machine_states])
diff --git a/opendc/api/v2/experiments/experimentId/rack-states/__init__.py b/opendc/api/v2/experiments/experimentId/rack-states/__init__.py
deleted file mode 100644
index e69de29b..00000000
--- a/opendc/api/v2/experiments/experimentId/rack-states/__init__.py
+++ /dev/null
diff --git a/opendc/api/v2/experiments/experimentId/rack-states/endpoint.py b/opendc/api/v2/experiments/experimentId/rack-states/endpoint.py
deleted file mode 100644
index f3acf56a..00000000
--- a/opendc/api/v2/experiments/experimentId/rack-states/endpoint.py
+++ /dev/null
@@ -1,42 +0,0 @@
-from opendc.models_old.experiment import Experiment
-from opendc.models_old.rack_state import RackState
-from opendc.util import exceptions
-from opendc.util.rest import Response
-
-
-def GET(request):
- """Get this Experiment's Tack States."""
-
- # Make sure required parameters are there
-
- try:
- request.check_required_parameters(path={'experimentId': 'int'})
-
- except exceptions.ParameterError as e:
- return Response(400, str(e))
-
- # Instantiate an Experiment from the database
-
- experiment = Experiment.from_primary_key((request.params_path['experimentId'], ))
-
- # Make sure this Experiment exists
-
- if not experiment.exists():
- return Response(404, '{} not found.'.format(experiment))
-
- # Make sure this user is authorized to view this Experiment's Rack States
-
- if not experiment.google_id_has_at_least(request.google_id, 'VIEW'):
- return Response(403, 'Forbidden from viewing Rack States for {}.'.format(experiment))
-
- # Get and return the Rack States
-
- if 'tick' in request.params_query:
- rack_states = RackState.from_experiment_id_and_tick(request.params_path['experimentId'],
- request.params_query['tick'])
-
- else:
- rack_states = RackState.from_experiment_id(request.params_path['experimentId'])
-
- return Response(200, 'Successfully retrieved Rack States for {}.'.format(experiment),
- [x.to_JSON() for x in rack_states])
diff --git a/opendc/api/v2/experiments/experimentId/room-states/__init__.py b/opendc/api/v2/experiments/experimentId/room-states/__init__.py
deleted file mode 100644
index e69de29b..00000000
--- a/opendc/api/v2/experiments/experimentId/room-states/__init__.py
+++ /dev/null
diff --git a/opendc/api/v2/experiments/experimentId/room-states/endpoint.py b/opendc/api/v2/experiments/experimentId/room-states/endpoint.py
deleted file mode 100644
index db3f8b14..00000000
--- a/opendc/api/v2/experiments/experimentId/room-states/endpoint.py
+++ /dev/null
@@ -1,42 +0,0 @@
-from opendc.models_old.experiment import Experiment
-from opendc.models_old.room_state import RoomState
-from opendc.util import exceptions
-from opendc.util.rest import Response
-
-
-def GET(request):
- """Get this Experiment's Room States."""
-
- # Make sure required parameters are there
-
- try:
- request.check_required_parameters(path={'experimentId': 'int'})
-
- except exceptions.ParameterError as e:
- return Response(400, str(e))
-
- # Instantiate an Experiment from the database
-
- experiment = Experiment.from_primary_key((request.params_path['experimentId'], ))
-
- # Make sure this Experiment exists
-
- if not experiment.exists():
- return Response(404, '{} not found.'.format(experiment))
-
- # Make sure this user is authorized to view this Experiment's Room States
-
- if not experiment.google_id_has_at_least(request.google_id, 'VIEW'):
- return Response(403, 'Forbidden from viewing Room States for {}.'.format(experiment))
-
- # Get and return the Room States
-
- if 'tick' in request.params_query:
- room_states = RoomState.from_experiment_id_and_tick(request.params_path['experimentId'],
- request.params_query['tick'])
-
- else:
- room_states = RoomState.from_experiment_id(request.params_path['experimentId'])
-
- return Response(200, 'Successfully retrieved Room States for {}.'.format(experiment),
- [x.to_JSON() for x in room_states])
diff --git a/opendc/api/v2/experiments/experimentId/statistics/__init__.py b/opendc/api/v2/experiments/experimentId/statistics/__init__.py
deleted file mode 100644
index e69de29b..00000000
--- a/opendc/api/v2/experiments/experimentId/statistics/__init__.py
+++ /dev/null
diff --git a/opendc/api/v2/experiments/experimentId/statistics/task-durations/__init__.py b/opendc/api/v2/experiments/experimentId/statistics/task-durations/__init__.py
deleted file mode 100644
index e69de29b..00000000
--- a/opendc/api/v2/experiments/experimentId/statistics/task-durations/__init__.py
+++ /dev/null
diff --git a/opendc/api/v2/experiments/experimentId/statistics/task-durations/endpoint.py b/opendc/api/v2/experiments/experimentId/statistics/task-durations/endpoint.py
deleted file mode 100644
index 498db239..00000000
--- a/opendc/api/v2/experiments/experimentId/statistics/task-durations/endpoint.py
+++ /dev/null
@@ -1,37 +0,0 @@
-from opendc.models_old.experiment import Experiment
-from opendc.models_old.task_duration import TaskDuration
-from opendc.util import exceptions
-from opendc.util.rest import Response
-
-
-def GET(request):
- """Get this Experiment's Task Durations."""
-
- # Make sure required parameters are there
-
- try:
- request.check_required_parameters(path={'experimentId': 'int'})
-
- except exceptions.ParameterError as e:
- return Response(400, str(e))
-
- # Instantiate an Experiment from the database
-
- experiment = Experiment.from_primary_key((request.params_path['experimentId'], ))
-
- # Make sure this Experiment exists
-
- if not experiment.exists():
- return Response(404, '{} not found.'.format(experiment))
-
- # Make sure this user is authorized to view this Experiment's Task Durations
-
- if not experiment.google_id_has_at_least(request.google_id, 'VIEW'):
- return Response(403, 'Forbidden from viewing Task Durations for {}.'.format(experiment))
-
- # Get and return the Task Durations
-
- task_durations = TaskDuration.from_experiment_id(request.params_path['experimentId'])
-
- return Response(200, 'Successfully retrieved Task Durations for {}.'.format(experiment),
- [x.to_JSON() for x in task_durations])
diff --git a/opendc/api/v2/experiments/experimentId/task-states/__init__.py b/opendc/api/v2/experiments/experimentId/task-states/__init__.py
deleted file mode 100644
index e69de29b..00000000
--- a/opendc/api/v2/experiments/experimentId/task-states/__init__.py
+++ /dev/null
diff --git a/opendc/api/v2/experiments/experimentId/task-states/endpoint.py b/opendc/api/v2/experiments/experimentId/task-states/endpoint.py
deleted file mode 100644
index c0ae47fc..00000000
--- a/opendc/api/v2/experiments/experimentId/task-states/endpoint.py
+++ /dev/null
@@ -1,42 +0,0 @@
-from opendc.models_old.experiment import Experiment
-from opendc.models_old.task_state import TaskState
-from opendc.util import exceptions
-from opendc.util.rest import Response
-
-
-def GET(request):
- """Get this Experiment's Task States."""
-
- # Make sure required parameters are there
-
- try:
- request.check_required_parameters(path={'experimentId': 'int'})
-
- except exceptions.ParameterError as e:
- return Response(400, str(e))
-
- # Instantiate an Experiment from the database
-
- experiment = Experiment.from_primary_key((request.params_path['experimentId'], ))
-
- # Make sure this Experiment exists
-
- if not experiment.exists():
- return Response(404, '{} not found.'.format(experiment))
-
- # Make sure this user is authorized to view Task States for this Experiment
-
- if not experiment.google_id_has_at_least(request.google_id, 'VIEW'):
- return Response(403, 'Forbidden from viewing Task States for {}.'.format(experiment))
-
- # Get and return the Task States
-
- if 'tick' in request.params_query:
- task_states = TaskState.from_experiment_id_and_tick(request.params_path['experimentId'],
- request.params_query['tick'])
-
- else:
- task_states = TaskState.query('experiment_id', request.params_path['experimentId'])
-
- return Response(200, 'Successfully retrieved Task States for {}.'.format(experiment),
- [x.to_JSON() for x in task_states])
diff --git a/opendc/api/v2/paths.json b/opendc/api/v2/paths.json
deleted file mode 100644
index ce054a8c..00000000
--- a/opendc/api/v2/paths.json
+++ /dev/null
@@ -1,19 +0,0 @@
-[
- "/users",
- "/users/{userId}",
- "/simulations",
- "/simulations/{simulationId}",
- "/simulations/{simulationId}/authorizations",
- "/simulations/{simulationId}/topologies",
- "/experiments/{experimentId}/last-simulated-tick",
- "/experiments/{experimentId}/machine-states",
- "/experiments/{experimentId}/rack-states",
- "/experiments/{experimentId}/room-states",
- "/experiments/{experimentId}/task-states",
- "/topologies/{topologyId}",
- "/simulations/{simulationId}/experiments",
- "/experiments/{experimentId}",
- "/schedulers",
- "/traces",
- "/traces/{traceId}"
-]
diff --git a/opendc/api/v2/schedulers/__init__.py b/opendc/api/v2/schedulers/__init__.py
deleted file mode 100644
index e69de29b..00000000
--- a/opendc/api/v2/schedulers/__init__.py
+++ /dev/null
diff --git a/opendc/api/v2/schedulers/endpoint.py b/opendc/api/v2/schedulers/endpoint.py
deleted file mode 100644
index 0bbc3322..00000000
--- a/opendc/api/v2/schedulers/endpoint.py
+++ /dev/null
@@ -1,10 +0,0 @@
-from opendc.util.rest import Response
-
-
-SCHEDULERS = ['DEFAULT']
-
-
-def GET(_):
- """Get all available Schedulers."""
-
- return Response(200, 'Successfully retrieved Schedulers.', [{'name': name} for name in SCHEDULERS])
diff --git a/opendc/api/v2/schedulers/test_endpoint.py b/opendc/api/v2/schedulers/test_endpoint.py
deleted file mode 100644
index a0bd8758..00000000
--- a/opendc/api/v2/schedulers/test_endpoint.py
+++ /dev/null
@@ -1,2 +0,0 @@
-def test_get_schedulers(client):
- assert '200' in client.get('/api/v2/schedulers').status
diff --git a/opendc/api/v2/simulations/__init__.py b/opendc/api/v2/simulations/__init__.py
deleted file mode 100644
index e69de29b..00000000
--- a/opendc/api/v2/simulations/__init__.py
+++ /dev/null
diff --git a/opendc/api/v2/simulations/endpoint.py b/opendc/api/v2/simulations/endpoint.py
deleted file mode 100644
index 232df2ff..00000000
--- a/opendc/api/v2/simulations/endpoint.py
+++ /dev/null
@@ -1,30 +0,0 @@
-from datetime import datetime
-
-from opendc.models.simulation import Simulation
-from opendc.models.topology import Topology
-from opendc.models.user import User
-from opendc.util import exceptions
-from opendc.util.database import Database
-from opendc.util.rest import Response
-
-
-def POST(request):
- """Create a new simulation, and return that new simulation."""
-
- request.check_required_parameters(body={'simulation': {'name': 'string'}})
-
- topology = Topology({'name': 'Default topology'})
- topology.insert()
-
- simulation = Simulation({'simulation': request.params_body['simulation']})
- simulation.set_property('datetimeCreated', Database.datetime_to_string(datetime.now()))
- simulation.set_property('datetimeLastEdited', Database.datetime_to_string(datetime.now()))
- simulation.set_property('topologyIds', [topology.obj['_id']])
- simulation.set_property('experimentIds', [])
- simulation.insert()
-
- user = User.from_google_id(request.google_id)
- user.obj['authorizations'].append({'simulationId': simulation.obj['_id'], 'authorizationLevel': 'OWN'})
- user.update()
-
- return Response(200, 'Successfully created simulation.', simulation.obj)
diff --git a/opendc/api/v2/simulations/simulationId/__init__.py b/opendc/api/v2/simulations/simulationId/__init__.py
deleted file mode 100644
index e69de29b..00000000
--- a/opendc/api/v2/simulations/simulationId/__init__.py
+++ /dev/null
diff --git a/opendc/api/v2/simulations/simulationId/authorizations/__init__.py b/opendc/api/v2/simulations/simulationId/authorizations/__init__.py
deleted file mode 100644
index e69de29b..00000000
--- a/opendc/api/v2/simulations/simulationId/authorizations/__init__.py
+++ /dev/null
diff --git a/opendc/api/v2/simulations/simulationId/authorizations/endpoint.py b/opendc/api/v2/simulations/simulationId/authorizations/endpoint.py
deleted file mode 100644
index df2b5cfd..00000000
--- a/opendc/api/v2/simulations/simulationId/authorizations/endpoint.py
+++ /dev/null
@@ -1,37 +0,0 @@
-from opendc.models_old.authorization import Authorization
-from opendc.models_old.simulation import Simulation
-from opendc.util import exceptions
-from opendc.util.rest import Response
-
-
-def GET(request):
- """Find all authorizations for a Simulation."""
-
- # Make sure required parameters are there
-
- try:
- request.check_required_parameters(path={'simulationId': 'string'})
-
- except exceptions.ParameterError as e:
- return Response(400, str(e))
-
- # Instantiate a Simulation and make sure it exists
-
- simulation = Simulation.from_primary_key((request.params_path['simulationId'], ))
-
- if not simulation.exists():
- return Response(404, '{} not found.'.format(simulation))
-
- # Make sure this User is allowed to view this Simulation's Authorizations
-
- if not simulation.google_id_has_at_least(request.google_id, 'VIEW'):
- return Response(403, 'Forbidden from retrieving Authorizations for {}.'.format(simulation))
-
- # Get the Authorizations
-
- authorizations = Authorization.query('simulation_id', request.params_path['simulationId'])
-
- # Return the Authorizations
-
- return Response(200, 'Successfully retrieved Authorizations for {}.'.format(simulation),
- [x.to_JSON() for x in authorizations])
diff --git a/opendc/api/v2/simulations/simulationId/authorizations/userId/__init__.py b/opendc/api/v2/simulations/simulationId/authorizations/userId/__init__.py
deleted file mode 100644
index e69de29b..00000000
--- a/opendc/api/v2/simulations/simulationId/authorizations/userId/__init__.py
+++ /dev/null
diff --git a/opendc/api/v2/simulations/simulationId/authorizations/userId/endpoint.py b/opendc/api/v2/simulations/simulationId/authorizations/userId/endpoint.py
deleted file mode 100644
index 121530db..00000000
--- a/opendc/api/v2/simulations/simulationId/authorizations/userId/endpoint.py
+++ /dev/null
@@ -1,178 +0,0 @@
-from opendc.models_old.authorization import Authorization
-from opendc.models_old.simulation import Simulation
-from opendc.models_old.user import User
-from opendc.util import exceptions
-from opendc.util.rest import Response
-
-
-def DELETE(request):
- """Delete a user's authorization level over a simulation."""
-
- # Make sure required parameters are there
-
- try:
- request.check_required_parameters(path={'simulationId': 'string', 'userId': 'string'})
-
- except exceptions.ParameterError as e:
- return Response(400, str(e))
-
- # Instantiate an Authorization
-
- authorization = Authorization.from_primary_key((request.params_path['userId'], request.params_path['simulationId']))
-
- # Make sure this Authorization exists in the database
-
- if not authorization.exists():
- return Response(404, '{} not found.'.format(authorization))
-
- # Make sure this User is allowed to delete this Authorization
-
- if not authorization.google_id_has_at_least(request.google_id, 'OWN'):
- return Response(403, 'Forbidden from deleting {}.'.format(authorization))
-
- # Delete this Authorization
-
- authorization.delete()
-
- return Response(200, 'Successfully deleted {}.'.format(authorization), authorization.to_JSON())
-
-
-def GET(request):
- """Get this User's Authorization over this Simulation."""
-
- # Make sure required parameters are there
-
- try:
- request.check_required_parameters(path={'simulationId': 'string', 'userId': 'string'})
-
- except exceptions.ParameterError as e:
- return Response(400, str(e))
-
- # Instantiate an Authorization
-
- authorization = Authorization.from_primary_key((request.params_path['userId'], request.params_path['simulationId']))
-
- # Make sure this Authorization exists in the database
-
- if not authorization.exists():
- return Response(404, '{} not found.'.format(authorization))
-
- # Read this Authorization from the database
-
- authorization.read()
-
- # Return this Authorization
-
- return Response(200, 'Successfully retrieved {}'.format(authorization), authorization.to_JSON())
-
-
-def POST(request):
- """Add an authorization for a user's access to a simulation."""
-
- # Make sure required parameters are there
-
- try:
- request.check_required_parameters(path={
- 'userId': 'string',
- 'simulationId': 'string'
- },
- body={'authorization': {
- 'authorizationLevel': 'string'
- }})
-
- except exceptions.ParameterError as e:
- return Response(400, str(e))
-
- # Instantiate an Authorization
-
- authorization = Authorization.from_JSON({
- 'userId':
- request.params_path['userId'],
- 'simulationId':
- request.params_path['simulationId'],
- 'authorizationLevel':
- request.params_body['authorization']['authorizationLevel']
- })
-
- # Make sure the Simulation and User exist
-
- user = User.from_primary_key((authorization.user_id, ))
- if not user.exists():
- return Response(404, '{} not found.'.format(user))
-
- simulation = Simulation.from_primary_key((authorization.simulation_id, ))
- if not simulation.exists():
- return Response(404, '{} not found.'.format(simulation))
-
- # Make sure this User is allowed to add this Authorization
-
- if not simulation.google_id_has_at_least(request.google_id, 'OWN'):
- return Response(403, 'Forbidden from creating {}.'.format(authorization))
-
- # Make sure this Authorization does not already exist
-
- if authorization.exists():
- return Response(409, '{} already exists.'.format(authorization))
-
- # Try to insert this Authorization into the database
-
- try:
- authorization.insert()
-
- except exceptions.ForeignKeyError:
- return Response(400, 'Invalid authorizationLevel')
-
- # Return this Authorization
-
- return Response(200, 'Successfully added {}'.format(authorization), authorization.to_JSON())
-
-
-def PUT(request):
- """Change a user's authorization level over a simulation."""
-
- # Make sure required parameters are there
-
- try:
- request.check_required_parameters(path={
- 'simulationId': 'string',
- 'userId': 'string'
- },
- body={'authorization': {
- 'authorizationLevel': 'string'
- }})
-
- except exceptions.ParameterError as e:
- return Response(400, str(e))
-
- # Instantiate and Authorization
-
- authorization = Authorization.from_JSON({
- 'userId':
- request.params_path['userId'],
- 'simulationId':
- request.params_path['simulationId'],
- 'authorizationLevel':
- request.params_body['authorization']['authorizationLevel']
- })
-
- # Make sure this Authorization exists
-
- if not authorization.exists():
- return Response(404, '{} not found.'.format(authorization))
-
- # Make sure this User is allowed to edit this Authorization
-
- if not authorization.google_id_has_at_least(request.google_id, 'OWN'):
- return Response(403, 'Forbidden from updating {}.'.format(authorization))
-
- # Try to update this Authorization
-
- try:
- authorization.update()
-
- except exceptions.ForeignKeyError as e:
- return Response(400, 'Invalid authorization level.')
-
- # Return this Authorization
-
- return Response(200, 'Successfully updated {}.'.format(authorization), authorization.to_JSON())
diff --git a/opendc/api/v2/simulations/simulationId/endpoint.py b/opendc/api/v2/simulations/simulationId/endpoint.py
deleted file mode 100644
index 282e3291..00000000
--- a/opendc/api/v2/simulations/simulationId/endpoint.py
+++ /dev/null
@@ -1,57 +0,0 @@
-from datetime import datetime
-
-from opendc.models.simulation import Simulation
-from opendc.models.topology import Topology
-from opendc.util.database import Database
-from opendc.util.rest import Response
-
-
-def GET(request):
- """Get this Simulation."""
-
- request.check_required_parameters(path={'simulationId': 'string'})
-
- simulation = Simulation.from_id(request.params_path['simulationId'])
-
- simulation.check_exists()
- simulation.check_user_access(request.google_id, False)
-
- return Response(200, 'Successfully retrieved simulation', simulation.obj)
-
-
-def PUT(request):
- """Update a simulation's name."""
-
- request.check_required_parameters(body={'simulation': {'name': 'name'}}, path={'simulationId': 'string'})
-
- simulation = Simulation.from_id(request.params_path['simulationId'])
-
- simulation.check_exists()
- simulation.check_user_access(request.google_id, True)
-
- simulation.set_property('name', request.params_body['simulation']['name'])
- simulation.set_property('datetime_last_edited', Database.datetime_to_string(datetime.now()))
- simulation.update()
-
- return Response(200, 'Successfully updated simulation.', simulation.obj)
-
-
-def DELETE(request):
- """Delete this Simulation."""
-
- request.check_required_parameters(path={'simulationId': 'string'})
-
- simulation = Simulation.from_id(request.params_path['simulationId'])
-
- simulation.check_exists()
- simulation.check_user_access(request.google_id, True)
-
- for topology_id in simulation.obj['topologyIds']:
- topology = Topology.from_id(topology_id)
- topology.delete()
-
- # TODO remove all experiments
-
- simulation.delete()
-
- return Response(200, f'Successfully deleted simulation.', simulation.obj)
diff --git a/opendc/api/v2/simulations/simulationId/experiments/__init__.py b/opendc/api/v2/simulations/simulationId/experiments/__init__.py
deleted file mode 100644
index e69de29b..00000000
--- a/opendc/api/v2/simulations/simulationId/experiments/__init__.py
+++ /dev/null
diff --git a/opendc/api/v2/simulations/simulationId/experiments/endpoint.py b/opendc/api/v2/simulations/simulationId/experiments/endpoint.py
deleted file mode 100644
index 9df84838..00000000
--- a/opendc/api/v2/simulations/simulationId/experiments/endpoint.py
+++ /dev/null
@@ -1,97 +0,0 @@
-from opendc.models_old.experiment import Experiment
-from opendc.models_old.simulation import Simulation
-from opendc.util import exceptions
-from opendc.util.rest import Response
-
-
-def GET(request):
- """Get this Simulation's Experiments."""
-
- # Make sure required parameters are there
-
- try:
- request.check_required_parameters(path={'simulationId': 'string'})
-
- except exceptions.ParameterError as e:
- return Response(400, str(e))
-
- # Instantiate a Simulation from the database
-
- simulation = Simulation.from_primary_key((request.params_path['simulationId'], ))
-
- # Make sure this Simulation exists
-
- if not simulation.exists():
- return Response(404, '{} not found.'.format(simulation))
-
- # Make sure this user is authorized to view this Simulation's Experiments
-
- if not simulation.google_id_has_at_least(request.google_id, 'VIEW'):
- return Reponse(403, 'Forbidden from viewing Experiments for {}.'.format(simulation))
-
- # Get and return the Experiments
-
- experiments = Experiment.query('simulation_id', request.params_path['simulationId'])
-
- return Response(200, 'Successfully retrieved Experiments for {}.'.format(simulation),
- [x.to_JSON() for x in experiments])
-
-
-def POST(request):
- """Add a new Experiment for this Simulation."""
-
- # Make sure required parameters are there
-
- try:
- request.check_required_parameters(path={'simulationId': 'string'},
- body={
- 'experiment': {
- 'simulationId': 'string',
- 'pathId': 'int',
- 'traceId': 'int',
- 'schedulerName': 'string',
- 'name': 'string'
- }
- })
-
- except exceptions.ParameterError as e:
- return Response(400, str(e))
-
- # Make sure the passed object's simulation id matches the path simulation id
-
- if request.params_path['simulationId'] != request.params_body['experiment']['simulationId']:
- return Response(403, 'ID mismatch.')
-
- # Instantiate a Simulation from the database
-
- simulation = Simulation.from_primary_key((request.params_path['simulationId'], ))
-
- # Make sure this Simulation exists
-
- if not simulation.exists():
- return Response(404, '{} not found.'.format(simulation))
-
- # Make sure this user is authorized to edit this Simulation's Experiments
-
- if not simulation.google_id_has_at_least(request.google_id, 'EDIT'):
- return Response(403, 'Forbidden from adding an experiment to {}.'.format(simulation))
-
- # Instantiate an Experiment
-
- experiment = Experiment.from_JSON(request.params_body['experiment'])
- experiment.state = 'QUEUED'
- experiment.last_simulated_tick = 0
-
- # Try to insert this Experiment
-
- try:
- experiment.insert()
-
- except exceptions.ForeignKeyError as e:
- return Response(400, 'Foreign key constraint not met.' + e)
-
- # Return this Experiment
-
- experiment.read()
-
- return Response(200, 'Successfully added {}.'.format(experiment), experiment.to_JSON())
diff --git a/opendc/api/v2/simulations/simulationId/test_endpoint.py b/opendc/api/v2/simulations/simulationId/test_endpoint.py
deleted file mode 100644
index a0586aab..00000000
--- a/opendc/api/v2/simulations/simulationId/test_endpoint.py
+++ /dev/null
@@ -1,97 +0,0 @@
-from opendc.util.database import DB
-
-
-def test_get_simulation_non_existing(client, mocker):
- mocker.patch.object(DB, 'fetch_one', return_value=None)
- assert '404' in client.get('/api/v2/simulations/1').status
-
-
-def test_get_simulation_no_authorizations(client, mocker):
- mocker.patch.object(DB, 'fetch_one', return_value={'authorizations': []})
- res = client.get('/api/v2/simulations/1')
- assert '403' in res.status
-
-
-def test_get_simulation_not_authorized(client, mocker):
- mocker.patch.object(DB,
- 'fetch_one',
- return_value={
- '_id': '1',
- 'authorizations': [{
- 'simulationId': '2',
- 'authorizationLevel': 'OWN'
- }]
- })
- res = client.get('/api/v2/simulations/1')
- assert '403' in res.status
-
-
-def test_get_simulation(client, mocker):
- mocker.patch.object(DB,
- 'fetch_one',
- return_value={
- '_id': '1',
- 'authorizations': [{
- 'simulationId': '1',
- 'authorizationLevel': 'EDIT'
- }]
- })
- res = client.get('/api/v2/simulations/1')
- assert '200' in res.status
-
-
-def test_update_simulation_missing_parameter(client):
- assert '400' in client.put('/api/v2/simulations/1').status
-
-
-def test_update_simulation_non_existing(client, mocker):
- mocker.patch.object(DB, 'fetch_one', return_value=None)
- assert '404' in client.put('/api/v2/simulations/1', json={'simulation': {'name': 'S'}}).status
-
-
-def test_update_simulation_not_authorized(client, mocker):
- mocker.patch.object(DB,
- 'fetch_one',
- return_value={
- '_id': '1',
- 'authorizations': [{
- 'simulationId': '1',
- 'authorizationLevel': 'VIEW'
- }]
- })
- mocker.patch.object(DB, 'update', return_value={})
- assert '403' in client.put('/api/v2/simulations/1', json={'simulation': {'name': 'S'}}).status
-
-
-def test_update_simulation(client, mocker):
- mocker.patch.object(DB,
- 'fetch_one',
- return_value={
- '_id': '1',
- 'authorizations': [{
- 'simulationId': '1',
- 'authorizationLevel': 'OWN'
- }]
- })
- mocker.patch.object(DB, 'update', return_value={})
-
- res = client.put('/api/v2/simulations/1', json={'simulation': {'name': 'S'}})
- assert '200' in res.status
-
-
-def test_delete_simulation_non_existing(client, mocker):
- mocker.patch.object(DB, 'fetch_one', return_value=None)
- assert '404' in client.delete('/api/v2/simulations/1').status
-
-
-def test_delete_simulation_different_user(client, mocker):
- mocker.patch.object(DB, 'fetch_one', return_value={'_id': '1', 'googleId': 'other_test', 'authorizations': [{'simulationId': '1', 'authorizationLevel': 'VIEW'}], 'topologyIds': []})
- mocker.patch.object(DB, 'delete_one', return_value=None)
- assert '403' in client.delete('/api/v2/simulations/1').status
-
-
-def test_delete_simulation(client, mocker):
- mocker.patch.object(DB, 'fetch_one', return_value={'_id': '1', 'googleId': 'test', 'authorizations': [{'simulationId': '1', 'authorizationLevel': 'OWN'}], 'topologyIds': []})
- mocker.patch.object(DB, 'delete_one', return_value={'googleId': 'test'})
- res = client.delete('/api/v2/simulations/1')
- assert '200' in res.status
diff --git a/opendc/api/v2/simulations/simulationId/topologies/__init__.py b/opendc/api/v2/simulations/simulationId/topologies/__init__.py
deleted file mode 100644
index e69de29b..00000000
--- a/opendc/api/v2/simulations/simulationId/topologies/__init__.py
+++ /dev/null
diff --git a/opendc/api/v2/simulations/simulationId/topologies/endpoint.py b/opendc/api/v2/simulations/simulationId/topologies/endpoint.py
deleted file mode 100644
index ab7b7006..00000000
--- a/opendc/api/v2/simulations/simulationId/topologies/endpoint.py
+++ /dev/null
@@ -1,29 +0,0 @@
-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
-
-
-def POST(request):
- """Add a new Topology to the specified simulation and return it"""
-
- request.check_required_parameters(path={'simulationId': 'string'}, body={'topology': {'name': 'string'}})
-
- simulation = Simulation.from_id(request.params_path['simulationId'])
-
- simulation.check_exists()
- simulation.check_user_access(request.google_id, True)
-
- topology = Topology({'name': request.params_body['topology']['name']})
- topology.set_property('datetimeCreated', Database.datetime_to_string(datetime.now()))
- topology.set_property('datetimeLastEdited', Database.datetime_to_string(datetime.now()))
- topology.insert()
-
- simulation.obj['topologyIds'].append(topology.obj['_id'])
- simulation.set_property('datetimeLastEdited', Database.datetime_to_string(datetime.now()))
- simulation.update()
-
- return Response(200, 'Successfully inserted topology.', topology.obj)
diff --git a/opendc/api/v2/simulations/simulationId/topologies/test_endpoint.py b/opendc/api/v2/simulations/simulationId/topologies/test_endpoint.py
deleted file mode 100644
index 10b5e3c9..00000000
--- a/opendc/api/v2/simulations/simulationId/topologies/test_endpoint.py
+++ /dev/null
@@ -1,26 +0,0 @@
-from opendc.util.database import DB
-
-
-def test_add_topology_missing_parameter(client):
- assert '400' in client.post('/api/v2/simulations/1/topologies/').status
-
-
-def test_add_topology(client, mocker):
- mocker.patch.object(DB, 'fetch_one', return_value={'_id': '1', 'authorizations': [{'simulationId': '1', 'authorizationLevel': 'OWN'}], 'topologyIds': []})
- mocker.patch.object(DB,
- 'insert',
- return_value={
- '_id': '1',
- 'datetimeCreated': '000',
- 'datetimeEdit': '000',
- 'topologyIds': []
- })
- mocker.patch.object(DB, 'update', return_value={})
- res = client.post('/api/v2/simulations/1/topologies/', json={'topology': {'name': 'test simulation'}})
- assert 'datetimeCreated' in res.json['content']
- assert 'datetimeEdit' in res.json['content']
- assert 'topologyIds' in res.json['content']
- assert '200' in res.status
-
-def test_add_topology_no_authorizations(client, mocker):
- pass \ No newline at end of file
diff --git a/opendc/api/v2/simulations/test_endpoint.py b/opendc/api/v2/simulations/test_endpoint.py
deleted file mode 100644
index d23df74a..00000000
--- a/opendc/api/v2/simulations/test_endpoint.py
+++ /dev/null
@@ -1,23 +0,0 @@
-from opendc.util.database import DB
-
-
-def test_add_simulation_missing_parameter(client):
- assert '400' in client.post('/api/v2/simulations').status
-
-
-def test_add_simulation(client, mocker):
- mocker.patch.object(DB, 'fetch_one', return_value={'_id': '1', 'authorizations': []})
- mocker.patch.object(DB,
- 'insert',
- return_value={
- '_id': '1',
- 'datetimeCreated': '000',
- 'datetimeEdit': '000',
- 'topologyIds': []
- })
- mocker.patch.object(DB, 'update', return_value={})
- res = client.post('/api/v2/simulations', json={'simulation': {'name': 'test simulation'}})
- assert 'datetimeCreated' in res.json['content']
- assert 'datetimeEdit' in res.json['content']
- assert 'topologyIds' in res.json['content']
- assert '200' in res.status
diff --git a/opendc/api/v2/topologies/__init__.py b/opendc/api/v2/topologies/__init__.py
deleted file mode 100644
index e69de29b..00000000
--- a/opendc/api/v2/topologies/__init__.py
+++ /dev/null
diff --git a/opendc/api/v2/topologies/topologyId/__init__.py b/opendc/api/v2/topologies/topologyId/__init__.py
deleted file mode 100644
index e69de29b..00000000
--- a/opendc/api/v2/topologies/topologyId/__init__.py
+++ /dev/null
diff --git a/opendc/api/v2/topologies/topologyId/endpoint.py b/opendc/api/v2/topologies/topologyId/endpoint.py
deleted file mode 100644
index 6c6ab9c2..00000000
--- a/opendc/api/v2/topologies/topologyId/endpoint.py
+++ /dev/null
@@ -1,16 +0,0 @@
-from opendc.models.topology import Topology
-from opendc.util import exceptions
-from opendc.util.rest import Response
-
-
-def GET(request):
- """Get this Topology."""
-
- request.check_required_parameters(path={'topologyId': 'int'})
-
- topology = Topology.from_id(request.params_path['topologyId'])
-
- topology.check_exists()
- topology.check_user_access(request.google_id, False)
-
- return Response(200, 'Successfully retrieved topology.', topology.obj)
diff --git a/opendc/api/v2/topologies/topologyId/rooms/__init__.py b/opendc/api/v2/topologies/topologyId/rooms/__init__.py
deleted file mode 100644
index e69de29b..00000000
--- a/opendc/api/v2/topologies/topologyId/rooms/__init__.py
+++ /dev/null
diff --git a/opendc/api/v2/topologies/topologyId/rooms/endpoint.py b/opendc/api/v2/topologies/topologyId/rooms/endpoint.py
deleted file mode 100644
index 96ee7028..00000000
--- a/opendc/api/v2/topologies/topologyId/rooms/endpoint.py
+++ /dev/null
@@ -1,93 +0,0 @@
-from opendc.models_old.datacenter import Datacenter
-from opendc.models_old.room import Room
-from opendc.util import exceptions
-from opendc.util.rest import Response
-
-
-def GET(request):
- """Get this Datacenter's Rooms."""
-
- # Make sure required parameters are there
-
- try:
- request.check_required_parameters(path={'datacenterId': 'int'})
- except exceptions.ParameterError as e:
- return Response(400, str(e))
-
- # Instantiate a Datacenter from the database
-
- datacenter = Datacenter.from_primary_key((request.params_path['datacenterId'], ))
-
- # Make sure this Datacenter exists
-
- if not datacenter.exists():
- return Response(404, '{} not found.'.format(datacenter))
-
- # Make sure this user is authorized to view this Datacenter's Rooms
-
- if not datacenter.google_id_has_at_least(request.google_id, 'VIEW'):
- return Response(403, 'Forbidden from viewing Rooms for {}.'.format(datacenter))
-
- # Get and return the Rooms
-
- rooms = Room.query('datacenter_id', datacenter.id)
-
- return Response(200, 'Successfully retrieved Rooms for {}.'.format(datacenter), [x.to_JSON() for x in rooms])
-
-
-def POST(request):
- """Add a Room."""
-
- # Make sure required parameters are there
-
- try:
- request.check_required_parameters(path={'datacenterId': 'int'},
- body={'room': {
- 'id': 'int',
- 'datacenterId': 'int',
- 'roomType': 'string'
- }})
- except exceptions.ParameterError as e:
- return Response(400, str(e))
-
- # Make sure the passed object's datacenter id matches the path datacenter id
-
- if request.params_path['datacenterId'] != request.params_body['room']['datacenterId']:
- return Response(400, 'ID mismatch.')
-
- # Instantiate a Datacenter from the database
-
- datacenter = Datacenter.from_primary_key((request.params_path['datacenterId'], ))
-
- # Make sure this Datacenter exists
-
- if not datacenter.exists():
- return Response(404, '{} not found.'.format(datacenter))
-
- # Make sure this user is authorized to edit this Datacenter's Rooms
-
- if not datacenter.google_id_has_at_least(request.google_id, 'EDIT'):
- return Response(403, 'Forbidden from adding a Room to {}.'.format(datacenter))
-
- # Add a name if not provided
-
- if 'name' not in request.params_body['room']:
- room_count = len(Room.query('datacenter_id', datacenter.id))
- request.params_body['room']['name'] = 'Room {}'.format(room_count)
-
- # Instantiate a Room
-
- room = Room.from_JSON(request.params_body['room'])
-
- # Try to insert this Room
-
- try:
- room.insert()
- except:
- return Response(400, 'Invalid `roomType` or existing `name`.')
-
- # Return this Room
-
- room.read()
-
- return Response(200, 'Successfully added {}.'.format(room), room.to_JSON())
diff --git a/opendc/api/v2/topologies/topologyId/test_endpoint.py b/opendc/api/v2/topologies/topologyId/test_endpoint.py
deleted file mode 100644
index e54052aa..00000000
--- a/opendc/api/v2/topologies/topologyId/test_endpoint.py
+++ /dev/null
@@ -1,46 +0,0 @@
-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}
-''' \ No newline at end of file
diff --git a/opendc/api/v2/traces/__init__.py b/opendc/api/v2/traces/__init__.py
deleted file mode 100644
index e69de29b..00000000
--- a/opendc/api/v2/traces/__init__.py
+++ /dev/null
diff --git a/opendc/api/v2/traces/endpoint.py b/opendc/api/v2/traces/endpoint.py
deleted file mode 100644
index 58cc6153..00000000
--- a/opendc/api/v2/traces/endpoint.py
+++ /dev/null
@@ -1,14 +0,0 @@
-from opendc.models_old.trace import Trace
-from opendc.util.rest import Response
-
-
-def GET(request):
- """Get all available Traces."""
-
- # Get the Traces
-
- traces = Trace.query()
-
- # Return the Traces
-
- return Response(200, 'Successfully retrieved Traces', [x.to_JSON() for x in traces])
diff --git a/opendc/api/v2/traces/traceId/__init__.py b/opendc/api/v2/traces/traceId/__init__.py
deleted file mode 100644
index e69de29b..00000000
--- a/opendc/api/v2/traces/traceId/__init__.py
+++ /dev/null
diff --git a/opendc/api/v2/traces/traceId/endpoint.py b/opendc/api/v2/traces/traceId/endpoint.py
deleted file mode 100644
index f6442a31..00000000
--- a/opendc/api/v2/traces/traceId/endpoint.py
+++ /dev/null
@@ -1,26 +0,0 @@
-from opendc.models_old.trace import Trace
-from opendc.util import exceptions
-from opendc.util.rest import Response
-
-
-def GET(request):
- """Get this Trace."""
-
- # Make sure required parameters are there
-
- try:
- request.check_required_parameters(path={'traceId': 'int'})
-
- except exceptions.ParameterError as e:
- return Response(400, str(e))
-
- # Instantiate a Trace and make sure it exists
-
- trace = Trace.from_primary_key((request.params_path['traceId'], ))
-
- if not trace.exists():
- return Response(404, '{} not found.'.format(trace))
-
- # Return this Trace
-
- return Response(200, 'Successfully retrieved {}.'.format(trace), trace.to_JSON())
diff --git a/opendc/api/v2/users/__init__.py b/opendc/api/v2/users/__init__.py
deleted file mode 100644
index e69de29b..00000000
--- a/opendc/api/v2/users/__init__.py
+++ /dev/null
diff --git a/opendc/api/v2/users/endpoint.py b/opendc/api/v2/users/endpoint.py
deleted file mode 100644
index c6041756..00000000
--- a/opendc/api/v2/users/endpoint.py
+++ /dev/null
@@ -1,31 +0,0 @@
-from opendc.models.user import User
-from opendc.util import exceptions
-from opendc.util.database import DB
-from opendc.util.rest import Response
-
-
-def GET(request):
- """Search for a User using their email address."""
-
- request.check_required_parameters(query={'email': 'string'})
-
- user = User.from_email(request.params_query['email'])
-
- user.check_exists()
-
- return Response(200, f'Successfully retrieved user.', user.obj)
-
-
-def POST(request):
- """Add a new User."""
-
- request.check_required_parameters(body={'user': {'email': 'string'}})
-
- user = User(request.params_body['user'])
- user.set_property('googleId', request.google_id)
- user.set_property('authorizations', [])
-
- user.check_already_exists()
-
- user.insert()
- return Response(200, f'Successfully created user.', user.obj)
diff --git a/opendc/api/v2/users/test_endpoint.py b/opendc/api/v2/users/test_endpoint.py
deleted file mode 100644
index d60429b3..00000000
--- a/opendc/api/v2/users/test_endpoint.py
+++ /dev/null
@@ -1,34 +0,0 @@
-from opendc.util.database import DB
-
-
-def test_get_user_by_email_missing_parameter(client):
- assert '400' in client.get('/api/v2/users').status
-
-
-def test_get_user_by_email_non_existing(client, mocker):
- mocker.patch.object(DB, 'fetch_one', return_value=None)
- assert '404' in client.get('/api/v2/users?email=test@test.com').status
-
-
-def test_get_user_by_email(client, mocker):
- mocker.patch.object(DB, 'fetch_one', return_value={'email': 'test@test.com'})
- res = client.get('/api/v2/users?email=test@test.com')
- assert 'email' in res.json['content']
- assert '200' in res.status
-
-
-def test_add_user_missing_parameter(client):
- assert '400' in client.post('/api/v2/users').status
-
-
-def test_add_user_existing(client, mocker):
- mocker.patch.object(DB, 'fetch_one', return_value={'email': 'test@test.com'})
- assert '409' in client.post('/api/v2/users', json={'user': {'email': 'test@test.com'}}).status
-
-
-def test_add_user(client, mocker):
- mocker.patch.object(DB, 'fetch_one', return_value=None)
- mocker.patch.object(DB, 'insert', return_value={'email': 'test@test.com'})
- res = client.post('/api/v2/users', json={'user': {'email': 'test@test.com'}})
- assert 'email' in res.json['content']
- assert '200' in res.status
diff --git a/opendc/api/v2/users/userId/__init__.py b/opendc/api/v2/users/userId/__init__.py
deleted file mode 100644
index e69de29b..00000000
--- a/opendc/api/v2/users/userId/__init__.py
+++ /dev/null
diff --git a/opendc/api/v2/users/userId/endpoint.py b/opendc/api/v2/users/userId/endpoint.py
deleted file mode 100644
index e68a2bb3..00000000
--- a/opendc/api/v2/users/userId/endpoint.py
+++ /dev/null
@@ -1,52 +0,0 @@
-from opendc.models.user import User
-from opendc.util import exceptions
-from opendc.util.rest import Response
-
-
-def GET(request):
- """Get this User."""
-
- request.check_required_parameters(path={'userId': 'string'})
-
- user = User.from_id(request.params_path['userId'])
-
- user.check_exists()
-
- return Response(200, f'Successfully retrieved user.', user.obj)
-
-
-def PUT(request):
- """Update this User's given name and/or family name."""
-
- request.check_required_parameters(body={'user': {
- 'givenName': 'string',
- 'familyName': 'string'
- }},
- path={'userId': 'string'})
-
- user = User.from_id(request.params_path['userId'])
-
- user.check_exists()
- user.check_correct_user(request.google_id)
-
- user.set_property('givenName', request.params_body['user']['givenName'])
- user.set_property('familyName', request.params_body['user']['familyName'])
-
- user.update()
-
- return Response(200, f'Successfully updated user.', user.obj)
-
-
-def DELETE(request):
- """Delete this User."""
-
- request.check_required_parameters(path={'userId': 'string'})
-
- user = User.from_id(request.params_path['userId'])
-
- user.check_exists()
- user.check_correct_user(request.google_id)
-
- user.delete()
-
- return Response(200, f'Successfully deleted user.', user.obj)
diff --git a/opendc/api/v2/users/userId/test_endpoint.py b/opendc/api/v2/users/userId/test_endpoint.py
deleted file mode 100644
index 0d590129..00000000
--- a/opendc/api/v2/users/userId/test_endpoint.py
+++ /dev/null
@@ -1,53 +0,0 @@
-from opendc.util.database import DB
-
-
-def test_get_user_non_existing(client, mocker):
- mocker.patch.object(DB, 'fetch_one', return_value=None)
- assert '404' in client.get('/api/v2/users/1').status
-
-
-def test_get_user(client, mocker):
- mocker.patch.object(DB, 'fetch_one', return_value={'email': 'test@test.com'})
- res = client.get('/api/v2/users/1')
- assert 'email' in res.json['content']
- assert '200' in res.status
-
-
-def test_update_user_missing_parameter(client):
- assert '400' in client.put('/api/v2/users/1').status
-
-
-def test_update_user_non_existing(client, mocker):
- mocker.patch.object(DB, 'fetch_one', return_value=None)
- assert '404' in client.put('/api/v2/users/1', json={'user': {'givenName': 'A', 'familyName': 'B'}}).status
-
-
-def test_update_user_different_user(client, mocker):
- mocker.patch.object(DB, 'fetch_one', return_value={'_id': '1', 'googleId': 'other_test'})
- assert '403' in client.put('/api/v2/users/1', json={'user': {'givenName': 'A', 'familyName': 'B'}}).status
-
-
-def test_update_user(client, mocker):
- mocker.patch.object(DB, 'fetch_one', return_value={'_id': '1', 'googleId': 'test'})
- mocker.patch.object(DB, 'update', return_value={'givenName': 'A', 'familyName': 'B'})
- res = client.put('/api/v2/users/1', json={'user': {'givenName': 'A', 'familyName': 'B'}})
- assert 'givenName' in res.json['content']
- assert '200' in res.status
-
-
-def test_delete_user_non_existing(client, mocker):
- mocker.patch.object(DB, 'fetch_one', return_value=None)
- assert '404' in client.delete('/api/v2/users/1').status
-
-
-def test_delete_user_different_user(client, mocker):
- mocker.patch.object(DB, 'fetch_one', return_value={'_id': '1', 'googleId': 'other_test'})
- assert '403' in client.delete('/api/v2/users/1').status
-
-
-def test_delete_user(client, mocker):
- mocker.patch.object(DB, 'fetch_one', return_value={'_id': '1', 'googleId': 'test'})
- mocker.patch.object(DB, 'delete_one', return_value={'googleId': 'test'})
- res = client.delete('/api/v2/users/1')
- assert 'googleId' in res.json['content']
- assert '200' in res.status