From 93778b96a6fb57ee59531d07c24ee420a017d2c6 Mon Sep 17 00:00:00 2001 From: bill-becker Date: Tue, 26 Sep 2023 13:49:46 -0600 Subject: [PATCH] Change /stable to /v3, remove /v3 from /dev, update tests /dev -> /v3 --- reo/scenario.py | 2 +- reopt_api/urls.py | 19 ++++++-------- reoptjl/test/test_http_endpoints.py | 36 +++++++++++++------------- reoptjl/test/test_job_endpoint.py | 40 ++++++++++++++--------------- resilience_stats/tests/test_erp.py | 12 ++++----- 5 files changed, 53 insertions(+), 56 deletions(-) diff --git a/reo/scenario.py b/reo/scenario.py index c9d971859..383961844 100644 --- a/reo/scenario.py +++ b/reo/scenario.py @@ -384,7 +384,7 @@ def setup_pv(pv_dict, latitude, longitude, time_steps_per_hour): ground_k_inputs = {"latitude": ghpghx_post["latitude"], "longitude": ghpghx_post["longitude"]} # Call to the django view endpoint /ghp_efficiency_thermal_factors which calls the http.jl endpoint - ground_k_resp = client.get(f'/dev/ghpghx/ground_conductivity', data=ground_k_inputs) + ground_k_resp = client.get(f'/v3/ghpghx/ground_conductivity', data=ground_k_inputs) ground_k_response = json.loads(ground_k_resp.content) ghpghx_post["ground_thermal_conductivity_btu_per_hr_ft_f"] = ground_k_response["thermal_conductivity"] diff --git a/reopt_api/urls.py b/reopt_api/urls.py index 3185f49c9..17d82d2d8 100644 --- a/reopt_api/urls.py +++ b/reopt_api/urls.py @@ -24,19 +24,16 @@ v3_api = Api(api_name='v3') v3_api.register(REoptJLJob()) -v3_api.register(GHPGHXJob()) v3_api.register(ERPJob()) +v3_api.register(GHPGHXJob()) stable_api = Api(api_name='stable') -stable_api.register(Job2()) -stable_api.register(OutageSimJob()) +stable_api.register(REoptJLJob()) +stable_api.register(ERPJob()) stable_api.register(GHPGHXJob()) dev_api = Api(api_name='dev') -dev_api.register(REoptJLJob()) dev_api.register(FutureCostsAPI()) -dev_api.register(GHPGHXJob()) -dev_api.register(ERPJob()) def page_not_found(request, url): @@ -77,12 +74,12 @@ def page_not_found(request, url): # (summary is within reoptjl.urls) re_path(r'', include(v3_api.urls)), - path('stable/', include('reo.urls_v2')), - path('stable/', include('resilience_stats.urls_v1_v2')), - path('stable/', include('proforma.urls')), - path('stable/', include('load_builder.urls')), - path('stable/', include('summary.urls')), + path('stable/', include('reoptjl.urls')), + path('stable/', include('resilience_stats.urls_v3plus')), path('stable/', include('ghpghx.urls')), + path('stable/', include('load_builder.urls')), + # TODO proforma for v3 + # (summary is within reoptjl.urls) re_path(r'', include(stable_api.urls)), path('dev/', include('reoptjl.urls')), diff --git a/reoptjl/test/test_http_endpoints.py b/reoptjl/test/test_http_endpoints.py index 9142f3c03..b8410fb91 100644 --- a/reoptjl/test/test_http_endpoints.py +++ b/reoptjl/test/test_http_endpoints.py @@ -21,7 +21,7 @@ def test_chp_defaults(self): http_response = response.json() # Call to the django view endpoint /chp_defaults which calls the http.jl endpoint - resp = self.api_client.get(f'/dev/chp_defaults', data=inputs) + resp = self.api_client.get(f'/v3/chp_defaults', data=inputs) view_response = json.loads(resp.content) mismatch = [] @@ -59,7 +59,7 @@ def test_steamturbine_defaults(self): http_response = response.json() # Call to the django view endpoint /chp_defaults which calls the http.jl endpoint - resp = self.api_client.get(f'/dev/chp_defaults', data=inputs) + resp = self.api_client.get(f'/v3/chp_defaults', data=inputs) view_response = json.loads(resp.content) mismatch = [] @@ -86,7 +86,7 @@ def test_absorption_chiller_defaults(self): http_response = response.json() # Call to the django view endpoint /absorption_chiller_defaults which calls the http.jl endpoint - resp = self.api_client.get(f'/dev/absorption_chiller_defaults', data=inputs) + resp = self.api_client.get(f'/v3/absorption_chiller_defaults', data=inputs) view_response = json.loads(resp.content) mismatch = [] @@ -112,8 +112,8 @@ def test_simulated_load(self): "longitude": -122.45 } - # The /dev/simulated_load endpoint calls the http.jl /simulated_load endpoint - response = self.api_client.get(f'/dev/simulated_load', data=inputs) + # The /v3/simulated_load endpoint calls the http.jl /simulated_load endpoint + response = self.api_client.get(f'/v3/simulated_load', data=inputs) http_response = json.loads(response.content) # Call to the v2 /simulated_load to check for consistency @@ -129,8 +129,8 @@ def test_simulated_load(self): inputs["percent_share[0]"] = 25.0 inputs["percent_share[1]"] = 100.0 - inputs["percent_share[0]"] - # The /dev/simulated_load endpoint calls the http.jl /simulated_load endpoint - response = self.api_client.get(f'/dev/simulated_load', data=inputs) + # The /v3/simulated_load endpoint calls the http.jl /simulated_load endpoint + response = self.api_client.get(f'/v3/simulated_load', data=inputs) http_response = json.loads(response.content) # Call to the v2 /simulated_load to check for consistency @@ -150,7 +150,7 @@ def test_emissions_profile_endpoint(self): "latitude": 47.606211, "longitude": -122.336052 } - resp = self.api_client.get(f'/dev/emissions_profile', data=inputs) + resp = self.api_client.get(f'/v3/emissions_profile', data=inputs) self.assertHttpOK(resp) view_response = json.loads(resp.content) self.assertEquals(view_response["meters_to_region"], 0.0) @@ -160,7 +160,7 @@ def test_emissions_profile_endpoint(self): "latitude": 47.606211, "longitude": 122.336052 } - resp = self.api_client.get(f'/dev/emissions_profile', data=inputs) + resp = self.api_client.get(f'/v3/emissions_profile', data=inputs) self.assertHttpBadRequest(resp) view_response = json.loads(resp.content) self.assertTrue("error" in view_response) @@ -172,7 +172,7 @@ def test_easiur_endpoint(self): "longitude": -122.336052, "inflation": 0.025 } - resp = self.api_client.get(f'/dev/easiur_costs', data=inputs) + resp = self.api_client.get(f'/v3/easiur_costs', data=inputs) self.assertHttpOK(resp) view_response = json.loads(resp.content) for ekey in ["NOx", "SO2", "PM25"]: @@ -183,7 +183,7 @@ def test_easiur_endpoint(self): "longitude": 122.336052, "inflation": 0.025 } - resp = self.api_client.get(f'/dev/easiur_costs', data=inputs) + resp = self.api_client.get(f'/v3/easiur_costs', data=inputs) self.assertHttpBadRequest(resp) view_response = json.loads(resp.content) self.assertTrue("error" in view_response) @@ -195,7 +195,7 @@ def test_ghp_endpoints(self): "doe_reference_name": "MediumOffice"} # Call to the django view endpoint /ghp_efficiency_thermal_factors which calls the http.jl endpoint - resp = self.api_client.get(f'/dev/ghp_efficiency_thermal_factors', data=inputs_dict) + resp = self.api_client.get(f'/v3/ghp_efficiency_thermal_factors', data=inputs_dict) view_response = json.loads(resp.content) self.assertEqual(view_response["cooling_efficiency_thermal_factor"], 0.43) @@ -206,7 +206,7 @@ def test_ghp_endpoints(self): "longitude": -122.45} # Call to the django view endpoint /ghpghx/ground_conductivity which calls the http.jl endpoint - resp = self.api_client.get(f'/dev/ghpghx/ground_conductivity', data=inputs_dict) + resp = self.api_client.get(f'/v3/ghpghx/ground_conductivity', data=inputs_dict) view_response = json.loads(resp.content) self.assertEqual(view_response["thermal_conductivity"], 1.117) @@ -220,7 +220,7 @@ def test_default_existing_chiller_cop(self): } # Call to the django view endpoint /get_existing_chiller_default_cop which calls the http.jl endpoint - resp = self.api_client.get(f'/dev/get_existing_chiller_default_cop', data=inputs_dict) + resp = self.api_client.get(f'/v3/get_existing_chiller_default_cop', data=inputs_dict) view_response = json.loads(resp.content) print(view_response) @@ -230,7 +230,7 @@ def test_default_existing_chiller_cop(self): inputs_dict = {} # Call to the django view endpoint /get_existing_chiller_default_cop which calls the http.jl endpoint - resp = self.api_client.get(f'/dev/get_existing_chiller_default_cop', data=inputs_dict) + resp = self.api_client.get(f'/v3/get_existing_chiller_default_cop', data=inputs_dict) view_response = json.loads(resp.content) print(view_response) @@ -244,7 +244,7 @@ def test_default_existing_chiller_cop(self): } # Call to the django view endpoint /get_existing_chiller_default_cop which calls the http.jl endpoint - resp = self.api_client.get(f'/dev/get_existing_chiller_default_cop', data=inputs_dict) + resp = self.api_client.get(f'/v3/get_existing_chiller_default_cop', data=inputs_dict) view_response = json.loads(resp.content) print(view_response) @@ -257,7 +257,7 @@ def test_default_existing_chiller_cop(self): } # Call to the django view endpoint /get_existing_chiller_default_cop which calls the http.jl endpoint - resp = self.api_client.get(f'/dev/get_existing_chiller_default_cop', data=inputs_dict) + resp = self.api_client.get(f'/v3/get_existing_chiller_default_cop', data=inputs_dict) view_response = json.loads(resp.content) print(view_response) @@ -269,7 +269,7 @@ def test_default_existing_chiller_cop(self): } # Call to the django view endpoint /get_existing_chiller_default_cop which calls the http.jl endpoint - resp = self.api_client.get(f'/dev/get_existing_chiller_default_cop', data=inputs_dict) + resp = self.api_client.get(f'/v3/get_existing_chiller_default_cop', data=inputs_dict) view_response = json.loads(resp.content) print(view_response) diff --git a/reoptjl/test/test_job_endpoint.py b/reoptjl/test/test_job_endpoint.py index f635f1588..a92c0e932 100644 --- a/reoptjl/test/test_job_endpoint.py +++ b/reoptjl/test/test_job_endpoint.py @@ -19,11 +19,11 @@ def test_multiple_outages(self): scenario_file = os.path.join('reoptjl', 'test', 'posts', 'outage.json') scenario = json.load(open(scenario_file, 'r')) - resp = self.api_client.post('/dev/job/', format='json', data=scenario) + resp = self.api_client.post('/v3/job/', format='json', data=scenario) self.assertHttpCreated(resp) r = json.loads(resp.content) run_uuid = r.get('run_uuid') - resp = self.api_client.get(f'/dev/job/{run_uuid}/results') + resp = self.api_client.get(f'/v3/job/{run_uuid}/results') r = json.loads(resp.content) results = r["outputs"] self.assertEqual(np.array(results["Outages"]["unserved_load_series_kw"]).shape, (1,2,5)) @@ -42,12 +42,12 @@ def test_pv_battery_and_emissions_defaults_from_julia(self): post_file = os.path.join('reoptjl', 'test', 'posts', 'pv_batt_emissions.json') post = json.load(open(post_file, 'r')) - resp = self.api_client.post('/dev/job/', format='json', data=post) + resp = self.api_client.post('/v3/job/', format='json', data=post) self.assertHttpCreated(resp) r = json.loads(resp.content) run_uuid = r.get('run_uuid') - resp = self.api_client.get(f'/dev/job/{run_uuid}/results') + resp = self.api_client.get(f'/v3/job/{run_uuid}/results') r = json.loads(resp.content) results = r["outputs"] @@ -75,12 +75,12 @@ def test_off_grid_defaults(self): post_file = os.path.join('reoptjl', 'test', 'posts', 'off_grid_defaults.json') post = json.load(open(post_file, 'r')) - resp = self.api_client.post('/dev/job/', format='json', data=post) + resp = self.api_client.post('/v3/job/', format='json', data=post) self.assertHttpCreated(resp) r = json.loads(resp.content) run_uuid = r.get('run_uuid') - resp = self.api_client.get(f'/dev/job/{run_uuid}/results') + resp = self.api_client.get(f'/v3/job/{run_uuid}/results') r = json.loads(resp.content) results = r["outputs"] @@ -99,12 +99,12 @@ def test_process_reopt_error(self): post_file = os.path.join('reoptjl', 'test', 'posts', 'handle_reopt_error.json') post = json.load(open(post_file, 'r')) - resp = self.api_client.post('/dev/job/', format='json', data=post) + resp = self.api_client.post('/v3/job/', format='json', data=post) self.assertHttpCreated(resp) r = json.loads(resp.content) run_uuid = r.get('run_uuid') - resp = self.api_client.get(f'/dev/job/{run_uuid}/results') + resp = self.api_client.get(f'/v3/job/{run_uuid}/results') r = json.loads(resp.content) assert('errors' in r["messages"].keys()) assert('warnings' in r["messages"].keys()) @@ -185,12 +185,12 @@ def test_thermal_in_results(self): ghpghx_response = json.load(open(ghpghx_response_file, 'r')) scenario["GHP"]["ghpghx_responses"] = [ghpghx_response] - resp = self.api_client.post('/dev/job/', format='json', data=scenario) + resp = self.api_client.post('/v3/job/', format='json', data=scenario) self.assertHttpCreated(resp) r = json.loads(resp.content) run_uuid = r.get('run_uuid') - resp = self.api_client.get(f'/dev/job/{run_uuid}/results') + resp = self.api_client.get(f'/v3/job/{run_uuid}/results') r = json.loads(resp.content) inputs = r["inputs"] results = r["outputs"] @@ -214,12 +214,12 @@ def test_chp_defaults_from_julia(self): # Default ExistingBoiler efficiency for production_type = steam is 0.75 post["SpaceHeatingLoad"]["annual_mmbtu"] = 8760 * 8 / 0.75 post["DomesticHotWaterLoad"]["annual_mmbtu"] = 8760 * 8 / 0.75 - resp = self.api_client.post('/dev/job/', format='json', data=post) + resp = self.api_client.post('/v3/job/', format='json', data=post) self.assertHttpCreated(resp) r = json.loads(resp.content) run_uuid = r.get('run_uuid') - resp = self.api_client.get(f'/dev/job/{run_uuid}/results') + resp = self.api_client.get(f'/v3/job/{run_uuid}/results') r = json.loads(resp.content) inputs_chp = r["inputs"]["CHP"] @@ -231,7 +231,7 @@ def test_chp_defaults_from_julia(self): } # Call to the django view endpoint /chp_defaults which calls the http.jl endpoint - resp = self.api_client.get(f'/dev/chp_defaults', data=inputs_chp_defaults) + resp = self.api_client.get(f'/v3/chp_defaults', data=inputs_chp_defaults) view_response = json.loads(resp.content) for key in view_response["default_inputs"].keys(): @@ -260,7 +260,7 @@ def test_peak_load_outage_times(self): "start_not_center_on_peaks": False } expected_time_steps = [50*24-1-47+1, 70*24+13-47+1, 170*24-47+1, 243*24-47+1] - resp = self.api_client.post(f'/dev/peak_load_outage_times', data=outage_inputs) + resp = self.api_client.post(f'/v3/peak_load_outage_times', data=outage_inputs) self.assertHttpOK(resp) resp = json.loads(resp.content) self.assertEquals(resp["outage_start_time_steps"], expected_time_steps) @@ -268,7 +268,7 @@ def test_peak_load_outage_times(self): outage_inputs["seasonal_peaks"] = False outage_inputs["start_not_center_on_peaks"] = True expected_time_steps = [243*24+1] - resp = self.api_client.post(f'/dev/peak_load_outage_times', data=outage_inputs) + resp = self.api_client.post(f'/v3/peak_load_outage_times', data=outage_inputs) self.assertHttpOK(resp) resp = json.loads(resp.content) self.assertEquals(resp["outage_start_time_steps"], expected_time_steps) @@ -281,12 +281,12 @@ def test_superset_input_fields(self): post_file = os.path.join('reoptjl', 'test', 'posts', 'all_inputs_test.json') post = json.load(open(post_file, 'r')) - resp = self.api_client.post('/dev/job/', format='json', data=post) + resp = self.api_client.post('/v3/job/', format='json', data=post) self.assertHttpCreated(resp) r = json.loads(resp.content) run_uuid = r.get('run_uuid') - resp = self.api_client.get(f'/dev/job/{run_uuid}/results') + resp = self.api_client.get(f'/v3/job/{run_uuid}/results') r = json.loads(resp.content) results = r["outputs"] @@ -299,12 +299,12 @@ def test_steamturbine_defaults_from_julia(self): post = json.load(open(post_file, 'r')) # Call http.jl /reopt to run SteamTurbine scenario and get results for defaults from julia checking - resp = self.api_client.post('/dev/job/', format='json', data=post) + resp = self.api_client.post('/v3/job/', format='json', data=post) self.assertHttpCreated(resp) r = json.loads(resp.content) run_uuid = r.get('run_uuid') - resp = self.api_client.get(f'/dev/job/{run_uuid}/results') + resp = self.api_client.get(f'/v3/job/{run_uuid}/results') r = json.loads(resp.content) inputs_steamturbine = r["inputs"]["SteamTurbine"] @@ -318,7 +318,7 @@ def test_steamturbine_defaults_from_julia(self): } # Call to the django view endpoint /chp_defaults which calls the http.jl endpoint - resp = self.api_client.get(f'/dev/chp_defaults', data=inputs_steamturbine_defaults) + resp = self.api_client.get(f'/v3/chp_defaults', data=inputs_steamturbine_defaults) view_response = json.loads(resp.content) for key in view_response["default_inputs"].keys(): diff --git a/resilience_stats/tests/test_erp.py b/resilience_stats/tests/test_erp.py index 646d6d39f..00c38dc29 100644 --- a/resilience_stats/tests/test_erp.py +++ b/resilience_stats/tests/test_erp.py @@ -13,17 +13,17 @@ def setUp(self): super(ERPTests, self).setUp() #for ERP simulation - self.reopt_base_erp = '/dev/erp/' - self.reopt_base_erp_results = '/dev/erp/{}/results/' - self.reopt_base_erp_help = '/dev/erp/help/' - self.reopt_base_erp_chp_defaults = '/dev/erp/chp_defaults/?prime_mover={0}&is_chp={1}&size_kw={2}' + self.reopt_base_erp = '/v3/erp/' + self.reopt_base_erp_results = '/v3/erp/{}/results/' + self.reopt_base_erp_help = '/v3/erp/help/' + self.reopt_base_erp_chp_defaults = '/v3/erp/chp_defaults/?prime_mover={0}&is_chp={1}&size_kw={2}' self.post_sim_gens_batt_pv_wind = os.path.join('resilience_stats', 'tests', 'ERP_sim_gens_batt_pv_wind_post.json') self.post_sim_large_stor = os.path.join('resilience_stats', 'tests', 'ERP_sim_large_stor_post.json') self.post_sim_only = os.path.join('resilience_stats', 'tests', 'ERP_sim_only_post.json') self.post_sim_long_dur_stor = os.path.join('resilience_stats', 'tests', 'ERP_sim_long_dur_stor_post.json') #for REopt optimization - self.reopt_base_opt = '/dev/job/' - self.reopt_base_opt_results = '/dev/job/{}/results' + self.reopt_base_opt = '/v3/job/' + self.reopt_base_opt_results = '/v3/job/{}/results' self.post_opt_gens_batt_pv_wind = os.path.join('resilience_stats', 'tests', 'ERP_opt_gens_batt_pv_wind_post.json') self.post_opt_long_dur_stor = os.path.join('resilience_stats', 'tests', 'ERP_opt_long_dur_stor_post.json')