Skip to content
Open
Show file tree
Hide file tree
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
14 changes: 14 additions & 0 deletions src/tokens/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,3 +189,17 @@ def test_token_submit_form_view(self) -> None:
rows = soup.select("div.alert.alert-warning")
matches = [s for s in rows if "This token is not valid yet" in str(s)]
self.assertEqual(len(matches), 1, "inactive token find does not return the not valid yet.")

def test_total_finds_pct_with_no_tokens(self) -> None:
"""Test calculating percentage with no tokens."""
self.client.force_login(self.users[0])
Token.objects.all().delete()

response = self.client.get(self.url_dashboard)
result = response.context["widgets"]["total_finds"]["no_js"]["Unique finds"]["pct"]

assert result == 0.0

result = response.context["widgets"]["total_finds"]["no_js"]["Not found"]["pct"]

assert result == 0.0
4 changes: 2 additions & 2 deletions src/tokens/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,11 @@ def get_total_finds_metrics(self, camp_finds: QuerySet) -> dict:
"no_js": {
"Unique finds": {
"value": total_finds_count,
"pct": (total_finds_count / token_count) * 100 if token_count else 0,
"pct": (total_finds_count / token_count) * 100 if token_count else 0.0,
},
"Not found": {
"value": (token_count - total_finds_count),
"pct": (token_count - total_finds_count) / token_count * 100 if token_count else 0,
"pct": (token_count - total_finds_count) / token_count * 100 if token_count else 0.0,
},
},
"chart": {
Expand Down
Loading