diff options
Diffstat (limited to 'web-server/opendc/api/v2/portfolios/portfolioId/scenarios')
3 files changed, 0 insertions, 162 deletions
diff --git a/web-server/opendc/api/v2/portfolios/portfolioId/scenarios/__init__.py b/web-server/opendc/api/v2/portfolios/portfolioId/scenarios/__init__.py deleted file mode 100644 index e69de29b..00000000 --- a/web-server/opendc/api/v2/portfolios/portfolioId/scenarios/__init__.py +++ /dev/null diff --git a/web-server/opendc/api/v2/portfolios/portfolioId/scenarios/endpoint.py b/web-server/opendc/api/v2/portfolios/portfolioId/scenarios/endpoint.py deleted file mode 100644 index 1c5e0ab6..00000000 --- a/web-server/opendc/api/v2/portfolios/portfolioId/scenarios/endpoint.py +++ /dev/null @@ -1,43 +0,0 @@ -from opendc.models.portfolio import Portfolio -from opendc.models.scenario import Scenario -from opendc.util.rest import Response - - -def POST(request): - """Add a new Scenario for this Portfolio.""" - - request.check_required_parameters(path={'portfolioId': 'string'}, - body={ - 'scenario': { - 'name': 'string', - 'trace': { - 'traceId': 'string', - 'loadSamplingFraction': 'float', - }, - 'topology': { - 'topologyId': 'string', - }, - 'operational': { - 'failuresEnabled': 'bool', - 'performanceInterferenceEnabled': 'bool', - 'schedulerName': 'string', - }, - } - }) - - portfolio = Portfolio.from_id(request.params_path['portfolioId']) - - portfolio.check_exists() - portfolio.check_user_access(request.google_id, True) - - scenario = Scenario(request.params_body['scenario']) - - scenario.set_property('portfolioId', request.params_path['portfolioId']) - scenario.set_property('simulationState', 'QUEUED') - - scenario.insert() - - portfolio.obj['scenarioIds'].append(scenario.get_id()) - portfolio.update() - - return Response(200, 'Successfully added Scenario.', scenario.obj) diff --git a/web-server/opendc/api/v2/portfolios/portfolioId/scenarios/test_endpoint.py b/web-server/opendc/api/v2/portfolios/portfolioId/scenarios/test_endpoint.py deleted file mode 100644 index 8b55bab0..00000000 --- a/web-server/opendc/api/v2/portfolios/portfolioId/scenarios/test_endpoint.py +++ /dev/null @@ -1,119 +0,0 @@ -from opendc.util.database import DB - - -def test_add_scenario_missing_parameter(client): - assert '400' in client.post('/api/v2/portfolios/1/scenarios').status - - -def test_add_scenario_non_existing_portfolio(client, mocker): - mocker.patch.object(DB, 'fetch_one', return_value=None) - assert '404' in client.post('/api/v2/portfolios/1/scenarios', - json={ - 'scenario': { - 'name': 'test', - 'trace': { - 'traceId': '1', - 'loadSamplingFraction': 1.0, - }, - 'topology': { - 'topologyId': '1', - }, - 'operational': { - 'failuresEnabled': True, - 'performanceInterferenceEnabled': False, - 'schedulerName': 'DEFAULT', - }, - } - }).status - - -def test_add_scenario_not_authorized(client, mocker): - mocker.patch.object(DB, - 'fetch_one', - return_value={ - '_id': '1', - 'projectId': '1', - 'portfolioId': '1', - 'authorizations': [{ - 'projectId': '1', - 'authorizationLevel': 'VIEW' - }] - }) - assert '403' in client.post('/api/v2/portfolios/1/scenarios', - json={ - 'scenario': { - 'name': 'test', - 'trace': { - 'traceId': '1', - 'loadSamplingFraction': 1.0, - }, - 'topology': { - 'topologyId': '1', - }, - 'operational': { - 'failuresEnabled': True, - 'performanceInterferenceEnabled': False, - 'schedulerName': 'DEFAULT', - }, - } - }).status - - -def test_add_scenario(client, mocker): - mocker.patch.object(DB, - 'fetch_one', - return_value={ - '_id': '1', - 'projectId': '1', - 'portfolioId': '1', - 'portfolioIds': ['1'], - 'scenarioIds': ['1'], - 'authorizations': [{ - 'projectId': '1', - 'authorizationLevel': 'EDIT' - }], - 'simulationState': 'QUEUED', - }) - mocker.patch.object(DB, - 'insert', - return_value={ - '_id': '1', - 'name': 'test', - 'trace': { - 'traceId': '1', - 'loadSamplingFraction': 1.0, - }, - 'topology': { - 'topologyId': '1', - }, - 'operational': { - 'failuresEnabled': True, - 'performanceInterferenceEnabled': False, - 'schedulerName': 'DEFAULT', - }, - 'portfolioId': '1', - 'simulationState': 'QUEUED', - }) - mocker.patch.object(DB, 'update', return_value=None) - res = client.post( - '/api/v2/portfolios/1/scenarios', - json={ - 'scenario': { - 'name': 'test', - 'trace': { - 'traceId': '1', - 'loadSamplingFraction': 1.0, - }, - 'topology': { - 'topologyId': '1', - }, - 'operational': { - 'failuresEnabled': True, - 'performanceInterferenceEnabled': False, - 'schedulerName': 'DEFAULT', - }, - } - }) - assert 'portfolioId' in res.json['content'] - assert 'simulationState' in res.json['content'] - assert '200' in res.status |
