9209.14.3
by Michael Nelson
Rename and move user-agent detection function to lp.services and provide specific tests there. |
1 |
# Copyright 2009 Canonical Ltd. This software is licensed under the
|
2 |
# GNU Affero General Public License version 3 (see the file LICENSE).
|
|
3 |
||
4 |
# pylint: disable-msg=F0401
|
|
5 |
||
6 |
"""Unit tests for browser helper functions."""
|
|
7 |
||
8 |
__metaclass__ = type |
|
9 |
__all__ = ['TestGetUserAgentDistroSeries', 'test_suite'] |
|
10 |
||
11 |
import unittest |
|
12 |
||
13 |
from lp.services.browser_helpers import get_user_agent_distroseries |
|
14 |
||
11403.1.4
by Henning Eggers
Reformatted imports using format-imports script r32. |
15 |
|
9209.14.3
by Michael Nelson
Rename and move user-agent detection function to lp.services and provide specific tests there. |
16 |
class TestGetUserAgentDistroSeries(unittest.TestCase): |
17 |
"""Test that the user_agent string is correctly parsed for os version."""
|
|
18 |
||
19 |
def test_get_user_agent_distroseries_when_present(self): |
|
20 |
"""The version number is returned when present."""
|
|
21 |
user_agent = ('Mozilla/5.0 ' |
|
22 |
'(X11; U; Linux i686; en-US; rv:1.9.0.10) '
|
|
23 |
'Gecko/2009042523 Ubuntu/10.09 (whatever) '
|
|
24 |
'Firefox/3.0.10') |
|
25 |
||
26 |
version = get_user_agent_distroseries(user_agent) |
|
27 |
self.failUnlessEqual('10.09', version, |
|
28 |
"Incorrect version string returned.") |
|
29 |
||
30 |
def test_get_user_agent_distroseries_when_invalid(self): |
|
31 |
"""None should be returned when the version is not matched."""
|
|
32 |
user_agent = ('Mozilla/5.0 ' |
|
33 |
'(X11; U; Linux i686; en-US; rv:1.9.0.10) '
|
|
34 |
'Gecko/2009042523 Ubuntu/10a.09 (whatever) '
|
|
35 |
'Firefox/3.0.10') |
|
36 |
||
37 |
version = get_user_agent_distroseries(user_agent) |
|
38 |
self.failUnless(version is None, |
|
39 |
"None should be returned when the match fails.") |
|
13677.3.2
by Steve Kowalik
Remove unneeded unittest imports. |
40 |
|
41 |
def test_suite(): |
|
42 |
return unittest.TestLoader().loadTestsFromName(__name__) |