Merge lp:~alecu/ubuntu-sso-client/gsettings-at-sign into lp:ubuntu-sso-client

Proposed by Alejandro J. Cura
Status: Merged
Approved by: Alejandro J. Cura
Approved revision: 978
Merged at revision: 976
Proposed branch: lp:~alecu/ubuntu-sso-client/gsettings-at-sign
Merge into: lp:ubuntu-sso-client
Diff against target: 120 lines (+44/-2)
5 files modified
ubuntu_sso/gtk/tests/test_gui.py (+1/-0)
ubuntu_sso/tests/test_credentials.py (+1/-0)
ubuntu_sso/utils/tests/test_common.py (+1/-0)
ubuntu_sso/utils/webclient/gsettings.py (+9/-2)
ubuntu_sso/utils/webclient/tests/test_gsettings.py (+32/-0)
To merge this branch: bzr merge lp:~alecu/ubuntu-sso-client/gsettings-at-sign
Reviewer Review Type Date Requested Status
Natalia Bidart (community) Approve
Manuel de la Peña (community) Approve
Review via email: mp+111691@code.launchpad.net

Commit message

- Account for g_variant_print type annotations (LP: #1007109).

To post a comment you must log in.
Revision history for this message
Manuel de la Peña (mandel) :
review: Approve
Revision history for this message
Natalia Bidart (nataliabidart) wrote :

The branch looks ok, I'm a little afraid we won't have more settings with 'annotations'.

Would you please improve a bit the parsing so the "default" case is not a cast to int()? I would suggest something like:

elif value.isdigit():
    parsed_value = int(valued)
else:
    logger.warning('Can not parse value from gsettings %r, ignoring.', value)

Does that make sense?

review: Needs Information
977. By Alejandro J. Cura

Handle default parsing case as suggested on reviews

978. By Alejandro J. Cura

Fixes requested on review

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

Works great!

Thanks

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'ubuntu_sso/gtk/tests/test_gui.py'
2--- ubuntu_sso/gtk/tests/test_gui.py 2012-06-22 16:51:06 +0000
3+++ ubuntu_sso/gtk/tests/test_gui.py 2012-06-25 16:38:20 +0000
4@@ -168,6 +168,7 @@
5 self.memento = MementoHandler()
6 self.memento.setLevel(logging.DEBUG)
7 gui.logger.addHandler(self.memento)
8+ self.addCleanup(gui.logger.removeHandler, self.memento)
9
10 def _set_called(self, *args, **kwargs):
11 """Set _called to True."""
12
13=== modified file 'ubuntu_sso/tests/test_credentials.py'
14--- ubuntu_sso/tests/test_credentials.py 2012-06-22 16:51:06 +0000
15+++ ubuntu_sso/tests/test_credentials.py 2012-06-25 16:38:20 +0000
16@@ -122,6 +122,7 @@
17 self.memento = MementoHandler()
18 self.memento.setLevel(logging.DEBUG)
19 credentials.logger.addHandler(self.memento)
20+ self.addCleanup(credentials.logger.removeHandler, self.memento)
21
22 self.patch(credentials, 'get_bin_dir', lambda: self.bin_dir)
23
24
25=== modified file 'ubuntu_sso/utils/tests/test_common.py'
26--- ubuntu_sso/utils/tests/test_common.py 2012-04-17 20:27:21 +0000
27+++ ubuntu_sso/utils/tests/test_common.py 2012-06-25 16:38:20 +0000
28@@ -106,6 +106,7 @@
29 self.memento = MementoHandler()
30 self.memento.setLevel(logging.DEBUG)
31 utils.logger.addHandler(self.memento)
32+ self.addCleanup(utils.logger.removeHandler, self.memento)
33
34 self.get_dir = getattr(utils, self.DIR_GETTER)
35
36
37=== modified file 'ubuntu_sso/utils/webclient/gsettings.py'
38--- ubuntu_sso/utils/webclient/gsettings.py 2012-04-09 17:38:24 +0000
39+++ ubuntu_sso/utils/webclient/gsettings.py 2012-06-25 16:38:20 +0000
40@@ -30,7 +30,11 @@
41
42 import subprocess
43
44+from ubuntu_sso.logger import setup_logging
45+
46+logger = setup_logging("ubuntu_sso.utils.webclient.gsettings")
47 GSETTINGS_CMDLINE = "gsettings list-recursively org.gnome.system.proxy"
48+CANNOT_PARSE_WARNING = "Cannot parse gsettings value: %r"
49
50
51 def parse_proxy_host(hostname):
52@@ -80,12 +84,15 @@
53 continue
54 if value.startswith("'"):
55 parsed_value = value[1:-1]
56- elif value.startswith('['):
57+ elif value.startswith(('[', '@')):
58 parsed_value = value
59 elif value in ('true', 'false'):
60 parsed_value = (value == 'true')
61+ elif value.isdigit():
62+ parsed_value = int(value)
63 else:
64- parsed_value = int(value)
65+ logger.warning(CANNOT_PARSE_WARNING, value)
66+ parsed_value = value
67 relative_key = (path + "." + key)[base_len:]
68 gsettings[relative_key] = parsed_value
69 mode = gsettings["mode"]
70
71=== modified file 'ubuntu_sso/utils/webclient/tests/test_gsettings.py'
72--- ubuntu_sso/utils/webclient/tests/test_gsettings.py 2012-04-09 17:38:24 +0000
73+++ ubuntu_sso/utils/webclient/tests/test_gsettings.py 2012-06-25 16:38:20 +0000
74@@ -28,7 +28,10 @@
75 # files in the program, then also delete it here.
76 """Test the gsettings parser."""
77
78+import logging
79+
80 from twisted.trial.unittest import TestCase
81+from ubuntuone.devtools.handlers import MementoHandler
82
83 from ubuntu_sso.utils.webclient import gsettings
84 from ubuntu_sso.utils.webclient.tests import (
85@@ -91,6 +94,35 @@
86 """Test a parser of gsettings."""
87 self._assert_parser_anonymous('https')
88
89+ def test_gsettings_empty_ignore_hosts(self):
90+ """Missing values in the ignore hosts."""
91+ troublesome_value = "@as []"
92+ template_values = dict(BASE_GSETTINGS_VALUES)
93+ template_values["ignore_hosts"] = troublesome_value
94+ fake_output = TEMPLATE_GSETTINGS_OUTPUT.format(**template_values)
95+ self.patch(gsettings.subprocess, "check_output",
96+ lambda _: fake_output)
97+ ps = gsettings.get_proxy_settings()
98+ self.assertEqual(ps, {})
99+
100+ def test_gsettings_cannot_parse(self):
101+ """Some weird setting that cannot be parsed is logged with warning."""
102+ memento = MementoHandler()
103+ memento.setLevel(logging.DEBUG)
104+ gsettings.logger.addHandler(memento)
105+ self.addCleanup(gsettings.logger.removeHandler, memento)
106+
107+ troublesome_value = "#bang"
108+ template_values = dict(BASE_GSETTINGS_VALUES)
109+ template_values["ignore_hosts"] = troublesome_value
110+ fake_output = TEMPLATE_GSETTINGS_OUTPUT.format(**template_values)
111+ self.patch(gsettings.subprocess, "check_output",
112+ lambda _: fake_output)
113+ ps = gsettings.get_proxy_settings()
114+ self.assertTrue(memento.check_warning(gsettings.CANNOT_PARSE_WARNING %
115+ troublesome_value))
116+ self.assertEqual(ps, {})
117+
118 def test_gsettings_parser_http_authenticated(self):
119 """Test a parser of gsettings."""
120 template_values = dict(BASE_GSETTINGS_VALUES)

Subscribers

People subscribed via source and target branches