Cosmetic fixes in preferences.py

add a new test to set/get text preferences with chars that must be escaped.

Monotone-Parent: 361f4d1d571053d2b3dd474a5d6755ef20cc2851
Monotone-Revision: 72203acde8ebf2eb487bf2f4d7ee94f9c8fcd81a

Monotone-Author: jraby@inverse.ca
Monotone-Date: 2012-02-16T22:03:36
Monotone-Branch: ca.inverse.sogo
maint-2.0.2
Jean Raby 2012-02-16 22:03:36 +00:00
parent 6aba8896c6
commit 3a4a518c9e
2 changed files with 45 additions and 2 deletions

View File

@ -53,6 +53,7 @@ class preferences:
# should probably be unified...
self.preferencesMap = {
"SOGoLanguage": "language",
"SOGoTimeZone": "timezone",
"SOGoSieveFilters": "sieveFilters",
# Vacation stuff
@ -88,9 +89,9 @@ class preferences:
self.client.execute (post)
# Raise an exception if the language wasn't properly set
# Raise an exception if the pref wasn't properly set
if post.response["status"] != 200:
raise Exception ("failure setting language, (code = %d)" \
raise Exception ("failure setting prefs, (code = %d)" \
% post.response["status"])
def get(self, preference):

View File

@ -0,0 +1,42 @@
#!/usr/bin/python
from config import hostname, port, username, password
import preferences
import simplejson
import sogotests
import unittest
import utilities
class preferencesTest(unittest.TestCase):
def _setTextPref(self, prefText = None ):
""" set a text preference to a known value """
self.prefs.set("autoReplyText", prefText)
# make sure it was set correctly
prefData = self.prefs.get("Vacation")
try:
self.assertEqual(prefData["autoReplyText"], prefText,
"%s != %s" % (prefData["autoReplyText"], prefText))
except TypeError as err:
self.fail("Preferences are probably hosed: %s" % (err))
def setUp(self):
self.prefs = preferences.preferences()
def tearDown(self):
self.prefs.set("autoReplyText", "")
def testSetTextPreferences(self):
""" Set/get a text preference - normal characters"""
self._setTextPref("defaultText")
def testSetTextPreferencesWeirdChars(self):
""" Set/get a text preference - weird characters - used to crash on 1.3.12"""
prefText = "weird data \ ' \"; ^"
self._setTextPref(prefText)
if __name__ == "__main__":
sogotests.runTests()