diff options
| author | Georgios Andreadis <info@gandreadis.com> | 2020-06-25 17:11:03 +0200 |
|---|---|---|
| committer | Georgios Andreadis <info@gandreadis.com> | 2020-06-25 17:11:03 +0200 |
| commit | c0bf71322e4fd510046588e388ada0a81f54631d (patch) | |
| tree | 7f0af5b0657558a4730b62298534cd6a1d829765 /opendc/api | |
| parent | cae7ee8ab4639963d3da7fef6f078a6078340a0b (diff) | |
Implement and test path
Diffstat (limited to 'opendc/api')
47 files changed, 34 insertions, 630 deletions
diff --git a/opendc/api/v2/jobs/__init__.py b/opendc/api/v2/jobs/__init__.py deleted file mode 100644 index e69de29b..00000000 --- a/opendc/api/v2/jobs/__init__.py +++ /dev/null diff --git a/opendc/api/v2/jobs/jobId/__init__.py b/opendc/api/v2/jobs/jobId/__init__.py deleted file mode 100644 index e69de29b..00000000 --- a/opendc/api/v2/jobs/jobId/__init__.py +++ /dev/null diff --git a/opendc/api/v2/jobs/jobId/endpoint.py b/opendc/api/v2/jobs/jobId/endpoint.py deleted file mode 100644 index 45eedf3f..00000000 --- a/opendc/api/v2/jobs/jobId/endpoint.py +++ /dev/null @@ -1,26 +0,0 @@ -from opendc.models_old.job import Job -from opendc.util import exceptions -from opendc.util.rest import Response - - -def GET(request): - """Get this Job.""" - - # Make sure required parameters are there - - try: - request.check_required_parameters(path={'jobId': 'int'}) - - except exceptions.ParameterError as e: - return Response(400, str(e)) - - # Instantiate a Job and make sure it exists - - job = Job.from_primary_key((request.params_path['jobId'], )) - - if not job.exists(): - return Response(404, '{} not found.'.format(job)) - - # Return this Job - - return Response(200, 'Successfully retrieved {}.'.format(job), job.to_JSON()) diff --git a/opendc/api/v2/jobs/jobId/tasks/__init__.py b/opendc/api/v2/jobs/jobId/tasks/__init__.py deleted file mode 100644 index e69de29b..00000000 --- a/opendc/api/v2/jobs/jobId/tasks/__init__.py +++ /dev/null diff --git a/opendc/api/v2/jobs/jobId/tasks/endpoint.py b/opendc/api/v2/jobs/jobId/tasks/endpoint.py deleted file mode 100644 index cae5ac90..00000000 --- a/opendc/api/v2/jobs/jobId/tasks/endpoint.py +++ /dev/null @@ -1,29 +0,0 @@ -from opendc.models_old.job import Job -from opendc.models_old.task import Task -from opendc.util import exceptions -from opendc.util.rest import Response - - -def GET(request): - """Get this Job's Tasks.""" - - # Make sure required parameters are there - - try: - request.check_required_parameters(path={'jobId': 'int'}) - - except exceptions.ParameterError as e: - return Response(400, str(e)) - - # Instantiate a Job and make sure it exists - - job = Job.from_primary_key((request.params_path['jobId'], )) - - if not job.exists(): - return Response(404, '{} not found.'.format(job)) - - # Get and return the Tasks - - tasks = Task.query('job_id', request.params_path['jobId']) - - return Response(200, 'Successfully retrieved Tasks for {}.'.format(job), [x.to_JSON() for x in tasks]) diff --git a/opendc/api/v2/paths/__init__.py b/opendc/api/v2/paths/__init__.py deleted file mode 100644 index e69de29b..00000000 --- a/opendc/api/v2/paths/__init__.py +++ /dev/null diff --git a/opendc/api/v2/paths/pathId/__init__.py b/opendc/api/v2/paths/pathId/__init__.py deleted file mode 100644 index e69de29b..00000000 --- a/opendc/api/v2/paths/pathId/__init__.py +++ /dev/null diff --git a/opendc/api/v2/paths/pathId/branches/__init__.py b/opendc/api/v2/paths/pathId/branches/__init__.py deleted file mode 100644 index e69de29b..00000000 --- a/opendc/api/v2/paths/pathId/branches/__init__.py +++ /dev/null diff --git a/opendc/api/v2/paths/pathId/branches/endpoint.py b/opendc/api/v2/paths/pathId/branches/endpoint.py deleted file mode 100644 index 6b0eebbd..00000000 --- a/opendc/api/v2/paths/pathId/branches/endpoint.py +++ /dev/null @@ -1,155 +0,0 @@ -from datetime import datetime - -from opendc.models_old.datacenter import Datacenter -from opendc.models_old.machine import Machine -from opendc.models_old.object import Object -from opendc.models_old.path import Path -from opendc.models_old.rack import Rack -from opendc.models_old.room import Room -from opendc.models_old.section import Section -from opendc.models_old.tile import Tile -from opendc.util import database, exceptions -from opendc.util.rest import Request, Response - - -def POST(request): - """Create a new Path that branches off of this Path at the specified tick.""" - - # Make sure required parameters are there - - try: - request.check_required_parameters(path={'pathId': 'int'}, body={'section': {'startTick': 'int'}}) - - except exceptions.ParameterError as e: - return Response(400, str(e)) - - # Instantiate the current Path from the database - - current_path = Path.from_primary_key((request.params_path['pathId'], )) - - # Make sure the current Path exists - - if not current_path.exists(): - return Response(404, '{} not found.'.format(current_path)) - - # Make sure this user is authorized to branch off the current Path - - if not current_path.google_id_has_at_least(request.google_id, 'EDIT'): - return Response(403, 'Forbidden from branching off {}.'.format(current_path)) - - # Create the new Path - - new_path = Path(simulation_id=current_path.simulation_id, - datetime_created=database.datetime_to_string(datetime.now())) - - new_path.insert() - - # Get the current Path's sections and add them to the new Path if they're before the branch - - current_sections = Section.query('path_id', current_path.id) - last_section = None - - for current_section in current_sections: - - if current_section.start_tick < request.params_body['section']['startTick'] or current_section.start_tick == 0: - new_section = Section(path_id=new_path.id, - datacenter_id=current_section.datacenter_id, - start_tick=current_section.start_tick) - - new_section.insert() - - last_section = current_section - - # Make a deep copy of the last section's datacenter, its rooms, their tiles, etc. - - path_parameters = {'simulationId': new_path.simulation_id} - - # Copy the Datacenter - - old_datacenter = Datacenter.from_primary_key((last_section.datacenter_id, )) - - message = old_datacenter.generate_api_call(path_parameters, request.token) - response = Request(message).process() - - path_parameters['datacenterId'] = response.content['id'] - - # Create the new last Section, with the IDs of the new Path and new Datacenter - - if last_section.start_tick != 0: - new_section = Section(path_id=new_path.id, - datacenter_id=path_parameters['datacenterId'], - start_tick=request.params_body['section']['startTick']) - - new_section.insert() - - else: - last_section.datacenter_id = path_parameters['datacenterId'] - last_section.update() - - # Copy the rest of the Datacenter, starting with the Rooms... - - old_rooms = Room.query('datacenter_id', old_datacenter.id) - - for old_room in old_rooms: - - old_room.datacenter_id = path_parameters['datacenterId'] - - if old_room.topology_id is None: - old_room.topology_id = old_room.id - - message = old_room.generate_api_call(path_parameters, request.token) - response = Request(message).process() - - path_parameters['roomId'] = response.content['id'] - - # ... then the Tiles, ... - - old_tiles = Tile.query('room_id', old_room.id) - - for old_tile in old_tiles: - - old_tile.room_id = path_parameters['roomId'] - - if old_tile.topology_id is None: - old_tile.topology_id = old_tile.id - - message = old_tile.generate_api_call(path_parameters, request.token) - response = Request(message).process() - - path_parameters['tileId'] = response.content['id'] - - old_objects = Object.query('id', old_tile.object_id) - - # ... then the Tile's Rack, ... - - if len(old_objects) == 1 and old_objects[0].type == 'RACK': - - old_rack = Rack.query('id', old_objects[0].id)[0] - - if old_rack.topology_id is None: - old_rack.topology_id = old_rack.id - - message = old_rack.generate_api_call(path_parameters, request.token) - response = Request(message).process() - - path_parameters['rackId'] = response.content['id'] - - # ... then the Rack's Machines ... - - old_machines = Machine.query('rack_id', old_rack.id) - - for old_machine in old_machines: - old_machine.read() - old_machine.rack_id = path_parameters['rackId'] - - if old_machine.topology_id is None: - old_machine.topology_id = old_machine.id - - message = old_machine.generate_api_call(path_parameters, request.token) - response = Request(message).process() - - path_parameters['machineId'] = response.content['id'] - - # Return the new Path - - return Response(200, 'Successfully created {}.'.format(new_path), new_path.to_JSON()) diff --git a/opendc/api/v2/paths/pathId/endpoint.py b/opendc/api/v2/paths/pathId/endpoint.py deleted file mode 100644 index a3348618..00000000 --- a/opendc/api/v2/paths/pathId/endpoint.py +++ /dev/null @@ -1,35 +0,0 @@ -from opendc.models_old.path import Path -from opendc.util import exceptions -from opendc.util.rest import Response - - -def GET(request): - """Get this Path.""" - - # Make sure required parameters are there - - try: - request.check_required_parameters(path={'pathId': 'int'}) - - except exceptions.ParameterError as e: - return Response(400, str(e)) - - # Instantiate a Path from the database - - path = Path.from_primary_key((request.params_path['pathId'], )) - - # Make sure this Path exists - - if not path.exists(): - return Response(404, '{} not found.'.format(path)) - - # Make sure this user is authorized to view this Path - - if not path.google_id_has_at_least(request.google_id, 'VIEW'): - return Response(403, 'Forbidden from retrieving {}.'.format(path)) - - # Return this Path - - path.read() - - return Response(200, 'Successfully retrieved {}.'.format(path), path.to_JSON()) diff --git a/opendc/api/v2/paths/pathId/sections/__init__.py b/opendc/api/v2/paths/pathId/sections/__init__.py deleted file mode 100644 index e69de29b..00000000 --- a/opendc/api/v2/paths/pathId/sections/__init__.py +++ /dev/null diff --git a/opendc/api/v2/paths/pathId/sections/endpoint.py b/opendc/api/v2/paths/pathId/sections/endpoint.py deleted file mode 100644 index 8f3e270b..00000000 --- a/opendc/api/v2/paths/pathId/sections/endpoint.py +++ /dev/null @@ -1,35 +0,0 @@ -from opendc.models_old.path import Path -from opendc.models_old.section import Section -from opendc.util import exceptions -from opendc.util.rest import Response - - -def GET(request): - """Get this Path's Sections.""" - - # Make sure required parameters are there - - try: - request.check_required_parameters(path={'pathId': 'int'}) - except exceptions.ParameterError as e: - return Response(400, str(e)) - - # Instantiate a Path from the database - - path = Path.from_primary_key((request.params_path['pathId'], )) - - # Make sure this Path exists - - if not path.exists(): - return Response(404, '{} not found.'.format(path)) - - # Make sure this user is authorized to view this Path's Sections - - if not path.google_id_has_at_least(request.google_id, 'VIEW'): - return Response(403, 'Forbidden from viewing Sections for {}.'.format(path)) - - # Get and return the Sections - - sections = Section.query('path_id', request.params_path['pathId']) - - return Response(200, 'Successfully retrieved Sections for {}.'.format(path), [x.to_JSON() for x in sections]) diff --git a/opendc/api/v2/room-types/__init__.py b/opendc/api/v2/room-types/__init__.py deleted file mode 100644 index e69de29b..00000000 --- a/opendc/api/v2/room-types/__init__.py +++ /dev/null diff --git a/opendc/api/v2/room-types/endpoint.py b/opendc/api/v2/room-types/endpoint.py deleted file mode 100644 index 71efc75d..00000000 --- a/opendc/api/v2/room-types/endpoint.py +++ /dev/null @@ -1,14 +0,0 @@ -from opendc.models_old.room_type import RoomType -from opendc.util.rest import Response - - -def GET(request): - """Get all available room types.""" - - # Get the RoomTypes - - room_types = RoomType.query() - - # Return the RoomTypes - - return Response(200, 'Successfully retrieved RoomTypes.', [x.to_JSON() for x in room_types]) diff --git a/opendc/api/v2/room-types/name/__init__.py b/opendc/api/v2/room-types/name/__init__.py deleted file mode 100644 index e69de29b..00000000 --- a/opendc/api/v2/room-types/name/__init__.py +++ /dev/null diff --git a/opendc/api/v2/room-types/name/allowed-objects/__init__.py b/opendc/api/v2/room-types/name/allowed-objects/__init__.py deleted file mode 100644 index e69de29b..00000000 --- a/opendc/api/v2/room-types/name/allowed-objects/__init__.py +++ /dev/null diff --git a/opendc/api/v2/room-types/name/allowed-objects/endpoint.py b/opendc/api/v2/room-types/name/allowed-objects/endpoint.py deleted file mode 100644 index 7b605c2b..00000000 --- a/opendc/api/v2/room-types/name/allowed-objects/endpoint.py +++ /dev/null @@ -1,23 +0,0 @@ -from opendc.models_old.allowed_object import AllowedObject -from opendc.util import exceptions -from opendc.util.rest import Response - - -def GET(request): - """Get this room's allowed objects.""" - - # Make sure required parameters are there - - try: - request.check_required_parameters(path={'name': 'string'}) - - except exceptions.ParameterError as e: - return Response(400, str(e)) - - # Get the AllowedObjects - - allowed_objects = AllowedObject.query('room_type', request.params_path['name']) - - # Return the AllowedObjects - - return Response(200, 'Successfully retrieved AllowedObjects.', [x.to_JSON() for x in allowed_objects]) diff --git a/opendc/api/v2/sections/__init__.py b/opendc/api/v2/sections/__init__.py deleted file mode 100644 index e69de29b..00000000 --- a/opendc/api/v2/sections/__init__.py +++ /dev/null diff --git a/opendc/api/v2/sections/sectionId/__init__.py b/opendc/api/v2/sections/sectionId/__init__.py deleted file mode 100644 index e69de29b..00000000 --- a/opendc/api/v2/sections/sectionId/__init__.py +++ /dev/null diff --git a/opendc/api/v2/sections/sectionId/endpoint.py b/opendc/api/v2/sections/sectionId/endpoint.py deleted file mode 100644 index 58af44b5..00000000 --- a/opendc/api/v2/sections/sectionId/endpoint.py +++ /dev/null @@ -1,34 +0,0 @@ -from opendc.models_old.section import Section -from opendc.util import exceptions -from opendc.util.rest import Response - - -def GET(request): - """Get this Path's Sections.""" - - # Make sure required parameters are there - - try: - request.check_required_parameters(path={'sectionId': 'int'}) - except exceptions.ParameterError as e: - return Response(400, str(e)) - - # Instantiate a Section from the database - - section = Section.from_primary_key((request.params_path['sectionId'], )) - - # Make sure this Section exists - - if not section.exists(): - return Response(404, '{} not found.'.format(section)) - - # Make sure this user is authorized to view this Section - - if not section.google_id_has_at_least(request.google_id, 'VIEW'): - return Response(403, 'Forbidden from viewing {}.'.format(section)) - - # Return the Section - - section.read() - - return Response(200, 'Successfully retrieved {}.'.format(section), section.to_JSON()) diff --git a/opendc/api/v2/simulations/endpoint.py b/opendc/api/v2/simulations/endpoint.py index 7ef90e97..dfeb8d5e 100644 --- a/opendc/api/v2/simulations/endpoint.py +++ b/opendc/api/v2/simulations/endpoint.py @@ -1,65 +1,32 @@ from datetime import datetime -from opendc.models_old.authorization import Authorization -from opendc.models_old.datacenter import Datacenter -from opendc.models_old.path import Path -from opendc.models_old.section import Section -from opendc.models_old.simulation import Simulation -from opendc.models_old.user import User -from opendc.util import database, exceptions +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.""" - # Make sure required parameters are there - try: request.check_required_parameters(body={'simulation': {'name': 'string'}}) - except exceptions.ParameterError as e: return Response(400, str(e)) - # Instantiate a Simulation - - simulation_data = request.params_body['simulation'] - - simulation_data['datetimeCreated'] = database.datetime_to_string(datetime.now()) - simulation_data['datetimeLastEdited'] = database.datetime_to_string(datetime.now()) - - simulation = Simulation.from_JSON(simulation_data) - - # Insert this Simulation into the database + 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.insert() - # Instantiate an Authorization and insert it into the database - - authorization = Authorization(user_id=User.from_google_id(request.google_id).id, - simulation_id=simulation.id, - authorization_level='OWN') - - authorization.insert() - - # Instantiate a Path and insert it into the database - - path = Path(simulation_id=simulation.id, datetime_created=database.datetime_to_string(datetime.now())) - - path.insert() - - # Instantiate a Datacenter and insert it into the database - - datacenter = Datacenter(starred=0, simulation_id=simulation.id) - - datacenter.insert() - - # Instantiate a Section and insert it into the database - - section = Section(path_id=path.id, datacenter_id=datacenter.id, start_tick=0) - - section.insert() - - # Return this Simulation + 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 {}.'.format(simulation), simulation.to_JSON()) + return Response(200, 'Successfully created simulation.', simulation.obj) diff --git a/opendc/api/v2/simulations/test_endpoint.py b/opendc/api/v2/simulations/test_endpoint.py new file mode 100644 index 00000000..fe4ac6ed --- /dev/null +++ b/opendc/api/v2/simulations/test_endpoint.py @@ -0,0 +1,16 @@ +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/specifications/__init__.py b/opendc/api/v2/specifications/__init__.py deleted file mode 100644 index e69de29b..00000000 --- a/opendc/api/v2/specifications/__init__.py +++ /dev/null diff --git a/opendc/api/v2/specifications/cpus/__init__.py b/opendc/api/v2/specifications/cpus/__init__.py deleted file mode 100644 index e69de29b..00000000 --- a/opendc/api/v2/specifications/cpus/__init__.py +++ /dev/null diff --git a/opendc/api/v2/specifications/cpus/endpoint.py b/opendc/api/v2/specifications/cpus/endpoint.py deleted file mode 100644 index b2ec36f4..00000000 --- a/opendc/api/v2/specifications/cpus/endpoint.py +++ /dev/null @@ -1,14 +0,0 @@ -from opendc.models_old.cpu import CPU -from opendc.util.rest import Response - - -def GET(request): - """Get a list of the specifications of all CPUs.""" - - # Get the CPUs - - cpus = CPU.query() - - # Return the CPUs - - return Response(200, 'Successfully retrieved CPUs.', [x.to_JSON() for x in cpus]) diff --git a/opendc/api/v2/specifications/cpus/id/__init__.py b/opendc/api/v2/specifications/cpus/id/__init__.py deleted file mode 100644 index e69de29b..00000000 --- a/opendc/api/v2/specifications/cpus/id/__init__.py +++ /dev/null diff --git a/opendc/api/v2/specifications/cpus/id/endpoint.py b/opendc/api/v2/specifications/cpus/id/endpoint.py deleted file mode 100644 index 83cda92d..00000000 --- a/opendc/api/v2/specifications/cpus/id/endpoint.py +++ /dev/null @@ -1,26 +0,0 @@ -from opendc.models_old.cpu import CPU -from opendc.util import exceptions -from opendc.util.rest import Response - - -def GET(request): - """Get the specs of a CPU.""" - - # Make sure required parameters are there - - try: - request.check_required_parameters(path={'id': 'int'}) - - except exceptions.ParameterError as e: - return Response(400, str(e)) - - # Instantiate a CPU and make sure it exists - - cpu = CPU.from_primary_key((request.params_path['id'], )) - - if not cpu.exists(): - return Response(404, '{} not found.'.format(cpu)) - - # Return this CPU - - return Response(200, 'Successfully retrieved {}.'.format(cpu), cpu.to_JSON()) diff --git a/opendc/api/v2/specifications/failure-models/__init__.py b/opendc/api/v2/specifications/failure-models/__init__.py deleted file mode 100644 index e69de29b..00000000 --- a/opendc/api/v2/specifications/failure-models/__init__.py +++ /dev/null diff --git a/opendc/api/v2/specifications/failure-models/endpoint.py b/opendc/api/v2/specifications/failure-models/endpoint.py deleted file mode 100644 index 63807ed2..00000000 --- a/opendc/api/v2/specifications/failure-models/endpoint.py +++ /dev/null @@ -1,14 +0,0 @@ -from opendc.models_old.failure_model import FailureModel -from opendc.util.rest import Response - - -def GET(request): - """Get all Failure Models.""" - - # Get the FailureModels - - failure_models = FailureModel.query() - - # Return the FailureModels - - return Response(200, 'Successfully retrieved FailureModels.', [x.to_JSON() for x in failure_models]) diff --git a/opendc/api/v2/specifications/failure-models/id/__init__.py b/opendc/api/v2/specifications/failure-models/id/__init__.py deleted file mode 100644 index e69de29b..00000000 --- a/opendc/api/v2/specifications/failure-models/id/__init__.py +++ /dev/null diff --git a/opendc/api/v2/specifications/failure-models/id/endpoint.py b/opendc/api/v2/specifications/failure-models/id/endpoint.py deleted file mode 100644 index bfba4f16..00000000 --- a/opendc/api/v2/specifications/failure-models/id/endpoint.py +++ /dev/null @@ -1,26 +0,0 @@ -from opendc.models_old.failure_model import FailureModel -from opendc.util import exceptions -from opendc.util.rest import Response - - -def GET(request): - """Get this Failure Model.""" - - # Make sure required parameters are there - - try: - request.check_required_parameters(path={'id': 'int'}) - - except exceptions.ParameterError as e: - return Response(400, str(e)) - - # Instantiate a FailureModel and make sure it exists - - failure_model = FailureModel.from_primary_key((request.params_path['id'], )) - - if not failure_model.exists(): - return Response(404, '{} not found.'.format(failure_model)) - - # Return this FailureModel - - return Response(200, 'Successfully retrieved {}.'.format(failure_model), failure_model.to_JSON()) diff --git a/opendc/api/v2/specifications/gpus/__init__.py b/opendc/api/v2/specifications/gpus/__init__.py deleted file mode 100644 index e69de29b..00000000 --- a/opendc/api/v2/specifications/gpus/__init__.py +++ /dev/null diff --git a/opendc/api/v2/specifications/gpus/endpoint.py b/opendc/api/v2/specifications/gpus/endpoint.py deleted file mode 100644 index d536ba47..00000000 --- a/opendc/api/v2/specifications/gpus/endpoint.py +++ /dev/null @@ -1,14 +0,0 @@ -from opendc.models_old.gpu import GPU -from opendc.util.rest import Response - - -def GET(request): - """Get a list of the specifications of all GPUs.""" - - # Get the GPUs - - gpus = GPU.query() - - # Return the GPUs - - return Response(200, 'Successfully retrieved GPUs.', [x.to_JSON() for x in gpus]) diff --git a/opendc/api/v2/specifications/gpus/id/__init__.py b/opendc/api/v2/specifications/gpus/id/__init__.py deleted file mode 100644 index e69de29b..00000000 --- a/opendc/api/v2/specifications/gpus/id/__init__.py +++ /dev/null diff --git a/opendc/api/v2/specifications/gpus/id/endpoint.py b/opendc/api/v2/specifications/gpus/id/endpoint.py deleted file mode 100644 index 9a0c0f75..00000000 --- a/opendc/api/v2/specifications/gpus/id/endpoint.py +++ /dev/null @@ -1,26 +0,0 @@ -from opendc.models_old.gpu import GPU -from opendc.util import exceptions -from opendc.util.rest import Response - - -def GET(request): - """Get the specs of a GPU.""" - - # Make sure required parameters are there - - try: - request.check_required_parameters(path={'id': 'int'}) - - except exceptions.ParameterError as e: - return Response(400, str(e)) - - # Instantiate a GPU and make sure it exists - - gpu = GPU.from_primary_key((request.params_path['id'], )) - - if not gpu.exists(): - return Response(404, '{} not found.'.format(gpu)) - - # Return this GPU - - return Response(200, 'Successfully retrieved {}.'.format(gpu), gpu.to_JSON()) diff --git a/opendc/api/v2/specifications/memories/__init__.py b/opendc/api/v2/specifications/memories/__init__.py deleted file mode 100644 index e69de29b..00000000 --- a/opendc/api/v2/specifications/memories/__init__.py +++ /dev/null diff --git a/opendc/api/v2/specifications/memories/endpoint.py b/opendc/api/v2/specifications/memories/endpoint.py deleted file mode 100644 index 7a8f6a7a..00000000 --- a/opendc/api/v2/specifications/memories/endpoint.py +++ /dev/null @@ -1,14 +0,0 @@ -from opendc.models_old.memory import Memory -from opendc.util.rest import Response - - -def GET(request): - """Get a list of the specifications of all Memories.""" - - # Get the Memories - - memories = Memory.query() - - # Return the Memories - - return Response(200, 'Successfully retrieved Memories.', [x.to_JSON() for x in memories]) diff --git a/opendc/api/v2/specifications/memories/id/__init__.py b/opendc/api/v2/specifications/memories/id/__init__.py deleted file mode 100644 index e69de29b..00000000 --- a/opendc/api/v2/specifications/memories/id/__init__.py +++ /dev/null diff --git a/opendc/api/v2/specifications/memories/id/endpoint.py b/opendc/api/v2/specifications/memories/id/endpoint.py deleted file mode 100644 index f8922833..00000000 --- a/opendc/api/v2/specifications/memories/id/endpoint.py +++ /dev/null @@ -1,26 +0,0 @@ -from opendc.models_old.memory import Memory -from opendc.util import exceptions -from opendc.util.rest import Response - - -def GET(request): - """Get the specs of a Memory.""" - - # Make sure required parameters are there - - try: - request.check_required_parameters(path={'id': 'int'}) - - except exceptions.ParameterError as e: - return Response(400, str(e)) - - # Instantiate a Memory and make sure it exists - - memory = Memory.from_primary_key((request.params_path['id'], )) - - if not memory.exists(): - return Response(404, '{} not found.'.format(memory)) - - # Return this Memory - - return Response(200, 'Successfully retrieved {}.'.format(memory), memory.to_JSON()) diff --git a/opendc/api/v2/specifications/storages/__init__.py b/opendc/api/v2/specifications/storages/__init__.py deleted file mode 100644 index e69de29b..00000000 --- a/opendc/api/v2/specifications/storages/__init__.py +++ /dev/null diff --git a/opendc/api/v2/specifications/storages/endpoint.py b/opendc/api/v2/specifications/storages/endpoint.py deleted file mode 100644 index 20b9b794..00000000 --- a/opendc/api/v2/specifications/storages/endpoint.py +++ /dev/null @@ -1,14 +0,0 @@ -from opendc.models_old.storage import Storage -from opendc.util.rest import Response - - -def GET(request): - """Get a list of the specifications of all Storages.""" - - # Get the Storages - - storages = Storage.query() - - # Return the Storages - - return Response(200, 'Successfully retrieved Storages.', [x.to_JSON() for x in storages]) diff --git a/opendc/api/v2/specifications/storages/id/__init__.py b/opendc/api/v2/specifications/storages/id/__init__.py deleted file mode 100644 index e69de29b..00000000 --- a/opendc/api/v2/specifications/storages/id/__init__.py +++ /dev/null diff --git a/opendc/api/v2/specifications/storages/id/endpoint.py b/opendc/api/v2/specifications/storages/id/endpoint.py deleted file mode 100644 index 39c20fef..00000000 --- a/opendc/api/v2/specifications/storages/id/endpoint.py +++ /dev/null @@ -1,26 +0,0 @@ -from opendc.models_old.storage import Storage -from opendc.util import exceptions -from opendc.util.rest import Response - - -def GET(request): - """Get the specs of a Storage.""" - - # Make sure required parameters are there - - try: - request.check_required_parameters(path={'id': 'int'}) - - except exceptions.ParameterError as e: - return Response(400, str(e)) - - # Instantiate a Storage and make sure it exists - - storage = Storage.from_primary_key((request.params_path['id'], )) - - if not storage.exists(): - return Response(404, '{} not found.'.format(storage)) - - # Return this CPU - - return Response(200, 'Successfully retrieved {}.'.format(storage), storage.to_JSON()) diff --git a/opendc/api/v2/traces/traceId/jobs/__init__.py b/opendc/api/v2/traces/traceId/jobs/__init__.py deleted file mode 100644 index e69de29b..00000000 --- a/opendc/api/v2/traces/traceId/jobs/__init__.py +++ /dev/null diff --git a/opendc/api/v2/traces/traceId/jobs/endpoint.py b/opendc/api/v2/traces/traceId/jobs/endpoint.py deleted file mode 100644 index af681b70..00000000 --- a/opendc/api/v2/traces/traceId/jobs/endpoint.py +++ /dev/null @@ -1,29 +0,0 @@ -from opendc.models_old.job import Job -from opendc.models_old.trace import Trace -from opendc.util import exceptions -from opendc.util.rest import Response - - -def GET(request): - """Get this Trace's Jobs.""" - - # 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)) - - # Get and return the Jobs - - jobs = Job.query('trace_id', request.params_path['traceId']) - - return Response(200, 'Successfully retrieved Jobs for {}.'.format(trace), [x.to_JSON() for x in jobs]) diff --git a/opendc/api/v2/users/endpoint.py b/opendc/api/v2/users/endpoint.py index 89dfc8c1..b1a3675d 100644 --- a/opendc/api/v2/users/endpoint.py +++ b/opendc/api/v2/users/endpoint.py @@ -31,6 +31,7 @@ def POST(request): user = User(request.params_body['user']) user.set_property('googleId', request.google_id) + user.set_property('authorizations', []) validation_error = user.validate_insertion() if validation_error is not None: diff --git a/opendc/api/v2/users/userId/test_endpoint.py b/opendc/api/v2/users/userId/test_endpoint.py index 01642fc3..0d590129 100644 --- a/opendc/api/v2/users/userId/test_endpoint.py +++ b/opendc/api/v2/users/userId/test_endpoint.py @@ -29,7 +29,7 @@ def test_update_user_different_user(client, mocker): 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=None) + 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 @@ -47,7 +47,7 @@ def test_delete_user_different_user(client, mocker): 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=None) + 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 |
