[damned-lies] Fix a crash when a branch name does not exist



commit ea1a2b557c610655c35fed74c182cd15ebf7e269
Author: Claude Paroz <claude 2xlibre net>
Date:   Sat Dec 3 10:39:36 2016 +0100

    Fix a crash when a branch name does not exist

 damnedlies/urls.py   |    3 ++-
 stats/tests/tests.py |    7 +++++++
 stats/views.py       |    2 +-
 3 files changed, 10 insertions(+), 2 deletions(-)
---
diff --git a/damnedlies/urls.py b/damnedlies/urls.py
index ba7ad51..e35f67d 100644
--- a/damnedlies/urls.py
+++ b/damnedlies/urls.py
@@ -72,7 +72,8 @@ urlpatterns += [
         stats_views.module_edit_branches,
         name='module_edit_branches'),
     url(r'^module/(?P<module_name>[\w\-\+]+)/branch/(?P<branch_name>[\w\-\.]+)/$',
-        stats_views.module_branch),
+        stats_views.module_branch,
+        name='module_branch'),
     url(r'^branch/(?P<branch_id>\d+)/refresh/$',
         stats_views.branch_refresh,
         name='branch_refresh'),
diff --git a/stats/tests/tests.py b/stats/tests/tests.py
index e4a2194..08e121b 100644
--- a/stats/tests/tests.py
+++ b/stats/tests/tests.py
@@ -124,6 +124,13 @@ class ModuleTestCase(TestCase):
         self.assertEqual(len(content), Module.objects.count())
         self.assertEqual(content[-1]["fields"]["vcs_root"], 'git://git.gnome.org/zenity')
 
+    def test_module_branch(self):
+        response = self.client.get(reverse('module_branch', args=['gnome-hello', 'master']))
+        self.assertContains(response, '<table class="stats table">')
+        # Missing branch
+        response = self.client.get(reverse('module_branch', args=['gnome-hello', 'missing']))
+        self.assertEqual(response.status_code, 404)
+
     def test_branch_methods(self):
         self.assertTrue(self.branch.is_head())
         self.assertEqual(self.branch.get_vcs_url(), "git://git.gnome.org/gnome-hello")
diff --git a/stats/views.py b/stats/views.py
index b62cdff..be1e1fe 100644
--- a/stats/views.py
+++ b/stats/views.py
@@ -74,7 +74,7 @@ def module(request, module_name):
 def module_branch(request, module_name, branch_name):
     """ This view is used to dynamically load a specific branch stats (jquery.load) """
     mod = get_object_or_404(Module, name=module_name)
-    branch = mod.branch_set.get(name=branch_name)
+    branch = get_object_or_404(mod.branch_set, name=branch_name)
     if request.user.is_authenticated():
         person = Person.get_by_user(request.user)
         langs = person.get_languages()


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]