From 17c4ec949a2fc9a90d8c8f44c201233f0995b967 Mon Sep 17 00:00:00 2001 From: Jean Raby Date: Fri, 20 May 2011 20:22:56 +0000 Subject: [PATCH] Add a rudimentary test for sogo-tool Monotone-Parent: 986c53393f0caccafae8ec72f8b2d56477f587b6 Monotone-Revision: 7f7501b1bb5b05b31afe18481c6a203e70e2222b Monotone-Author: jraby@inverse.ca Monotone-Date: 2011-05-20T20:22:56 Monotone-Branch: ca.inverse.sogo --- Tests/Integration/config.py.in | 3 ++ Tests/Integration/test-sogo-tool.py | 43 +++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100755 Tests/Integration/test-sogo-tool.py diff --git a/Tests/Integration/config.py.in b/Tests/Integration/config.py.in index a70fc0595..149dff65d 100644 --- a/Tests/Integration/config.py.in +++ b/Tests/Integration/config.py.in @@ -21,3 +21,6 @@ testput_nbrdays = 30 sieve_server = "localhost" sieve_port = 2000 + +sogo_user = "sogo" +sogo_tool_path = "/usr/local/sbin/sogo-tool" diff --git a/Tests/Integration/test-sogo-tool.py b/Tests/Integration/test-sogo-tool.py new file mode 100755 index 000000000..1da98ca54 --- /dev/null +++ b/Tests/Integration/test-sogo-tool.py @@ -0,0 +1,43 @@ +#!/usr/bin/python + +# XXX this script has to be run as root because it su to sogo_user +# in order to use its .GNUstepDefaults prefs +# Would be much better to have another way to specify which Defaults to use + +from config import sogo_user, sogo_tool_path + +import os +import pwd +import shutil +import sogotests +import tempfile +import unittest + +class sogoToolTest(unittest.TestCase): + + def setUp(self): + self.backupdir = tempfile.mkdtemp() + + def tearDown(self): + os.chdir("/") + shutil.rmtree(self.backupdir) + + def testBackupAll(self): + """ sogo-tool backup ALL """ + + (uid, gid) = pwd.getpwnam(sogo_user)[2:4] + + # We need to run as root since there's no way + # of using another user's GNUstepDefaults + self.assertEqual(os.getuid(), 0, "this test must run as root...") + + os.chown(self.backupdir, uid, gid) + status = os.system("su - %s -c \"(cd %s && %s backup . ALL >/dev/null 2>&1)\"" + % (sogo_user, self.backupdir, sogo_tool_path)) + + rc=os.WEXITSTATUS(status) + self.assertEqual(rc, 0, "sogo-tool failed RC=%d" % rc) + + +if __name__ == "__main__": + sogotests.runTests()