Merge lp:~linaro-infrastructure/linaro-ci-dashboard/test-changes-additions into lp:linaro-ci-dashboard

Proposed by Deepti B. Kalakeri
Status: Merged
Merged at revision: 8
Proposed branch: lp:~linaro-infrastructure/linaro-ci-dashboard/test-changes-additions
Merge into: lp:linaro-ci-dashboard
Diff against target: 86 lines (+74/-0)
2 files modified
dashboard/frontend/tests/__init__.py (+10/-0)
dashboard/frontend/tests/test_clientresponse.py (+64/-0)
To merge this branch: bzr merge lp:~linaro-infrastructure/linaro-ci-dashboard/test-changes-additions
Reviewer Review Type Date Requested Status
Stevan Radaković Approve
Review via email: mp+114028@code.launchpad.net

Description of the change

Organizing Django Tests into directories.
Adding some client response tests and modifying the __init__.py to include the tests.

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

Hey Deepti,

Thanks for finalizing the test changes. Only one thing bothers me here. If I remove the decorator line from our code, these tests will still pass. Can we accommodate the tests so that they actually fail in this case?
I think adding the 'not_auth' test for index page would do the trick...

review: Needs Fixing (code)
10. By Deepti B. Kalakeri

Adding a test test_response_index_when_user_not_auth_by_login_required which fails when decorator is missing

Revision history for this message
Deepti B. Kalakeri (deeptik) wrote :

Added test test_response_index_when_user_not_auth_by_login_required which check this and fails if accidentally login_required() decorator is removed.

Thanks!!!
Deepti.

Revision history for this message
Stevan Radaković (stevanr) wrote :

Thanks Deepti.
Looks good.
Approve +1

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added directory 'dashboard/frontend/tests'
2=== added file 'dashboard/frontend/tests/__init__.py'
3--- dashboard/frontend/tests/__init__.py 1970-01-01 00:00:00 +0000
4+++ dashboard/frontend/tests/__init__.py 2012-07-10 14:09:20 +0000
5@@ -0,0 +1,10 @@
6+from dashboard.frontend.tests.test_views import *
7+from dashboard.frontend.tests.test_clientresponse import *
8+
9+
10+#starts the test suite
11+__test__= {
12+ 'HomePageViewTests': HomePageViewTest,
13+ 'IndexViewTests': IndexViewTest,
14+ 'ClientResponseTests': ClientResponseTests,
15+ }
16
17=== added file 'dashboard/frontend/tests/test_clientresponse.py'
18--- dashboard/frontend/tests/test_clientresponse.py 1970-01-01 00:00:00 +0000
19+++ dashboard/frontend/tests/test_clientresponse.py 2012-07-10 14:09:20 +0000
20@@ -0,0 +1,64 @@
21+#!/usr/bin/env python
22+# Copyright (C) 2012 Linaro
23+#
24+# This file is part of linaro-ci-dashboard.
25+#
26+# linaro-ci-dashboard is free software: you can redistribute it and/or modify
27+# it under the terms of the GNU Affero General Public License as published by
28+# the Free Software Foundation, either version 3 of the License, or
29+# (at your option) any later version.
30+#
31+# linaro-ci-dashboard is distributed in the hope that it will be useful,
32+# but WITHOUT ANY WARRANTY; without even the implied warranty of
33+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34+# GNU Affero General Public License for more details.
35+#
36+# You should have received a copy of the GNU Affero General Public License
37+# along with linaro-ci-dashboard. If not, see <http://www.gnu.org/licenses/>.
38+
39+from django.test import TestCase
40+from django.contrib.auth.models import User, Group
41+from django.test.client import Client
42+
43+class ClientResponseTests(TestCase):
44+
45+ def setUp(self):
46+ self.client = Client()
47+ self.user = 'someuser'
48+ self.passwd = 'somepasswd'
49+ self.email = 'someuser@example.com'
50+ self.group = 'somegroup'
51+ self.user = User.objects.create_user(self.user,
52+ self.email, self.passwd)
53+ self.group = Group.objects.create(name=self.group)
54+
55+ def tearDown(self):
56+ user = User.objects.filter(username=self.user)
57+ group = Group.objects.filter(name=self.group)
58+ if user:
59+ user.delete()
60+ if group:
61+ group.delete()
62+
63+ # Test case should fail if the login_required decorator source code
64+ # in index_view.py is removed.
65+ def test_response_index_when_user_not_auth_by_login_required(self):
66+ response = self.client.get('/index/')
67+ self.assertNotEqual(200, response.status_code)
68+
69+ def test_response_home_when_user_not_auth_by_login_required(self):
70+ response = self.client.get('/home/')
71+ self.assertNotIn(str(self.user), response.content)
72+
73+ def test_response_with_invalid_user(self):
74+ passwd = 'invalid_passwd'
75+ login_value = self.client.login(username=self.user, password=passwd)
76+ self.assertEqual(login_value, False)
77+
78+ def test_response_when_user_authed(self):
79+ self.client.login(username=self.user, password=self.passwd)
80+ response = self.client.get('/')
81+ self.assertIn(str(self.user), response.content)
82+ response = self.client.get('/home/')
83+ self.assertIn(str(self.user), response.content)
84+
85
86=== renamed file 'dashboard/frontend/tests.py' => 'dashboard/frontend/tests/test_views.py'

Subscribers

People subscribed via source and target branches

to all changes: