Skip to content

Commit

Permalink
Refine code and add unit test #7
Browse files Browse the repository at this point in the history
Signed-off-by: tdruez <[email protected]>
  • Loading branch information
tdruez committed Feb 16, 2024
1 parent 2125c6b commit 2233d4f
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ Release notes
data is fetched from the PurlDB to initialize the form.
https://github.com/nexB/dejacode/issues/47

- If you select two versions of the same Product in the Product list, or two different
Products, and click the Compare button, you can now download the results of the
comparison to a .xlsx file, making it easy to share the information with your
colleagues.
https://github.com/nexB/dejacode/issues/7

- Add dark theme support in UI.
https://github.com/nexB/dejacode/issues/25

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ <h1 class="header-title">
</h1>
</div>
<div class="col-auto">
<a href="?download_xlsx=1" target="_blank" class="btn btn-outline-dark"><i class="fas fa-download"></i> Download as XLSX</a>
<a href="?download_xlsx=1" target="_blank" class="btn btn-outline-dark">
<i class="fas fa-download me-1"></i>Download as XLSX
</a>
</div>
</div>
</div>
Expand Down
6 changes: 6 additions & 0 deletions product_portfolio/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1224,6 +1224,12 @@ def test_product_portfolio_product_tree_comparison_view_proper(self):
self.assertContains(response, "Added (2)")
self.assertContains(response, "Removed (1)")

response = self.client.get(url, data={"download_xlsx": True})
expected_type = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
self.assertEqual(expected_type, response.headers.get("Content-Type"))
expected_disposition = "attachment; filename=product_comparison.xlsx"
self.assertEqual(expected_disposition, response.headers.get("Content-Disposition"))

def test_product_portfolio_product_tree_comparison_view_secured_access(self):
self.client.login(username=self.basic_user.username, password="secret")
url = resolve_url(
Expand Down
4 changes: 2 additions & 2 deletions product_portfolio/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -978,7 +978,7 @@ def get_queryset(self):
)


def xlsx_download(request, rows, left_product, right_product):
def comparison_download_xlsx(request, rows, left_product, right_product):
wb = Workbook()
ws = wb.active
ws.title = "Product comparison"
Expand Down Expand Up @@ -1133,7 +1133,7 @@ def sort_by_name_version(row):
rows.sort(key=sort_by_name_version)

if request.GET.get("download_xlsx"):
return xlsx_download(request, rows, left_product, right_product)
return comparison_download_xlsx(request, rows, left_product, right_product)

action_filters = [
{"value": "added", "count": len(added), "checked": True},
Expand Down

0 comments on commit 2233d4f

Please sign in to comment.