From d739d8ff62604adb39bf298eaaf395593a941193 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C4=93teris=20Caune?= Date: Thu, 16 Mar 2017 18:12:30 +0200 Subject: [PATCH] DRY: use channel.get_kind_display() --- hc/api/admin.py | 26 +++----------------------- hc/api/tests/test_admin.py | 13 +++++++++++-- templates/front/channels.html | 13 +------------ 3 files changed, 15 insertions(+), 37 deletions(-) diff --git a/hc/api/admin.py b/hc/api/admin.py index b05d48d8..8b4b40d4 100644 --- a/hc/api/admin.py +++ b/hc/api/admin.py @@ -165,30 +165,10 @@ class ChannelsAdmin(admin.ModelAdmin): return obj.user.email if obj.user else None def formatted_kind(self, obj): - if obj.kind == "pd": - return "PagerDuty" - elif obj.kind == "victorops": - return "VictorOps" - elif obj.kind == "pushbullet": - return "Pushbullet" - elif obj.kind == "discord": - return "Discord" - elif obj.kind == "po": - return "Pushover" - elif obj.kind == "webhook": - return "Webhook" - elif obj.kind == "slack": - return "Slack" - elif obj.kind == "hipchat": - return "HipChat" - elif obj.kind == "opsgenie": - return "OpsGenie" - elif obj.kind == "email" and obj.email_verified: - return "Email" - elif obj.kind == "email" and not obj.email_verified: + if obj.kind == "email" and not obj.email_verified: return "Email (unverified)" - else: - raise NotImplementedError("Bad channel kind: %s" % obj.kind) + + return obj.get_kind_display() formatted_kind.short_description = "Kind" formatted_kind.allow_tags = True diff --git a/hc/api/tests/test_admin.py b/hc/api/tests/test_admin.py index 0c4d68c9..7f55787f 100644 --- a/hc/api/tests/test_admin.py +++ b/hc/api/tests/test_admin.py @@ -15,8 +15,17 @@ class ApiAdminTestCase(BaseTestCase): def test_it_shows_channel_list_with_pushbullet(self): self.client.login(username="alice@example.org", password="password") - ch = Channel(user=self.alice, kind="pushbullet", value="test-token") - ch.save() + Channel.objects.create(user=self.alice, kind="pushbullet", + value="test-token") r = self.client.get("/admin/api/channel/") self.assertContains(r, "Pushbullet") + + def test_it_shows_channel_list_with_unverified_email(self): + self.client.login(username="alice@example.org", password="password") + + Channel.objects.create(user=self.alice, kind="email", + value="foo@example.org") + + r = self.client.get("/admin/api/channel/") + self.assertContains(r, "Email (unverified)") diff --git a/templates/front/channels.html b/templates/front/channels.html index e43748ca..41159478 100644 --- a/templates/front/channels.html +++ b/templates/front/channels.html @@ -26,18 +26,7 @@ {% for ch in channels %} - - {% if ch.kind == "email" %} Email - {% elif ch.kind == "webhook" %} Webhook - {% elif ch.kind == "slack" %} Slack - {% elif ch.kind == "hipchat" %} HipChat - {% elif ch.kind == "pd" %} PagerDuty - {% elif ch.kind == "po" %} Pushover - {% elif ch.kind == "victorops" %} VictorOps - {% elif ch.kind == "pushbullet" %} Pushbullet - {% elif ch.kind == "opsgenie" %} OpsGenie - {% elif ch.kind == "discord" %} Discord {% endif %} - + {{ ch.get_kind_display }} {% if ch.kind == "email" %} to