Merge lp:~canonical-isd-hackers/ubuntu-webcatalog/useragent_778562_patched_browsers into lp:ubuntu-webcatalog

Proposed by Danny Tamez
Status: Merged
Approved by: Anthony Lenton
Approved revision: 28
Merged at revision: 27
Proposed branch: lp:~canonical-isd-hackers/ubuntu-webcatalog/useragent_778562_patched_browsers
Merge into: lp:ubuntu-webcatalog
Diff against target: 75 lines (+35/-3)
2 files modified
src/webcatalog/tests/test_views.py (+19/-1)
src/webcatalog/views.py (+16/-2)
To merge this branch: bzr merge lp:~canonical-isd-hackers/ubuntu-webcatalog/useragent_778562_patched_browsers
Reviewer Review Type Date Requested Status
Anthony Lenton (community) Approve
Review via email: mp+66196@code.launchpad.net

Commit message

Adds support for patched browsers that actually give us the distro.

Description of the change

Adds support for patched browsers that actually give us the distro.

To post a comment you must log in.
28. By Danny Tamez

Fixed typo

Revision history for this message
Anthony Lenton (elachuni) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/webcatalog/tests/test_views.py'
2--- src/webcatalog/tests/test_views.py 2011-06-28 15:03:12 +0000
3+++ src/webcatalog/tests/test_views.py 2011-06-28 18:33:31 +0000
4@@ -169,6 +169,25 @@
5
6 self.assertNotContains(response, 'Purchase %s' % app.name)
7
8+ def test_button_for_non_guessed_match(self):
9+ ua = 'blah X11; Linux Ubuntu/11.04 blah blah'
10+ response, app = self.get_app_and_response(useragent=ua,
11+ for_purchase=True)
12+
13+ self.assertContains(response, 'Purchase %s' % app.name)
14+ self.assertNotContains(response, 'Install %s' % app.name)
15+ self.assertNotContains(response, 'Not running %s?' %
16+ settings.DEFAULT_DISTRO)
17+
18+ def test_button_for_non_guessed_non_match(self):
19+ ua = 'blah X11; Linux Ubuntu/11.10 blah blah'
20+ response, app = self.get_app_and_response(useragent=ua,
21+ for_purchase=True)
22+
23+ self.assertContains(response, 'Not available for your version of'
24+ ' Ubuntu')
25+ self.assertNotContains(response, 'Not running %s?' %
26+ settings.DEFAULT_DISTRO)
27
28
29 class SearchTestCase(TestCaseWithFactory):
30@@ -277,7 +296,6 @@
31 self.assertEqual(1, page.number)
32
33
34-
35 class OverviewTestCase(TestCaseWithFactory):
36 def test_index_contains_links_to_departments(self):
37 dept = self.factory.make_department('foo')
38
39=== modified file 'src/webcatalog/views.py'
40--- src/webcatalog/views.py 2011-06-28 15:03:12 +0000
41+++ src/webcatalog/views.py 2011-06-28 18:33:31 +0000
42@@ -158,17 +158,31 @@
43
44
45 def get_user_os(request):
46+ distros = {
47+ '10.04': 'lucid',
48+ '10.10': 'maverick',
49+ '11.04': 'natty',
50+ '11.10': 'oneiric',
51+ }
52 os = {'is_linux': False, 'distro': 'unknown', 'arch': 'unknown'}
53 try:
54 ua = request.META['HTTP_USER_AGENT']
55 except KeyError:
56 return os
57 os['is_linux'] = ua.find('X11; Linux') > -1
58- # Until we can figure out a way to actually get the distro we'll
59- # assume a default distro
60 if os['is_linux']:
61 os['distro'] = settings.DEFAULT_DISTRO
62 os['distro_is_a_guess'] = True
63+ # Some browsers will have a patch that will actually give us the distro
64+ if ua.find('buntu') > -1:
65+ os['distro_is_a_guess'] = False
66+ slash = ua.find('/', ua.find('buntu'))
67+ if slash > -1:
68+ version = ua[slash + 1: slash + 6]
69+ distro = distros[version]
70+ if distro:
71+ os['distro'] = distro
72+ os['distro_is_a_guess'] = False
73 else:
74 os['distro'] = ''
75 os['distro_is_a_guess'] = False

Subscribers

People subscribed via source and target branches