Merge lp:~mvo/software-center/5.4-fix-save-person-to-config into lp:software-center

Proposed by Michael Vogt
Status: Merged
Merged at revision: 3253
Proposed branch: lp:~mvo/software-center/5.4-fix-save-person-to-config
Merge into: lp:software-center
Diff against target: 99 lines (+18/-10)
4 files modified
softwarecenter/backend/ubuntusso.py (+1/-0)
softwarecenter/config.py (+7/-0)
softwarecenter/utils.py (+2/-7)
tests/test_utils.py (+8/-3)
To merge this branch: bzr merge lp:~mvo/software-center/5.4-fix-save-person-to-config
Reviewer Review Type Date Requested Status
software-store-developers Pending
Review via email: mp+135677@code.launchpad.net

Description of the change

This branch ensures that the "username" is saved everytime that
the ubuntu sso whoami call is done. This helps making reviews
editable again

To post a comment you must log in.
Revision history for this message
Michael Vogt (mvo) wrote :

This should also go into the 5.4 branch, a end-to-end test there is needed to ensure that editing a review still works as the rnrclient_pristine.py is using "str" for the @validate in the modify_review function there.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'softwarecenter/backend/ubuntusso.py'
2--- softwarecenter/backend/ubuntusso.py 2012-09-14 13:25:45 +0000
3+++ softwarecenter/backend/ubuntusso.py 2012-11-22 13:18:26 +0000
4@@ -81,6 +81,7 @@
5 # once we have data, make sure to save it
6 config = get_config()
7 config.email = piston_whoami["preferred_email"]
8+ config.reviews_username = piston_whoami["username"]
9 # emit
10 self.emit("whoami", piston_whoami)
11
12
13=== modified file 'softwarecenter/config.py'
14--- softwarecenter/config.py 2012-09-06 17:25:40 +0000
15+++ softwarecenter/config.py 2012-11-22 13:18:26 +0000
16@@ -135,6 +135,13 @@
17 None,
18 "The prefered email of the user, automatically set via the ubuntu-sso")
19 # the review section
20+ reviews_username = property(
21+ lambda self: self._generic_get(
22+ "username", section="reviews", default=""),
23+ lambda self, value: self._generic_set(
24+ "username", value, section="reviews"),
25+ None,
26+ "The sso username")
27 reviews_post_via_gwibber = property(
28 lambda self: self._generic_getbool(
29 "gwibber_send", section="reviews", default=False),
30
31=== modified file 'softwarecenter/utils.py'
32--- softwarecenter/utils.py 2012-09-24 07:57:33 +0000
33+++ softwarecenter/utils.py 2012-11-22 13:18:26 +0000
34@@ -623,10 +623,7 @@
35 curr_name = get_person_from_config()
36 if curr_name != username:
37 config = get_config()
38- if not config.has_section("reviews"):
39- config.add_section("reviews")
40- config.set("reviews", "username", username)
41- config.write()
42+ config.reviews_username = username
43 # refresh usefulness cache in the background once we know
44 # the person
45 from backend.reviews import UsefulnessCache
46@@ -638,9 +635,7 @@
47 """ get the username value for Ubuntu SSO from the config file
48 """
49 cfg = get_config()
50- if cfg.has_option("reviews", "username"):
51- return cfg.get("reviews", "username")
52- return None
53+ return cfg.reviews_username
54
55
56 def pnormaldist(qn):
57
58=== modified file 'tests/test_utils.py'
59--- tests/test_utils.py 2012-09-07 13:34:37 +0000
60+++ tests/test_utils.py 2012-11-22 13:18:26 +0000
61@@ -151,7 +151,7 @@
62 def test_get_uuid(self):
63 uuid = get_uuid()
64 self.assertTrue(uuid and len(uuid) > 0)
65-
66+
67 def test_get_recommender_uuid(self):
68 uuid = get_recommender_uuid()
69 self.assertTrue("-" not in uuid and len(uuid) > 0)
70@@ -196,7 +196,7 @@
71 self.assertEqual(capitalize_first_word(""), "")
72
73 @unittest.skipIf(
74- os.getuid() == 0,
75+ os.getuid() == 0,
76 "fails when run as root as os.access() is always successful")
77 def test_ensure_file_writable_and_delete_if_not(self):
78 # first test that a non-writable file (0400) is deleted
79@@ -213,7 +213,7 @@
80 self.assertTrue(os.path.exists(test_file_writeable.name))
81
82 @unittest.skipIf(
83- os.getuid() == 0,
84+ os.getuid() == 0,
85 "fails when run as root as os.chmod() is always successful")
86 def test_safe_makedirs(self):
87 tmp = mkdtemp()
88@@ -311,6 +311,11 @@
89 for i in range(64*1024):
90 l.append(i)
91
92+ def test_save_person_to_config(self):
93+ from softwarecenter.utils import (
94+ save_person_to_config, get_person_from_config)
95+ save_person_to_config("meep")
96+ self.assertEqual(get_person_from_config(), "meep")
97
98 if __name__ == "__main__":
99 unittest.main()

Subscribers

People subscribed via source and target branches