From f9bad16845dea62590198593e6ba3a377c4c87ed Mon Sep 17 00:00:00 2001 From: josihoppe <116898820+josihoppe@users.noreply.github.com> Date: Thu, 26 Mar 2026 12:10:09 +0100 Subject: [PATCH] adjusted parsing tests to new timeseries set up --- app/projects/tests.py | 151 +++++++++++++++++++++--------------------- 1 file changed, 76 insertions(+), 75 deletions(-) diff --git a/app/projects/tests.py b/app/projects/tests.py index dab6f1b1c..0c24bf45c 100644 --- a/app/projects/tests.py +++ b/app/projects/tests.py @@ -240,78 +240,79 @@ def test_export_project_via_get_with_scenarios(self): self.assertIn("scenario_set_data", response.json()) -# class UploadTimeseriesTest(TestCase): -# fixtures = ["fixtures/benchmarks_fixture.json"] -# -# @classmethod -# def setUpTestData(cls): -# pass -# -# def setUp(self): -# self.factory = RequestFactory() -# self.client.login(username="testUser", password="ASas12,.") -# self.project = Project.objects.get(id=1) -# self.post_url = reverse("asset_create_or_update", args=[2, "demand"]) -# -# def test_load_demand_csv_double_timeseries(self): -# with open("./test_files/test_ts_double.csv") as fp: -# data = { -# "name": "Test_input_timeseries", -# "pos_x": 0, -# "pos_y": 0, -# "input_timeseries": fp, -# } -# response = self.client.post(self.post_url, data, format="multipart") -# self.assertEqual(response.status_code, 200) -# asset = Asset.objects.last() -# self.assertEqual(asset.input_timeseries_values, [1, 2, 3, 4]) -# -# def test_load_demand_csv_double_decimal_point_with_comma(self): -# with open("./test_files/test_ts_csv_semicolon.csv") as fp: -# data = { -# "name": "Test_input_timeseries", -# "pos_x": 0, -# "pos_y": 0, -# "input_timeseries": fp, -# } -# response = self.client.post(self.post_url, data, format="multipart") -# self.assertEqual(response.status_code, 200) -# asset = Asset.objects.last() -# self.assertEqual(asset.input_timeseries_values, [8.5, 3.3, 4.0, 6.0]) -# -# def test_load_demand_xlsx_double_timeseries(self): -# with open("./test_files/test_ts_double.xlsx", "rb") as fp: -# data = { -# "name": "Test_input_timeseries", -# "pos_x": 0, -# "pos_y": 0, -# "input_timeseries": fp, -# } -# response = self.client.post(self.post_url, data, format="multipart") -# self.assertEqual(response.status_code, 200) -# asset = Asset.objects.last() -# self.assertEqual(asset.input_timeseries_values, [1, 2, 3, 4]) -# -# def test_load_demand_csv_decimal_point_with_comma(self): -# with open("./test_files/test_ts_comma_decimal.csv") as fp: -# data = { -# "name": "Test_input_timeseries", -# "pos_x": 0, -# "pos_y": 0, -# "input_timeseries": fp, -# } -# response = self.client.post(self.post_url, data, format="multipart") -# self.assertEqual(response.status_code, 200) -# asset = Asset.objects.last() -# self.assertEqual(asset.input_timeseries_values, [1.2, 2, 3.0, 4]) -# -# def test_load_demand_file_wrong_format_raises_error(self): -# with open("./test_files/test_ts.notsupported") as fp: -# data = { -# "name": "Test_input_timeseries", -# "pos_x": 0, -# "pos_y": 0, -# "input_timeseries": fp, -# } -# response = self.client.post(self.post_url, data, format="multipart") -# self.assertEqual(response.status_code, 422) +class UploadTimeseriesTest(TestCase): + fixtures = ["fixtures/benchmarks_fixture.json"] + + @classmethod + def setUpTestData(cls): + pass + + def setUp(self): + self.factory = RequestFactory() + self.client.login(username="testUser", password="ASas12,.") + self.project = Project.objects.get(id=1) + self.post_url = reverse("asset_create_or_update", args=[2, "demand"]) + + def test_load_demand_csv_double_timeseries(self): + with open("./test_files/test_ts_double.csv") as fp: + data = { + "name": "Test_input_timeseries", + "input_timeseries_scalar": "", + "input_timeseries_select": "", + "input_timeseries_file": fp, + } + response = self.client.post(self.post_url, data, format="multipart") + print(response.content.decode()) + self.assertEqual(response.status_code, 200) + asset = Asset.objects.last() + self.assertEqual(asset.input_timeseries_values, [1, 2, 3, 4]) + + def test_load_demand_csv_double_decimal_point_with_comma(self): + with open("./test_files/test_ts_csv_semicolon.csv") as fp: + data = { + "name": "Test_input_timeseries", + "input_timeseries_scalar": "", + "input_timeseries_select": "", + "input_timeseries_file": fp, + } + response = self.client.post(self.post_url, data, format="multipart") + self.assertEqual(response.status_code, 200) + asset = Asset.objects.last() + self.assertEqual(asset.input_timeseries_values, [8.5, 3.3, 4.0, 6.0]) + + def test_load_demand_xlsx_double_timeseries(self): + with open("./test_files/test_ts_double.xlsx", "rb") as fp: + data = { + "name": "Test_input_timeseries", + "input_timeseries_scalar": "", + "input_timeseries_select": "", + "input_timeseries_file": fp, + } + response = self.client.post(self.post_url, data, format="multipart") + self.assertEqual(response.status_code, 200) + asset = Asset.objects.last() + self.assertEqual(asset.input_timeseries_values, [1, 2, 3, 4]) + + def test_load_demand_csv_decimal_point_with_comma(self): + with open("./test_files/test_ts_comma_decimal.csv") as fp: + data = { + "name": "Test_input_timeseries", + "input_timeseries_scalar": "", + "input_timeseries_select": "", + "input_timeseries_file": fp, + } + response = self.client.post(self.post_url, data, format="multipart") + self.assertEqual(response.status_code, 200) + asset = Asset.objects.last() + self.assertEqual(asset.input_timeseries_values, [1.2, 2, 3.0, 4]) + + def test_load_demand_file_wrong_format_raises_error(self): + with open("./test_files/test_ts.notsupported") as fp: + data = { + "name": "Test_input_timeseries", + "input_timeseries_scalar": "", + "input_timeseries_select": "", + "input_timeseries_file": fp, + } + response = self.client.post(self.post_url, data, format="multipart") + self.assertEqual(response.status_code, 422)