Merge lp:~zematynnad/ubuntu-webcatalog/preflight_987822 into lp:ubuntu-webcatalog

Proposed by Danny Tamez
Status: Merged
Approved by: Natalia Bidart
Approved revision: 129
Merged at revision: 128
Proposed branch: lp:~zematynnad/ubuntu-webcatalog/preflight_987822
Merge into: lp:ubuntu-webcatalog
Diff against target: 243 lines (+201/-0)
5 files modified
django_project/urls.py (+2/-0)
src/webcatalog/preflight.py (+90/-0)
src/webcatalog/schema.py (+1/-0)
src/webcatalog/tests/__init__.py (+1/-0)
src/webcatalog/tests/test_preflight.py (+107/-0)
To merge this branch: bzr merge lp:~zematynnad/ubuntu-webcatalog/preflight_987822
Reviewer Review Type Date Requested Status
Natalia Bidart (community) Approve
Review via email: mp+107483@code.launchpad.net

Commit message

Preflight check for webcatalog

Description of the change

Overview
=========
This branch adds some more functionality for preflight check to webcatalog.

Details
========
To view preflight for ubuntu-webcatalog go to /+preflight. Here is a screenshot of the preflight page: http://simplest-image-hosting.net/png-0-sn2383

The setting PREFLIGHT_GROUPS was added so that we can configure which groups are allowed to view the preflight page. Since webcatalog does not currently have a login page the +preflight url redirects to the openid login page and then redirects on success to the preflight page.

To Test
=========
$fab bootstrap test

To post a comment you must log in.
Revision history for this message
Natalia Bidart (nataliabidart) wrote :

While running the test suite I'm getting 3 failures that I already had notices in trunk, those are fixed in:

https://code.launchpad.net/~nataliabidart/ubuntu-webcatalog/law-and-order/+merge/108204

Would you please review and merge that branch in?

Besides that, I'm getting this output from the test run:

Creating test database for alias 'default'...
...................................................................F...F.......................F........................................................................................................................................Generated checkid_setup request to https://login.staging.ubuntu.com/+openid with assocication {HMAC-SHA1}{4fc7c2c1}{RSEj3w==}
................./home/nessita/canonical/webcatalog/review_preflight_987822/src/webcatalog/preflight.py:46:5: E303 too many blank lines (2)
.

Would you fix the pep8 issue? And perhaps check what is printing the "Generated checkid_setup request to..." message being printed?

Thanks!

review: Needs Fixing
127. By Danny Tamez

Merge from trunk.

128. By Danny Tamez

Remove extra blank line.

129. By Danny Tamez

Fix docstrings and move imports to the top.

Revision history for this message
Natalia Bidart (nataliabidart) wrote :

Looks good! Thanks

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'django_project/urls.py'
--- django_project/urls.py 2012-03-19 17:01:05 +0000
+++ django_project/urls.py 2012-05-31 20:32:19 +0000
@@ -29,6 +29,8 @@
29 url(r'^cat/', include('webcatalog.urls')),29 url(r'^cat/', include('webcatalog.urls')),
30 url(r'^admin/', include(admin.site.urls)),30 url(r'^admin/', include(admin.site.urls)),
31 (r'^preflight/$', include('preflight.urls')),31 (r'^preflight/$', include('preflight.urls')),
32 url(r'^\+preflight/$', redirect_to,
33 {'url': '/openid/login?next=/preflight/'}),
32 url(r'^$', redirect_to, {'url': '/cat/'}),34 url(r'^$', redirect_to, {'url': '/cat/'}),
3335
34 # OpenID views36 # OpenID views
3537
=== added file 'src/webcatalog/preflight.py'
--- src/webcatalog/preflight.py 1970-01-01 00:00:00 +0000
+++ src/webcatalog/preflight.py 2012-05-31 20:32:19 +0000
@@ -0,0 +1,90 @@
1# -*- coding: utf-8 -*-
2# This file is part of the Apps Directory
3# Copyright (C) 2011 Canonical Ltd.
4#
5# This program is free software: you can redistribute it and/or modify
6# it under the terms of the GNU Affero General Public License as
7# published by the Free Software Foundation, either version 3 of the
8# License, or (at your option) any later version.
9#
10# This program is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13# GNU Affero General Public License for more details.
14#
15# You should have received a copy of the GNU Affero General Public License
16# along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18"""Preflight check for webcatalog."""
19
20from __future__ import (
21 absolute_import,
22 with_statement,
23 )
24
25from django import db
26from django.conf import settings
27from preflight import Preflight, register
28
29import openid
30import piston.utils
31
32from webcatalog.utilities import WebServices
33
34__metaclass__ = type
35__all__ = [
36 'WebcatalogPreflight'
37 ]
38
39
40class WebcatalogPreflight(Preflight):
41
42 def authenticate(self, request):
43 if not request.user.is_authenticated():
44 return False
45 allowed_teams = getattr(settings, 'PREFLIGHT_GROUPS', [])
46 groups = request.user.groups.filter(name__in=allowed_teams)
47 return groups.count() > 0
48
49 def versions(self):
50 return [
51 {'name': 'openid', 'version': openid.__version__},
52 {'name': 'piston', 'version': piston.utils.get_version()},
53 ]
54
55 def check_validate_config(self):
56 """Make sure that our config files validate correctly. """
57 parser = settings.__CONFIGGLUE_PARSER__
58 return parser.is_valid()
59
60 def check_rnr_available(self):
61 """Make sure that rnr can be reached. """
62 rnr = WebServices().rnr_api
63 return rnr.server_status() == 'ok'
64
65 def check_recommender_available(self):
66 """Make sure that the recommender can be reached. """
67 recommender = WebServices().recommender_api
68 return recommender.server_status() == 'ok'
69
70 def check_screenshots_available(self):
71 """Make sure that screenshots are available. """
72 screenshots = WebServices().get_screenshots_for_package('apt')
73 return len(screenshots) > 0
74
75 def check_identity_provider_available(self):
76 """Make sure SSO can be reached."""
77 sso = WebServices().identity_provider
78 return not sso.validate_token(
79 consumer_key='invalid', token="token")
80
81 def check_database(self):
82 """Make sure database connections are accepted."""
83 cursor = db.connection.cursor()
84 cursor.execute('SELECT 42')
85 cursor.fetchone()
86
87 return True
88
89
90register(WebcatalogPreflight)
091
=== modified file 'src/webcatalog/schema.py'
--- src/webcatalog/schema.py 2012-04-19 23:05:19 +0000
+++ src/webcatalog/schema.py 2012-05-31 20:32:19 +0000
@@ -72,6 +72,7 @@
72 class preflight(schema.Section):72 class preflight(schema.Section):
73 preflight_base_template = schema.StringOption(73 preflight_base_template = schema.StringOption(
74 default="webcatalog/base.html")74 default="webcatalog/base.html")
75 preflight_groups = schema.ListOption(item=schema.StringOption())
7576
76 class rnr(schema.Section):77 class rnr(schema.Section):
77 rnr_service_root = schema.StringOption(78 rnr_service_root = schema.StringOption(
7879
=== modified file 'src/webcatalog/tests/__init__.py'
--- src/webcatalog/tests/__init__.py 2012-03-08 18:00:09 +0000
+++ src/webcatalog/tests/__init__.py 2012-05-31 20:32:19 +0000
@@ -25,6 +25,7 @@
25from .test_models import *25from .test_models import *
26from .test_managers import *26from .test_managers import *
27from .test_pep8 import *27from .test_pep8 import *
28from .test_preflight import *
28from .test_templatetags import *29from .test_templatetags import *
29from .test_utilities import *30from .test_utilities import *
30from .test_views import *31from .test_views import *
3132
=== added file 'src/webcatalog/tests/test_preflight.py'
--- src/webcatalog/tests/test_preflight.py 1970-01-01 00:00:00 +0000
+++ src/webcatalog/tests/test_preflight.py 2012-05-31 20:32:19 +0000
@@ -0,0 +1,107 @@
1# -*- coding: utf-8 -*-
2# This file is part of the Ubuntu Web Catalog
3# Copyright (C) 2011 Canonical Ltd.
4#
5# This program is free software: you can redistribute it and/or modify
6# it under the terms of the GNU Affero General Public License as
7# published by the Free Software Foundation, either version 3 of the
8# License, or (at your option) any later version.
9#
10# This program is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13# GNU Affero General Public License for more details.
14#
15# You should have received a copy of the GNU Affero General Public License
16# along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18from django.contrib.auth.models import (
19 Group,
20 User,
21 )
22from mock import patch
23
24from webcatalog.tests.factory import TestCaseWithFactory
25from webcatalog.tests.helpers import patch_settings
26
27__metaclass__ = type
28
29
30class TestPreflight(TestCaseWithFactory):
31
32 def login(self, add_to_group=True, user=None):
33 if not user:
34 user = User.objects.create_user(username='test',
35 email='test@test.com',
36 password='test')
37 if add_to_group:
38 group = Group.objects.create(name='preflight')
39 user.groups.add(group)
40 user.save()
41 self.client.login(username='test', password='test')
42
43 def test_public_url_redirects_to_login(self):
44 response = self.client.get('/+preflight', follow=True)
45
46 with patch_settings(PREFLIGHT_GROUPS=['preflight']):
47 self.assertContains(response, 'OpenID transaction in progress')
48
49 def test_login_needed_for_preflight(self):
50 self.login()
51
52 with patch_settings(PREFLIGHT_GROUPS=['preflight']):
53 response = self.client.get('/preflight/')
54
55 self.assertEqual(200, response.status_code)
56
57 def test_no_login_means_preflight_not_found(self):
58 with patch_settings(PREFLIGHT_GROUPS=['preflight']):
59 response = self.client.get('/preflight/')
60
61 self.assertEqual(404, response.status_code)
62
63 def test_login_but_wrong_group_means_preflight_not_found(self):
64 with patch_settings(PREFLIGHT_GROUPS=['preflight']):
65 self.login(add_to_group=False)
66
67 response = self.client.get('/preflight/')
68
69 self.assertEqual(404, response.status_code)
70
71 @patch('webcatalog.utilities.WebServices.identity_provider')
72 @patch('webcatalog.utilities.WebServices.get_screenshots_for_package')
73 @patch('webcatalog.utilities.WebServices.recommender_api')
74 @patch('webcatalog.utilities.WebServices.rnr_api')
75 def test_success(self, mock_rnr, mock_recommender, mock_screenshots,
76 mock_sso):
77 mock_rnr.server_status.return_value = 'ok'
78 mock_recommender.server_status.return_value = 'ok'
79 mock_screenshots.return_value = ['some_screenshot.jpg']
80 mock_sso.validate_token.return_value = False
81 self.login()
82
83 with patch_settings(PREFLIGHT_GROUPS=['preflight']):
84 response = self.client.get('/preflight/')
85
86 self.assertEqual(200, response.status_code)
87 libs = set([x['name'] for x in response.context[0]['versions']])
88 apps = response.context['applications']
89 checks = set((x.name, x.passed) for x in apps[0].checks)
90 expected_libs = set([
91 'Python',
92 'openid',
93 'piston',
94 'Django',
95 'preflight',
96 ])
97 expected_checks = set([
98 ('validate_config', True),
99 ('database', True),
100 ('rnr_available', True),
101 ('identity_provider_available', True),
102 ('recommender_available', True),
103 ('rnr_available', True),
104 ('screenshots_available', True),
105 ])
106 self.assertEqual(expected_libs, libs)
107 self.assertEqual(expected_checks, checks)

Subscribers

People subscribed via source and target branches