Skip to content

Commit

Permalink
fix: rename heading to column_headings and include heading in preview
Browse files Browse the repository at this point in the history
  • Loading branch information
VDigitall committed Apr 14, 2021
1 parent 1943ef3 commit 0d51646
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
8 changes: 4 additions & 4 deletions core/tests/test_upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def test_table_preview(self, client, upload_obj_validated):
)
assert len(response.json()) == 1
data = response.json()[0]
assert set(data.keys()) == {"id", "name", "preview"}
assert set(data.keys()) == {"id", "name", "preview", "heading"}

def test_table_r_friendly_preview(self, client, upload_obj_validated):
selection = create_data_selection(client, upload_obj_validated, self.url_prefix)
Expand All @@ -113,7 +113,7 @@ def test_table_r_friendly_preview(self, client, upload_obj_validated):
)
assert len(response.json()) == 1
data = response.json()[0]
assert set(data.keys()) == {"id", "name", "preview", "headings"}
assert set(data.keys()) == {"id", "name", "preview", "column_headings", "heading"}

def test_table_split_preview(self, client, upload_obj_validated):
selection = create_data_selection(client, upload_obj_validated, self.url_prefix)
Expand All @@ -138,7 +138,7 @@ def test_table_split_preview(self, client, upload_obj_validated):
)
assert len(response.json()) == 3
data = response.json()[0]
assert set(data.keys()) == {"id", "name", "preview", "headings"}
assert set(data.keys()) == {"id", "name", "preview", "heading", "column_headings"}

def test_table_split_include_preview(self, client, upload_obj_validated):
selection = create_data_selection(client, upload_obj_validated, self.url_prefix)
Expand Down Expand Up @@ -171,4 +171,4 @@ def test_table_split_include_preview(self, client, upload_obj_validated):
)
assert len(response.json()) == 2
data = response.json()[0]
assert set(data.keys()) == {"id", "name", "preview", "headings"}
assert set(data.keys()) == {"id", "name", "preview", "heading", "column_headings"}
8 changes: 4 additions & 4 deletions core/tests/test_urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def test_table_preview(self, client, url_obj_w_files):
)
assert len(response.json()) == 1
data = response.json()[0]
assert set(data.keys()) == {"id", "name", "preview"}
assert set(data.keys()) == {"id", "name", "preview", "heading"}

def test_table_r_friendly_preview(self, client, url_obj_w_files):
selection = create_data_selection(client, url_obj_w_files, self.url_prefix)
Expand All @@ -110,7 +110,7 @@ def test_table_r_friendly_preview(self, client, url_obj_w_files):
)
assert len(response.json()) == 1
data = response.json()[0]
assert set(data.keys()) == {"id", "name", "preview", "headings"}
assert set(data.keys()) == {"id", "name", "preview", "heading", "column_headings"}

def test_table_split_preview(self, client, url_obj_w_files):
selection = create_data_selection(client, url_obj_w_files, self.url_prefix)
Expand All @@ -135,7 +135,7 @@ def test_table_split_preview(self, client, url_obj_w_files):
)
assert len(response.json()) == 3
data = response.json()[0]
assert set(data.keys()) == {"id", "name", "preview", "headings"}
assert set(data.keys()) == {"id", "name", "preview", "heading", "column_headings"}

def test_table_split_include_preview(self, client, url_obj_w_files):
selection = create_data_selection(client, url_obj_w_files, self.url_prefix)
Expand Down Expand Up @@ -168,4 +168,4 @@ def test_table_split_include_preview(self, client, url_obj_w_files):
)
assert len(response.json()) == 2
data = response.json()[0]
assert set(data.keys()) == {"id", "name", "preview", "headings"}
assert set(data.keys()) == {"id", "name", "preview", "heading", "column_headings"}
9 changes: 6 additions & 3 deletions core/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,9 +268,10 @@ def list(self, request, url_id=None, upload_id=None, selection_id=None, table_id
"name": f"{tables[table.name]['name']}.csv",
"id": str(table.id),
"preview": csvfile.read(),
"heading": table.heading,
}
if selection.headings_type != selection.OCDS:
preview["headings"] = table.column_headings
preview["column_headings"] = table.column_headings
data.append(preview)
for child_table in table.array_tables.all():
if not child_table.include:
Expand All @@ -281,9 +282,10 @@ def list(self, request, url_id=None, upload_id=None, selection_id=None, table_id
"name": f"{tables[child_table.name]['name']}.csv",
"id": str(child_table.id),
"preview": csvfile.read(),
"heading": child_table.heading,
}
if selection.headings_type != selection.OCDS:
preview["headings"] = child_table.column_headings
preview["column_headings"] = child_table.column_headings
data.append(preview)
else:
preview_path = f"{datasource_dir}/{table.name}_combined.csv"
Expand All @@ -294,8 +296,9 @@ def list(self, request, url_id=None, upload_id=None, selection_id=None, table_id
"name": f"{tables[table.name]['name']}.csv",
"id": str(table.id),
"preview": csvfile.read(),
"heading": table.heading,
}
if selection.headings_type != selection.OCDS:
preview["headings"] = table.column_headings
preview["column_headings"] = table.column_headings
data.append(preview)
return Response(data)

0 comments on commit 0d51646

Please sign in to comment.