Merge lp:~linaro-infrastructure/linaro-ci-dashboard/view-tests-extension into lp:linaro-ci-dashboard

Proposed by Stevan Radaković
Status: Merged
Merged at revision: 17
Proposed branch: lp:~linaro-infrastructure/linaro-ci-dashboard/view-tests-extension
Merge into: lp:linaro-ci-dashboard
Diff against target: 196 lines (+116/-21)
3 files modified
dashboard/frontend/tests/test_clientresponse.py (+45/-1)
dashboard/frontend/tests/test_custom_commands.py (+21/-0)
dashboard/frontend/tests/test_views.py (+50/-20)
To merge this branch: bzr merge lp:~linaro-infrastructure/linaro-ci-dashboard/view-tests-extension
Reviewer Review Type Date Requested Status
Deepti B. Kalakeri (community) Approve
Review via email: mp+117082@code.launchpad.net

Description of the change

Add more view and client tests for the new frontend code.

To post a comment you must log in.
Revision history for this message
Deepti B. Kalakeri (deeptik) wrote :

Thanks for working on them. Changes looks good, except for the following:

 63 class IntegrationLoopDetailViewTest(TestCase):
 64
 65 def setUp(self):
 66 self.mock_loop = Mock()
 67 self.mock_loop.loop_ptr = Mock()
 68 self.mock_loop.loop_ptr = Mock()

self.mock_loop.loop_ptr = Mock() has been defined twice, remove one of them and merge it.

review: Approve
18. By Stevan Radaković

Code review fixes.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'dashboard/frontend/tests/test_clientresponse.py'
2--- dashboard/frontend/tests/test_clientresponse.py 2012-07-19 10:44:27 +0000
3+++ dashboard/frontend/tests/test_clientresponse.py 2012-07-28 02:29:17 +0000
4@@ -19,7 +19,7 @@
5 from django.test import TestCase
6 from django.contrib.auth.models import User, Group
7 from django.test.client import Client
8-
9+import urllib
10
11 class ClientResponseTests(TestCase):
12
13@@ -32,6 +32,11 @@
14 self.user = User.objects.create_user(self.user,
15 self.email, self.passwd)
16 self.group = Group.objects.create(name=self.group)
17+ self.integration_loop_data = {"name" : "testjob",
18+ "branch" : "lp:linaro-ci-dashboard",
19+ "precommand" : "make migrate",
20+ "command" : "make test",
21+ }
22
23 def tearDown(self):
24 user = User.objects.filter(username=self.user)
25@@ -62,3 +67,42 @@
26 self.assertIn(str(self.user), response.content)
27 response = self.client.get('/home/')
28 self.assertIn(str(self.user), response.content)
29+
30+ def test_integration_loop_create_get(self):
31+ self.client.login(username=self.user, password=self.passwd)
32+ response = self.client.get("/integration_loop/create/")
33+ self.assertIn("/integration_loop/create/", response.content)
34+ template_names = [template.name for template in
35+ response.templates]
36+ self.assertEquals(template_names, ["integration_loop_create.html",
37+ "header.html"])
38+
39+ def test_integration_loop_create_post_no_data(self):
40+ self.client.login(username=self.user, password=self.passwd)
41+ response = self.client.post("/integration_loop/create/", {})
42+ self.assertEquals(response.status_code, 200)
43+ self.assertIn("This field is required", response.content)
44+
45+ def test_integration_loop_create_post(self):
46+ self.client.login(username=self.user, password=self.passwd)
47+
48+ # Follow redirect after save.
49+ response = self.client.post("/integration_loop/create/",
50+ self.integration_loop_data, follow=True)
51+ # Assert response code.
52+ self.assertEquals(response.status_code, 200)
53+ # Assert redirect chain.
54+ self.assertEquals(response.redirect_chain[0][1], 302)
55+ self.assertIn(urllib.quote(self.integration_loop_data["name"]),
56+ response.redirect_chain[0][0])
57+ # Assert template names for detail page.
58+ template_names = [template.name for template in
59+ response.templates]
60+ self.assertEquals(template_names, ["integration_loop_detail.html",
61+ "header.html"])
62+ # Assert if everything is present on detail page.
63+ self.assertIn(self.integration_loop_data["name"], response.content)
64+ self.assertIn(self.integration_loop_data["branch"], response.content)
65+ self.assertIn(self.integration_loop_data["precommand"],
66+ response.content)
67+ self.assertIn(self.integration_loop_data["command"], response.content)
68
69=== modified file 'dashboard/frontend/tests/test_custom_commands.py'
70--- dashboard/frontend/tests/test_custom_commands.py 2012-07-19 10:44:27 +0000
71+++ dashboard/frontend/tests/test_custom_commands.py 2012-07-28 02:29:17 +0000
72@@ -17,6 +17,8 @@
73 # along with linaro-ci-dashboard. If not, see <http://www.gnu.org/licenses/>.
74
75 import frontend.management.commands.jenkins as jenkins
76+import frontend.management.commands.setsuperuser as setsuperuser
77+from django.contrib.auth.models import User
78 from django.core.management.base import CommandError
79 from django.conf import settings
80 from subprocess import CalledProcessError
81@@ -28,6 +30,25 @@
82 import shutil
83
84
85+class SetsuperuserCommandTest(TestCase):
86+
87+ def setUp(self):
88+ self.command = setsuperuser.Command()
89+
90+ def test_find_and_update_user_non_existing(self):
91+ self.assertRaises(CommandError,
92+ self.command.find_and_update_user,
93+ ("non_existing_user"))
94+
95+ def test_find_and_update_user(self):
96+ user = User(username="existing_user")
97+ user.save()
98+ self.command.find_and_update_user("existing_user")
99+ user = User.objects.get(username="existing_user")
100+ self.assertEquals(user.is_staff, True)
101+ self.assertEquals(user.is_superuser, True)
102+
103+
104 class JenkinsCommandTest(TestCase):
105
106 orig_dir = os.getcwd()
107
108=== modified file 'dashboard/frontend/tests/test_views.py'
109--- dashboard/frontend/tests/test_views.py 2012-07-09 19:27:50 +0000
110+++ dashboard/frontend/tests/test_views.py 2012-07-28 02:29:17 +0000
111@@ -15,14 +15,17 @@
112 #
113 # You should have received a copy of the GNU Affero General Public License
114 # along with linaro-ci-dashboard. If not, see <http://www.gnu.org/licenses/>.
115-from django.core.management.base import CommandError
116-from django.contrib.auth.models import User
117 from django.test import TestCase
118 from mock import Mock, patch
119
120-import frontend.management.commands.setsuperuser as setsuperuser
121 from frontend.views.home_page_view import HomePageView
122 from frontend.views.index_view import IndexView
123+from frontend.views.integration_loop_create_view \
124+ import IntegrationLoopCreateView
125+from frontend.views.integration_loop_update_view \
126+ import IntegrationLoopUpdateView
127+from frontend.views.integration_loop_detail_view \
128+ import IntegrationLoopDetailView
129
130
131 class HomePageViewTest(TestCase):
132@@ -43,20 +46,47 @@
133 self.assertEqual(context['request'], "some request data")
134
135
136-class SetsuperuserCommandTest(TestCase):
137-
138- def setUp(self):
139- self.command = setsuperuser.Command()
140-
141- def test_find_and_update_user_non_existing(self):
142- self.assertRaises(CommandError,
143- self.command.find_and_update_user,
144- ("non_existing_user"))
145-
146- def test_find_and_update_user(self):
147- user = User(username="existing_user")
148- user.save()
149- self.command.find_and_update_user("existing_user")
150- user = User.objects.get(username="existing_user")
151- self.assertEquals(user.is_staff, True)
152- self.assertEquals(user.is_superuser, True)
153+class IntegrationLoopCreateViewTest(TestCase):
154+
155+ def setUp(self):
156+ self.mock_loop = Mock()
157+
158+ def test_get_context_data(self):
159+ integration_loop_create_view = IntegrationLoopCreateView()
160+ integration_loop_create_view.request = "some request data"
161+ integration_loop_create_view.object = self.mock_loop
162+ context = IntegrationLoopCreateView.get_context_data(
163+ integration_loop_create_view)
164+ self.assertEqual(context['request'], "some request data")
165+
166+
167+class IntegrationLoopDetailViewTest(TestCase):
168+
169+ def setUp(self):
170+ self.mock_loop = Mock()
171+ self.mock_loop.loop_ptr = Mock()
172+ self.mock_loop.loop_ptr.loopbuild_set = Mock()
173+ self.mock_loop.loop_ptr.loopbuild_set.all = Mock()
174+
175+ def test_get_context_data(self):
176+ integration_loop_detail_view = IntegrationLoopDetailView()
177+ integration_loop_detail_view.request = "some request data"
178+ integration_loop_detail_view.object = self.mock_loop
179+ context = IntegrationLoopDetailView.get_context_data(
180+ integration_loop_detail_view)
181+ self.assertEqual(context['request'], "some request data")
182+ self.assertEqual(context['builds'].__class__.__name__, "Mock")
183+
184+
185+class IntegrationLoopUpdateViewTest(TestCase):
186+
187+ def setUp(self):
188+ self.mock_loop = Mock()
189+
190+ def test_get_context_data(self):
191+ integration_loop_update_view = IntegrationLoopUpdateView()
192+ integration_loop_update_view.request = "some request data"
193+ integration_loop_update_view.object = self.mock_loop
194+ context = IntegrationLoopUpdateView.get_context_data(
195+ integration_loop_update_view)
196+ self.assertEqual(context['request'], "some request data")

Subscribers

People subscribed via source and target branches

to all changes: