From 3f09ab94f0c3aca893186dca867cec0bc3ad8f2a Mon Sep 17 00:00:00 2001 From: C Robert Date: Fri, 2 Oct 2009 20:10:40 +0000 Subject: [PATCH] Added multilingual testing in all.py Monotone-Parent: abd75a9093d6e54e0ffd1212fc032a610a2f3331 Monotone-Revision: 6b701660e1b1301f2a55944ee5d70d4e92f44cd9 Monotone-Author: crobert@inverse.ca Monotone-Date: 2009-10-02T20:10:40 Monotone-Branch: ca.inverse.sogo --- Tests/all.py | 43 +++++++++++++++++++++++-- Tests/preferences.py | 74 +++++++++++++++++++++++++++++++++++++++++++ Tests/test-maildav.py | 7 ++-- 3 files changed, 119 insertions(+), 5 deletions(-) create mode 100644 Tests/preferences.py diff --git a/Tests/all.py b/Tests/all.py index d0a1f20ea..9347ed119 100755 --- a/Tests/all.py +++ b/Tests/all.py @@ -1,10 +1,24 @@ #!/usr/bin/python -import os, unittest +import os, sys, unittest, getopt, traceback +import preferences if __name__ == "__main__": loader = unittest.TestLoader() modules = [] + # Duplicated from UIxPreferences.m + languages = ["Czech", "Dutch", "English", "French", + "German", "Hungarian", "Italian", "BrazilianPortuguese", + "Russian", "Spanish", "Welsh"] + + # We can disable testing all languages + testLanguages = True + opts, args = getopt.getopt (sys.argv[1:], [], ["disable-languages"]) + for o, a in opts: + if o == "--disable-languages": + testLanguages = False + + for mod in os.listdir("."): if mod.startswith("test-") and mod.endswith(".py"): modules.append(mod[:-3]) @@ -15,6 +29,31 @@ if __name__ == "__main__": print "%d tests in modules: '%s'" % (suite.countTestCases(), "', '".join(modules)) runner = unittest.TextTestRunner() - runner.run(suite) + + if testLanguages: + prefs = preferences.preferences() + # Get the current language + userLanguageString = prefs.get ("Language") + if userLanguageString: + userLanguage = languages.index (userLanguageString) + else: + userLanguage = 2 + + for i in range (0, len (languages)): + try: + prefs.set ("language", i) + except Exception, inst: + print '-' * 60 + traceback.print_exc () + print '-' * 60 + + print "Running test in %s (%d/%d)" % \ + (languages[i], i + 1, len (languages)) + runner.run(suite) + # Revert to the original language + prefs.set ("language", userLanguage) + else: + runner.run(suite) + else: print "No test available." diff --git a/Tests/preferences.py b/Tests/preferences.py new file mode 100644 index 000000000..2cc31903b --- /dev/null +++ b/Tests/preferences.py @@ -0,0 +1,74 @@ +from config import hostname, port, username, password +import webdavlib +import urllib +import base64 + + +class HTTPPreferencesPOST (webdavlib.HTTPPOST): + cookie = None + + def prepare_headers (self): + headers = webdavlib.HTTPPOST.prepare_headers(self) + if self.cookie: + headers["Cookie"] = self.cookie + return headers + +class HTTPPreferencesGET (webdavlib.HTTPGET): + cookie = None + + def prepare_headers (self): + headers = webdavlib.HTTPGET.prepare_headers(self) + if self.cookie: + headers["Cookie"] = self.cookie + return headers + + + +class preferences: + login = username + passw = password + + def __init__ (self, otherLogin = None, otherPassword = None): + if otherLogin and otherPassword: + self.login = otherLogin + self.passw = otherPassword + + self.client = webdavlib.WebDAVClient(hostname, port, + self.login, self.passw) + + authString = \ + base64.urlsafe_b64encode (username+":"+password).replace("=", "%3D") + self.cookie = \ + "0xHIGHFLYxSOGo=basic%%20%s;%%20SOGo=6C0F6C0F014AC60ED5" % authString + + self.preferencesMap = {"language": "2.1.0.3.0.1.3.1.1.3.1.2"} + + def set (self, preference, value): + formKey = self.preferencesMap[preference] + content = "%s=%s" % (formKey, value) + url = "/SOGo/so/cyril/preferences" + + post = HTTPPreferencesPOST (url, content) + post.content_type = "application/x-www-form-urlencoded" + post.cookie = self.cookie + + self.client.execute (post) + + # Raise an exception if the language wasn't properly set + if post.response["status"] != 200: + raise Exception ("failure setting language, (code = %d)" \ + % post.response["status"]) + + def get (self, preference): + url = "/SOGo/so/cyril/preferences/jsonDefaults" + get = HTTPPreferencesGET (url) + get.cookie = self.cookie + self.client.execute (get) + content = eval (get.response['body']) + return content[preference] + + +# Simple main to test this class +if __name__ == "__main__": + p = preferences () + p.set ("language", 6) diff --git a/Tests/test-maildav.py b/Tests/test-maildav.py index f993c0743..14e1f8dd3 100755 --- a/Tests/test-maildav.py +++ b/Tests/test-maildav.py @@ -240,12 +240,13 @@ class DAVMailCollectionTest(unittest.TestCase): def testMKCOL(self): """Folder creation""" - self._makeCollection("test-dav-mail-%40-abc") self._deleteCollection("test-dav-mail-%40-abc") - self._makeCollection("test-dav-mail-@-def") self._deleteCollection("test-dav-mail-@-def") - self._makeCollection("test-dav-mail-%20-ghi") self._deleteCollection("test-dav-mail-%20-ghi") + + self._makeCollection("test-dav-mail-%40-abc") + self._makeCollection("test-dav-mail-@-def") + self._makeCollection("test-dav-mail-%20-ghi") self._makeCollection("test-dav-mail-%25-jkl", 500) # Test MOVE