Browse Source

Add "(not unique)" note next to ambiguous ping URLs

pull/563/head
Pēteris Caune 3 years ago
parent
commit
2adf4b6aee
No known key found for this signature in database GPG Key ID: E28D7679E9A9EDE2
3 changed files with 48 additions and 4 deletions
  1. +32
    -1
      hc/front/tests/test_my_checks.py
  2. +10
    -0
      hc/front/views.py
  3. +6
    -3
      templates/front/my_checks_desktop.html

+ 32
- 1
hc/front/tests/test_my_checks.py View File

@ -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 ("[email protected]", "[email protected]"):
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="[email protected]", 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="[email protected]", 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="[email protected]", password="password")
self.client.get(self.url + "?urls=slug")
self.project.refresh_from_db()
self.assertTrue(self.project.show_slugs)

+ 10
- 0
hc/front/views.py View File

@ -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,
}


+ 6
- 3
templates/front/my_checks_desktop.html View File

@ -82,10 +82,13 @@
</td>
<td class="hidden-xs hidden-sm url">
{% if project.show_slugs and not check.slug %}
<span class="unavailable">unavailable, set name first</span>
<span class="unavailable">unavailable, set name first</span>
{% else %}
<span class="my-checks-url">{{ check.url|format_ping_endpoint }}</span>
<button class="copy-link" data-clipboard-text="{{ check.url }}">copy</button>
<span class="my-checks-url">{{ check.url|format_ping_endpoint }}</span>
{% if project.show_slugs and check.slug in ambiguous %}
<small class="text-danger">(not unique)</small>
{% endif %}
<button class="copy-link" data-clipboard-text="{{ check.url }}">copy</button>
{% endif %}
</td>
<td class="hidden-xs">


Loading…
Cancel
Save