diff --git a/hc/front/tests/test_my_checks.py b/hc/front/tests/test_my_checks.py index 5f449cd6..99975c43 100644 --- a/hc/front/tests/test_my_checks.py +++ b/hc/front/tests/test_my_checks.py @@ -8,15 +8,17 @@ class MyChecksTestCase(BaseTestCase): def setUp(self): super().setUp() self.check = Check(project=self.project, name="Alice Was Here") + self.check.slug = "alice-was-here" self.check.save() - self.url = "/projects/%s/checks/" % self.project.code + self.url = f"/projects/{self.project.code}/checks/" def test_it_works(self): for email in ("alice@example.org", "bob@example.org"): self.client.login(username=email, password="password") r = self.client.get(self.url) self.assertContains(r, "Alice Was Here", status_code=200) + self.assertContains(r, str(self.check.code), status_code=200) # The pause button: self.assertContains(r, "btn btn-default pause", status_code=200) @@ -139,3 +141,32 @@ class MyChecksTestCase(BaseTestCase): # The pause button: self.assertNotContains(r, "btn btn-default pause", status_code=200) + + def test_it_shows_slugs(self): + self.project.show_slugs = True + self.project.save() + + self.client.login(username="alice@example.org", password="password") + r = self.client.get(self.url) + self.assertContains(r, "alice-was-here") + self.assertNotContains(r, "(not unique)") + + def test_it_shows_not_unique_note(self): + self.project.show_slugs = True + self.project.save() + + dupe = Check(project=self.project, name="Alice Was Here") + dupe.slug = "alice-was-here" + dupe.save() + + self.client.login(username="alice@example.org", password="password") + r = self.client.get(self.url) + self.assertContains(r, "alice-was-here") + self.assertContains(r, "(not unique)") + + def test_it_saves_url_format_preference(self): + self.client.login(username="alice@example.org", password="password") + self.client.get(self.url + "?urls=slug") + + self.project.refresh_from_db() + self.assertTrue(self.project.show_slugs) diff --git a/hc/front/views.py b/hc/front/views.py index d64d0d07..ef017e3a 100644 --- a/hc/front/views.py +++ b/hc/front/views.py @@ -209,6 +209,15 @@ def my_checks(request, code): if search not in search_key: hidden_checks.add(check) + # Figure out which checks have ambiguous ping URLs + seen, ambiguous = set(), set() + if project.show_slugs: + for check in checks: + if check.slug and check.slug in seen: + ambiguous.add(check.slug) + else: + seen.add(check.slug) + # Do we need to show the "Last Duration" header? show_last_duration = False for check in checks: @@ -231,6 +240,7 @@ def my_checks(request, code): "selected_tags": selected_tags, "search": search, "hidden_checks": hidden_checks, + "ambiguous": ambiguous, "show_last_duration": show_last_duration, } diff --git a/templates/front/my_checks_desktop.html b/templates/front/my_checks_desktop.html index 7b7b56ec..613f6df4 100644 --- a/templates/front/my_checks_desktop.html +++ b/templates/front/my_checks_desktop.html @@ -82,10 +82,13 @@