Browse Source

Fix crash on /members/contact when no chatroom specified

Part of bugs revealed by upgrade to Django 1.8

Added tests.

Ref https://code.ffdn.org/FFDN/coin/pulls/99#issuecomment-399
Jocelyn Delalande 8 years ago
parent
commit
636bceb6b3
2 changed files with 13 additions and 2 deletions
  1. 7 2
      coin/isp_database/models.py
  2. 6 0
      coin/isp_database/tests.py

+ 7 - 2
coin/isp_database/models.py

@@ -115,8 +115,13 @@ class ISPInfo(SingleInstanceMixin, models.Model):
 
     @property
     def main_chat_verbose(self):
-        m = utils.re_chat_url.match(self.chatroom_set.first().url)
-        return '{channel} sur {server}'.format(**(m.groupdict()))
+        first_chatroom = self.chatroom_set.first()
+        if first_chatroom:
+            m = utils.re_chat_url.match(first_chatroom.url)
+            if m:
+                return '{channel} sur {server}'.format(**(m.groupdict()))
+
+        return None
 
     def get_absolute_url(self):
         return '/isp.json'

+ 6 - 0
coin/isp_database/tests.py

@@ -28,6 +28,12 @@ class TestContactPage(TestCase):
 
     def test_chat_view(self):
         isp = ISPInfo.objects.create(name='test', email='foo@example.com', )
+
+        # Without chatroom
+        response = self.client.get('/members/contact/')
+        self.assertEqual(response.status_code, 200)
+
+        # With chatroom
         ChatRoom.objects.create(
             isp=isp, url='irc://irc.example.com/#chan')