Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
151 changes: 76 additions & 75 deletions app/projects/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Loading