Merge lp:~milo/linaro-ci-dashboard/simple-mock into lp:linaro-ci-dashboard

Proposed by Milo Casagrande
Status: Merged
Approved by: Stevan Radaković
Approved revision: 50
Merged at revision: 50
Proposed branch: lp:~milo/linaro-ci-dashboard/simple-mock
Merge into: lp:linaro-ci-dashboard
Diff against target: 650 lines (+328/-152)
12 files modified
Makefile (+2/-2)
dashboard/frontend/android_build/tests/test_android_build_views.py (+9/-15)
dashboard/frontend/android_textfield_loop/tests/test_android_textfield_views.py (+9/-9)
dashboard/frontend/integration_loop/tests/__init__.py (+27/-0)
dashboard/frontend/integration_loop/tests/test_integration_loop_clientresponse.py (+75/-0)
dashboard/frontend/integration_loop/tests/test_integration_loop_views.py (+56/-0)
dashboard/frontend/kernel_build/tests/test_kernel_build_views.py (+9/-13)
dashboard/frontend/tests/__init__.py (+0/-3)
dashboard/frontend/tests/loop_mock.py (+125/-0)
dashboard/frontend/tests/test_clientresponse.py (+0/-54)
dashboard/frontend/tests/test_views.py (+15/-53)
dashboard/frontend/views/loop_detail_view.py (+1/-3)
To merge this branch: bzr merge lp:~milo/linaro-ci-dashboard/simple-mock
Reviewer Review Type Date Requested Status
Stevan Radaković Approve
Linaro Infrastructure Pending
Review via email: mp+124358@code.launchpad.net

Description of the change

In this branch I worked out a little issue we had when running the tests. Basically, with the new refactoring of the views, we are looking for objects with the query 'Loop.objects.get' that accepts parameters (in our case the primary key). The problem is that during the test we mock the other objects present in the view, so the primary key during the test is not a valid primary key for the query set.

Here I introduced a couple of very simple mocks, Python classes that inherits from MagicMock, that mimicks a Loop instance, the 'Loop.objects' query, the '_meta' field and a generic 'field'.

I refactored the tests in order to use the new mocks, and also moved the integration_loop tests under the integration_loop sub-app (before they were under the frontend main app).

To post a comment you must log in.
Revision history for this message
Stevan Radaković (stevanr) wrote :

Thanks Milo, it looks great!
Approve +1.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'Makefile'
2--- Makefile 2012-09-10 16:49:11 +0000
3+++ Makefile 2012-09-14 08:22:19 +0000
4@@ -33,7 +33,7 @@
5
6 test:
7 python dashboard/manage.py jenkins start
8- python dashboard/manage.py test frontend android_build kernel_build \
9- android_textfield_loop jenkinsserver
10+ python dashboard/manage.py test frontend android_build integration_loop \
11+ kernel_build android_textfield_loop jenkinsserver
12
13 .PHONY: help migration test
14
15=== modified file 'dashboard/frontend/android_build/tests/test_android_build_views.py'
16--- dashboard/frontend/android_build/tests/test_android_build_views.py 2012-09-12 14:31:41 +0000
17+++ dashboard/frontend/android_build/tests/test_android_build_views.py 2012-09-14 08:22:19 +0000
18@@ -14,8 +14,6 @@
19 #
20 # You should have received a copy of the GNU Affero General Public License
21 # along with linaro-ci-dashboard. If not, see <http://www.gnu.org/licenses/>.
22-from django.test import TestCase
23-from mock import MagicMock
24
25 from frontend.android_build.views.android_loop_create_view \
26 import AndroidLoopCreateView
27@@ -23,18 +21,13 @@
28 import AndroidLoopDetailView
29 from frontend.android_build.views.android_loop_update_view\
30 import AndroidLoopUpdateView
31-
32-
33-class AndroidBuildViewsTest(TestCase):
34-
35- def setUp(self):
36- self.mock_loop = MagicMock()
37- self.mock_loop.loop_ptr = MagicMock()
38- self.mock_loop.loop_ptr.id = 0
39- self.mock_loop.loop_ptr.loopbuild_set = MagicMock()
40- self.mock_loop.loop_ptr.loopbuild_set.all = MagicMock()
41- self.mock_loop.next_loop = MagicMock()
42- self.mock_loop.next_loop.id = 1
43+from frontend.tests.test_views import (
44+ ViewsTestsGeneral,
45+ LoopMock
46+)
47+
48+
49+class AndroidBuildViewsTest(ViewsTestsGeneral):
50
51 def test_create_view_get_context_data(self):
52 android_loop_create_view = AndroidLoopCreateView()
53@@ -51,7 +44,8 @@
54 context = AndroidLoopDetailView.get_context_data(
55 android_loop_detail_view)
56 self.assertEqual(context['request'], "some request data")
57- self.assertEqual(context['builds'].__class__.__name__, "MagicMock")
58+ self.assertEqual(context['builds'].__class__.__name__,
59+ LoopMock.__name__)
60
61 def test_update_view_get_context_data(self):
62 android_loop_update_view = AndroidLoopUpdateView()
63
64=== modified file 'dashboard/frontend/android_textfield_loop/tests/test_android_textfield_views.py'
65--- dashboard/frontend/android_textfield_loop/tests/test_android_textfield_views.py 2012-09-10 07:45:21 +0000
66+++ dashboard/frontend/android_textfield_loop/tests/test_android_textfield_views.py 2012-09-14 08:22:19 +0000
67@@ -14,8 +14,6 @@
68 #
69 # You should have received a copy of the GNU Affero General Public License
70 # along with linaro-ci-dashboard. If not, see <http://www.gnu.org/licenses/>.
71-from django.test import TestCase
72-from mock import MagicMock
73
74 from frontend.android_textfield_loop.views.android_textfield_loop_create_view \
75 import AndroidTextFieldLoopCreateView
76@@ -23,12 +21,13 @@
77 import AndroidTextFieldLoopDetailView
78 from frontend.android_textfield_loop.views.android_textfield_loop_update_view \
79 import AndroidTextFieldLoopUpdateView
80-
81-
82-class AndroidTextFieldViewsTest(TestCase):
83-
84- def setUp(self):
85- self.mock_loop = MagicMock()
86+from frontend.tests.test_views import (
87+ ViewsTestsGeneral,
88+ LoopMock,
89+)
90+
91+
92+class AndroidTextFieldViewsTest(ViewsTestsGeneral):
93
94 def test_create_view_get_context_data(self):
95 android_textfield_create_view = AndroidTextFieldLoopCreateView()
96@@ -45,7 +44,8 @@
97 context = AndroidTextFieldLoopDetailView.get_context_data(
98 android_textfield_detail_view)
99 self.assertEqual(context['request'], "some request data")
100- self.assertEqual(context['builds'].__class__.__name__, "MagicMock")
101+ self.assertEqual(context['builds'].__class__.__name__,
102+ LoopMock.__name__)
103
104 def test_update_view_get_context_data(self):
105 android_textfield_update_view = AndroidTextFieldLoopUpdateView()
106
107=== added directory 'dashboard/frontend/integration_loop/tests'
108=== added file 'dashboard/frontend/integration_loop/tests/__init__.py'
109--- dashboard/frontend/integration_loop/tests/__init__.py 1970-01-01 00:00:00 +0000
110+++ dashboard/frontend/integration_loop/tests/__init__.py 2012-09-14 08:22:19 +0000
111@@ -0,0 +1,27 @@
112+# Copyright (C) 2012 Linaro
113+#
114+# This file is part of linaro-ci-dashboard.
115+#
116+# linaro-ci-dashboard is free software: you can redistribute it and/or modify
117+# it under the terms of the GNU Affero General Public License as published by
118+# the Free Software Foundation, either version 3 of the License, or
119+# (at your option) any later version.
120+#
121+# linaro-ci-dashboard is distributed in the hope that it will be useful,
122+# but WITHOUT ANY WARRANTY; without even the implied warranty of
123+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
124+# GNU Affero General Public License for more details.
125+#
126+# You should have received a copy of the GNU Affero General Public License
127+# along with linaro-ci-dashboard. If not, see <http://www.gnu.org/licenses/>.
128+
129+from dashboard.frontend.integration_loop.tests.test_integration_loop_views \
130+ import *
131+from dashboard.frontend.integration_loop.tests.\
132+ test_integration_loop_clientresponse import *
133+
134+
135+__test__ = {
136+ 'IntegrationLoopViewsTest': IntegrationLoopViewsTest,
137+ 'IntegrationLoopClientresponseTest': IntegrationLoopClientresponseTest,
138+}
139\ No newline at end of file
140
141=== added file 'dashboard/frontend/integration_loop/tests/test_integration_loop_clientresponse.py'
142--- dashboard/frontend/integration_loop/tests/test_integration_loop_clientresponse.py 1970-01-01 00:00:00 +0000
143+++ dashboard/frontend/integration_loop/tests/test_integration_loop_clientresponse.py 2012-09-14 08:22:19 +0000
144@@ -0,0 +1,75 @@
145+# Copyright (C) 2012 Linaro
146+#
147+# This file is part of linaro-ci-dashboard.
148+#
149+# linaro-ci-dashboard is free software: you can redistribute it and/or modify
150+# it under the terms of the GNU Affero General Public License as published by
151+# the Free Software Foundation, either version 3 of the License, or
152+# (at your option) any later version.
153+#
154+# linaro-ci-dashboard is distributed in the hope that it will be useful,
155+# but WITHOUT ANY WARRANTY; without even the implied warranty of
156+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
157+# GNU Affero General Public License for more details.
158+#
159+# You should have received a copy of the GNU Affero General Public License
160+# along with linaro-ci-dashboard. If not, see <http://www.gnu.org/licenses/>.
161+
162+import urllib
163+from frontend.tests.test_clientresponse import ClientResponseTestsGeneral
164+
165+
166+class IntegrationLoopClientresponseTest(ClientResponseTestsGeneral):
167+
168+ def setUp(self):
169+ super(IntegrationLoopClientresponseTest, self).setUp()
170+ self.integration_loop_data = {"name": "testjob",
171+ "branch": "lp:linaro-ci-dashboard",
172+ "precommand": "make migrate",
173+ "command": "make test",
174+ "next_loop_0": "",
175+ }
176+
177+ def test_integration_loop_create_get(self):
178+ self.client.login(username=self.user, password=self.passwd)
179+ response = self.client.get("/integration_loop/create/")
180+ self.assertIn("/integration_loop/create/", response.content)
181+ template_names = [template.name for template in
182+ response.templates]
183+ self.assertEquals(template_names, ["integration_loop_create.html",
184+ "loop_create.html",
185+ "base.html",
186+ "login.html",
187+ ])
188+
189+ def test_integration_loop_create_post_no_data(self):
190+ self.client.login(username=self.user, password=self.passwd)
191+ response = self.client.post("/integration_loop/create/", {})
192+ self.assertEquals(response.status_code, 200)
193+ self.assertIn("This field is required", response.content)
194+
195+ def test_integration_loop_create_post(self):
196+ self.client.login(username=self.user, password=self.passwd)
197+
198+ # Follow redirect after save.
199+ response = self.client.post("/integration_loop/create/",
200+ self.integration_loop_data, follow=True)
201+ # Assert response code.
202+ self.assertEquals(response.status_code, 200)
203+ # Assert redirect chain.
204+ self.assertEquals(response.redirect_chain[0][1], 302)
205+ self.assertIn(urllib.quote(self.integration_loop_data["name"]),
206+ response.redirect_chain[0][0])
207+ # Assert template names for detail page.
208+ template_names = [template.name for template in
209+ response.templates]
210+ self.assertEquals(template_names, ["loop_detail.html",
211+ "base.html",
212+ "login.html",
213+ ])
214+ # Assert if everything is present on detail page.
215+ self.assertIn(self.integration_loop_data["name"], response.content)
216+ self.assertIn(self.integration_loop_data["branch"], response.content)
217+ self.assertIn(self.integration_loop_data["precommand"],
218+ response.content)
219+ self.assertIn(self.integration_loop_data["command"], response.content)
220\ No newline at end of file
221
222=== added file 'dashboard/frontend/integration_loop/tests/test_integration_loop_views.py'
223--- dashboard/frontend/integration_loop/tests/test_integration_loop_views.py 1970-01-01 00:00:00 +0000
224+++ dashboard/frontend/integration_loop/tests/test_integration_loop_views.py 2012-09-14 08:22:19 +0000
225@@ -0,0 +1,56 @@
226+# Copyright (C) 2012 Linaro
227+#
228+# This file is part of linaro-ci-dashboard.
229+#
230+# linaro-ci-dashboard is free software: you can redistribute it and/or modify
231+# it under the terms of the GNU Affero General Public License as published by
232+# the Free Software Foundation, either version 3 of the License, or
233+# (at your option) any later version.
234+#
235+# linaro-ci-dashboard is distributed in the hope that it will be useful,
236+# but WITHOUT ANY WARRANTY; without even the implied warranty of
237+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
238+# GNU Affero General Public License for more details.
239+#
240+# You should have received a copy of the GNU Affero General Public License
241+# along with linaro-ci-dashboard. If not, see <http://www.gnu.org/licenses/>.
242+
243+from frontend.integration_loop.views.integration_loop_create_view \
244+ import IntegrationLoopCreateView
245+from frontend.integration_loop.views.integration_loop_update_view \
246+ import IntegrationLoopUpdateView
247+from frontend.integration_loop.views.integration_loop_detail_view \
248+ import IntegrationLoopDetailView
249+from frontend.tests.test_views import (
250+ ViewsTestsGeneral,
251+ LoopMock,
252+)
253+
254+
255+class IntegrationLoopViewsTest(ViewsTestsGeneral):
256+
257+ def test_create_view_get_context_data(self):
258+ integration_loop_create_view = IntegrationLoopCreateView()
259+ integration_loop_create_view.request = "some request data"
260+ integration_loop_create_view.object = self.mock_loop
261+ context = IntegrationLoopCreateView.get_context_data(
262+ integration_loop_create_view)
263+ self.assertEqual(context['request'], "some request data")
264+
265+ def test_detail_view_get_context_data(self):
266+ integration_loop_detail_view = IntegrationLoopDetailView()
267+ integration_loop_detail_view.request = "some request data"
268+ integration_loop_detail_view.object = self.mock_loop
269+ context = IntegrationLoopDetailView.get_context_data(
270+ integration_loop_detail_view)
271+ self.assertEqual(context['request'], "some request data")
272+ self.assertEqual(context['builds'].__class__.__name__,
273+ LoopMock.__name__)
274+
275+ def test_update_view_get_context_data(self):
276+ integration_loop_update_view = IntegrationLoopUpdateView()
277+ integration_loop_update_view.request = "some request data"
278+ integration_loop_update_view.object = self.mock_loop
279+ context = IntegrationLoopUpdateView.get_context_data(
280+ integration_loop_update_view)
281+ self.assertEqual(context['request'], "some request data")
282
283=== modified file 'dashboard/frontend/kernel_build/tests/test_kernel_build_views.py'
284--- dashboard/frontend/kernel_build/tests/test_kernel_build_views.py 2012-08-23 11:22:21 +0000
285+++ dashboard/frontend/kernel_build/tests/test_kernel_build_views.py 2012-09-14 08:22:19 +0000
286@@ -14,8 +14,6 @@
287 #
288 # You should have received a copy of the GNU Affero General Public License
289 # along with linaro-ci-dashboard. If not, see <http://www.gnu.org/licenses/>.
290-from django.test import TestCase
291-from mock import MagicMock
292
293 from frontend.kernel_build.views.kernel_loop_create_view \
294 import KernelLoopCreateView
295@@ -23,16 +21,13 @@
296 import KernelLoopDetailView
297 from frontend.kernel_build.views.kernel_loop_update_view\
298 import KernelLoopUpdateView
299-
300-
301-class KernelBuildViewsTest(TestCase):
302-
303- def setUp(self):
304- self.mock_loop = MagicMock()
305- self.mock_loop.loop_ptr = MagicMock()
306- self.mock_loop.loop_ptr.id = 0
307- self.mock_loop.loop_ptr.loopbuild_set = MagicMock()
308- self.mock_loop.loop_ptr.loopbuild_set.all = MagicMock()
309+from frontend.tests.test_views import (
310+ ViewsTestsGeneral,
311+ LoopMock,
312+)
313+
314+
315+class KernelBuildViewsTest(ViewsTestsGeneral):
316
317 def test_create_view_get_context_data(self):
318 kernel_loop_create_view = KernelLoopCreateView()
319@@ -49,7 +44,8 @@
320 context = KernelLoopDetailView.get_context_data(
321 kernel_loop_detail_view)
322 self.assertEqual(context['request'], "some request data")
323- self.assertEqual(context['builds'].__class__.__name__, "MagicMock")
324+ self.assertEqual(context['builds'].__class__.__name__,
325+ LoopMock.__name__)
326
327 def test_update_view_get_context_data(self):
328 kernel_loop_update_view = KernelLoopUpdateView()
329
330=== modified file 'dashboard/frontend/tests/__init__.py'
331--- dashboard/frontend/tests/__init__.py 2012-09-05 17:32:44 +0000
332+++ dashboard/frontend/tests/__init__.py 2012-09-14 08:22:19 +0000
333@@ -9,9 +9,6 @@
334 __test__ = {
335 'HomePageViewTests': HomePageViewTest,
336 'IndexViewTests': IndexViewTest,
337- 'IntegrationLoopCreateViewTests': IntegrationLoopCreateViewTest,
338- 'IntegrationLoopDetailViewTests': IntegrationLoopDetailViewTest,
339- 'IntegrationLoopUpdateViewTests': IntegrationLoopUpdateViewTest,
340 'LoopTests': LoopTest,
341 'ClientResponseTests': ClientResponseTests,
342 'JenkinsCommandTest': JenkinsCommandTest,
343
344=== added file 'dashboard/frontend/tests/loop_mock.py'
345--- dashboard/frontend/tests/loop_mock.py 1970-01-01 00:00:00 +0000
346+++ dashboard/frontend/tests/loop_mock.py 2012-09-14 08:22:19 +0000
347@@ -0,0 +1,125 @@
348+# Copyright (C) 2012 Linaro
349+#
350+# This file is part of linaro-ci-dashboard.
351+#
352+# linaro-ci-dashboard is free software: you can redistribute it and/or modify
353+# it under the terms of the GNU Affero General Public License as published by
354+# the Free Software Foundation, either version 3 of the License, or
355+# (at your option) any later version.
356+#
357+# linaro-ci-dashboard is distributed in the hope that it will be useful,
358+# but WITHOUT ANY WARRANTY; without even the implied warranty of
359+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
360+# GNU Affero General Public License for more details.
361+#
362+# You should have received a copy of the GNU Affero General Public License
363+# along with linaro-ci-dashboard. If not, see <http://www.gnu.org/licenses/>.
364+
365+from mock import MagicMock
366+
367+
368+class ObjectsMock(MagicMock):
369+ """
370+ This mock represents the 'objects' queryset of a Django model. It is
371+ basically used to mock access like 'MODEL.objects' when looking up
372+ a specific model.
373+ """
374+ def __init__(self, *args, **kwargs):
375+ super(ObjectsMock, self).__init__(*args, **kwargs)
376+
377+ def get(self, *args, **kwargs):
378+ return LoopMock()
379+
380+ def all(self):
381+ return [LoopMock()]
382+
383+
384+class LoopMock(MagicMock):
385+ """
386+ Class that mocks a generic Loop object. This class should be used when it
387+ is necessary to pass an actual object.
388+ """
389+ def __init__(self, *args, **kwargs):
390+ super(LoopMock, self).__init__(*args, **kwargs)
391+
392+ @property
393+ def name(self):
394+ return self.__class__.__name__
395+
396+ @property
397+ def type(self):
398+ return self.__class__.__name__
399+
400+ @property
401+ def is_restricted(self):
402+ return False
403+
404+ @property
405+ def is_protected(self):
406+ return False
407+
408+ @property
409+ def _meta(self):
410+ return MetaMock()
411+
412+
413+class MetaMock(MagicMock):
414+ """
415+ Mock class that represents the Meta class of a Django model, accessed via
416+ the _meta attribute of a model instance.
417+ """
418+ def __init__(self, *args, **kwargs):
419+ super(MetaMock, self).__init__(*args, **kwargs)
420+
421+ @property
422+ def app_label(self):
423+ return "label"
424+
425+ def get_field(self, name=None):
426+ """
427+ Mocks the get_field method of _meta.
428+
429+ :param name: The name of the field to get back.
430+ :type name str
431+ :return A FieldMock object mocking a field.
432+ """
433+ return FieldMock(name=name)
434+
435+
436+class FieldMock(MagicMock):
437+ """
438+ Mock class that represents a field in a class model.
439+ """
440+ def __init__(self, name=None, verbose_name=None, *args, **kwargs):
441+ """
442+ Initialized the field mock. By default, if passed with no arguments,
443+ the field name and verbose name will be set to the class name.
444+
445+ :param name: The name associated with this field.
446+ :type name str
447+ :param verbose_name: The verbose name associated with this field.
448+ :type verbose_name str
449+ """
450+ super(FieldMock, self).__init__(*args, **kwargs)
451+ if name is not None:
452+ self._name = name
453+ else:
454+ self._name = self.__class__.__name__
455+ if verbose_name is not None:
456+ self._verbose_name = verbose_name
457+ else:
458+ self._verbose_name = self.__class__.__name__
459+
460+ @property
461+ def name(self):
462+ """
463+ :return The name of the field.
464+ """
465+ return self._name
466+
467+ @property
468+ def verbose_name(self):
469+ """
470+ :return The verbose name associated with the field.
471+ """
472+ return self._verbose_name
473
474=== modified file 'dashboard/frontend/tests/test_clientresponse.py'
475--- dashboard/frontend/tests/test_clientresponse.py 2012-09-12 13:15:13 +0000
476+++ dashboard/frontend/tests/test_clientresponse.py 2012-09-14 08:22:19 +0000
477@@ -19,7 +19,6 @@
478 from django.test import TestCase
479 from django.contrib.auth.models import User, Group
480 from django.test.client import Client
481-import urllib
482
483
484 class ClientResponseTestsGeneral(TestCase):
485@@ -44,15 +43,6 @@
486
487 class ClientResponseTests(ClientResponseTestsGeneral):
488
489- def setUp(self):
490- super(ClientResponseTests, self).setUp()
491- self.integration_loop_data = {"name": "testjob",
492- "branch": "lp:linaro-ci-dashboard",
493- "precommand": "make migrate",
494- "command": "make test",
495- "next_loop_0": "",
496- }
497-
498 # Test case should fail if the login_required decorator source code
499 # in index_view.py is removed.
500 def test_response_index_when_user_not_auth_by_login_required(self):
501@@ -74,47 +64,3 @@
502 self.assertIn(str(self.user), response.content)
503 response = self.client.get('/home/')
504 self.assertIn(str(self.user), response.content)
505-
506- def test_integration_loop_create_get(self):
507- self.client.login(username=self.user, password=self.passwd)
508- response = self.client.get("/integration_loop/create/")
509- self.assertIn("/integration_loop/create/", response.content)
510- template_names = [template.name for template in
511- response.templates]
512- self.assertEquals(template_names, ["integration_loop_create.html",
513- "loop_create.html",
514- "base.html",
515- "login.html",
516- ])
517-
518- def test_integration_loop_create_post_no_data(self):
519- self.client.login(username=self.user, password=self.passwd)
520- response = self.client.post("/integration_loop/create/", {})
521- self.assertEquals(response.status_code, 200)
522- self.assertIn("This field is required", response.content)
523-
524- def test_integration_loop_create_post(self):
525- self.client.login(username=self.user, password=self.passwd)
526-
527- # Follow redirect after save.
528- response = self.client.post("/integration_loop/create/",
529- self.integration_loop_data, follow=True)
530- # Assert response code.
531- self.assertEquals(response.status_code, 200)
532- # Assert redirect chain.
533- self.assertEquals(response.redirect_chain[0][1], 302)
534- self.assertIn(urllib.quote(self.integration_loop_data["name"]),
535- response.redirect_chain[0][0])
536- # Assert template names for detail page.
537- template_names = [template.name for template in
538- response.templates]
539- self.assertEquals(template_names, ["loop_detail.html",
540- "base.html",
541- "login.html",
542- ])
543- # Assert if everything is present on detail page.
544- self.assertIn(self.integration_loop_data["name"], response.content)
545- self.assertIn(self.integration_loop_data["branch"], response.content)
546- self.assertIn(self.integration_loop_data["precommand"],
547- response.content)
548- self.assertIn(self.integration_loop_data["command"], response.content)
549
550=== modified file 'dashboard/frontend/tests/test_views.py'
551--- dashboard/frontend/tests/test_views.py 2012-08-16 15:38:48 +0000
552+++ dashboard/frontend/tests/test_views.py 2012-09-14 08:22:19 +0000
553@@ -15,17 +15,25 @@
554 #
555 # You should have received a copy of the GNU Affero General Public License
556 # along with linaro-ci-dashboard. If not, see <http://www.gnu.org/licenses/>.
557+
558 from django.test import TestCase
559-from mock import Mock, patch
560
561 from frontend.views.home_page_view import HomePageView
562 from frontend.views.index_view import IndexView
563-from frontend.integration_loop.views.integration_loop_create_view \
564- import IntegrationLoopCreateView
565-from frontend.integration_loop.views.integration_loop_update_view \
566- import IntegrationLoopUpdateView
567-from frontend.integration_loop.views.integration_loop_detail_view \
568- import IntegrationLoopDetailView
569+from frontend.tests.loop_mock import (
570+ ObjectsMock,
571+ LoopMock,
572+)
573+from frontend.models.loop import Loop
574+
575+
576+class ViewsTestsGeneral(TestCase):
577+ def setUp(self):
578+ self.mock_loop = LoopMock()
579+ Loop.objects = ObjectsMock()
580+
581+ def tearDown(self):
582+ super(ViewsTestsGeneral, self).tearDown()
583
584
585 class HomePageViewTest(TestCase):
586@@ -44,49 +52,3 @@
587 index_view.request = "some request data"
588 context = IndexView.get_context_data(index_view)
589 self.assertEqual(context['request'], "some request data")
590-
591-
592-class IntegrationLoopCreateViewTest(TestCase):
593-
594- def setUp(self):
595- self.mock_loop = Mock()
596-
597- def test_get_context_data(self):
598- integration_loop_create_view = IntegrationLoopCreateView()
599- integration_loop_create_view.request = "some request data"
600- integration_loop_create_view.object = self.mock_loop
601- context = IntegrationLoopCreateView.get_context_data(
602- integration_loop_create_view)
603- self.assertEqual(context['request'], "some request data")
604-
605-
606-class IntegrationLoopDetailViewTest(TestCase):
607-
608- def setUp(self):
609- self.mock_loop = Mock()
610- self.mock_loop.loop_ptr = Mock()
611- self.mock_loop.loop_ptr.loopbuild_set = Mock()
612- self.mock_loop.loop_ptr.loopbuild_set.all = Mock()
613-
614- def test_get_context_data(self):
615- integration_loop_detail_view = IntegrationLoopDetailView()
616- integration_loop_detail_view.request = "some request data"
617- integration_loop_detail_view.object = self.mock_loop
618- context = IntegrationLoopDetailView.get_context_data(
619- integration_loop_detail_view)
620- self.assertEqual(context['request'], "some request data")
621- self.assertEqual(context['builds'].__class__.__name__, "Mock")
622-
623-
624-class IntegrationLoopUpdateViewTest(TestCase):
625-
626- def setUp(self):
627- self.mock_loop = Mock()
628-
629- def test_get_context_data(self):
630- integration_loop_update_view = IntegrationLoopUpdateView()
631- integration_loop_update_view.request = "some request data"
632- integration_loop_update_view.object = self.mock_loop
633- context = IntegrationLoopUpdateView.get_context_data(
634- integration_loop_update_view)
635- self.assertEqual(context['request'], "some request data")
636
637=== modified file 'dashboard/frontend/views/loop_detail_view.py'
638--- dashboard/frontend/views/loop_detail_view.py 2012-09-12 14:31:41 +0000
639+++ dashboard/frontend/views/loop_detail_view.py 2012-09-14 08:22:19 +0000
640@@ -55,9 +55,7 @@
641 field = self.object._meta.get_field('next_loop')
642 pk = self.object.next_loop_id
643 verbose_name = field.verbose_name.capitalize()
644- # XXX changed to isinstance, since tests were failing: we need to
645- # mock Loop, not the model variable, in a better way in our tests.
646- if isinstance(pk, int):
647+ if pk is not None:
648 # Get the pointer to the object we want to retrieve, and retrieve
649 # the actual instance. We can do this since all our loops inherits
650 # from the same base class (Loop), and we have the information

Subscribers

People subscribed via source and target branches