diff --git a/admin/templates/admin/tag_list.html b/admin/templates/admin/tag_list.html index b4bcab3e..6922e3ce 100644 --- a/admin/templates/admin/tag_list.html +++ b/admin/templates/admin/tag_list.html @@ -31,8 +31,9 @@ {% for tag in tags %} {% include 'common/tag_badge.html' with tag=tag.name %} - {{ tag.vm_count }} - {{ tag.host_count }} + {# the VM list or the Computes page, showing the tag's only #} + {% if tag.vm_count %}{{ tag.vm_count }}{% else %}0{% endif %} + {% if tag.host_count %}{{ tag.host_count }}{% else %}0{% endif %} {% trans "Rename" %} {% trans "Delete" %} diff --git a/admin/tests/test_logs_page.py b/admin/tests/test_logs_page.py index d371da17..08afa871 100644 --- a/admin/tests/test_logs_page.py +++ b/admin/tests/test_logs_page.py @@ -63,6 +63,7 @@ class LogsPageTests(TestCase): self.assertEqual(self.rows(page)[0][1], log.date.strftime("%Y-%m-%d %H:%M:%S")) def test_a_vm_row_links_the_vm_while_it_is_there(self): + # not its user or host: the row keeps their names, which another may take later page = self.page(q="alice") self.assertEqual(page.xpath("//tbody/tr/td/a/@href"), [reverse("instances:instance", args=[self.vm.pk])]) self.vm.delete() diff --git a/admin/tests/test_views.py b/admin/tests/test_views.py index 7af34103..9ab73342 100644 --- a/admin/tests/test_views.py +++ b/admin/tests/test_views.py @@ -139,6 +139,20 @@ class AdminTestCase(TestCase): self.assertEqual(said(self.client.post(reverse("admin:tag_update", args=[tag.id]), {"name": "new-name"})), ["Tag old-name renamed to new-name"]) + def test_a_tag_s_counts_link_its_vms_and_hosts(self): + from computes.models import Compute, Tag + from instances.models import Instance + + host = Compute.objects.create(name="tg-host", hostname="192.0.2.8", login="", password="", type=4) + tag = Tag.objects.create(name="web") + Instance.objects.create(compute=host, name="tg-vm", uuid="00000000-0000-4000-8000-0000000000cc").tags.add(tag) + page = html.fromstring(self.client.get(reverse("admin:tag_list")).content) + self.assertEqual(page.xpath("//tbody//td/a[not(contains(@class, 'btn'))]/@href"), [reverse("instances:index") + "?tag=web"]) + host.tags.add(tag) + page = html.fromstring(self.client.get(reverse("admin:tag_list")).content) + self.assertEqual(page.xpath("//tbody//td/a[not(contains(@class, 'btn'))]/@href"), + [reverse("instances:index") + "?tag=web", reverse("computes") + "?tag=web"]) + def test_users(self): response = self.client.get(reverse("admin:user_create")) self.assertEqual(response.status_code, 200) diff --git a/instances/templates/instances/vm_list.html b/instances/templates/instances/vm_list.html index 7cbbfa7f..f7679e68 100644 --- a/instances/templates/instances/vm_list.html +++ b/instances/templates/instances/vm_list.html @@ -22,7 +22,7 @@ {# and shows this bar at the foot of the window while any is chosen #}