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
This commit is contained in:
C Robert
2009-10-02 20:10:40 +00:00
parent deadf8e33e
commit 3f09ab94f0
3 changed files with 119 additions and 5 deletions

View File

@@ -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."

74
Tests/preferences.py Normal file
View File

@@ -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)

View File

@@ -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