From edaedf6ee7ea24031eb0a3b0a4edffeb8120619e Mon Sep 17 00:00:00 2001 From: Antoine Nguyen Date: Sun, 24 Feb 2013 15:07:44 +0100 Subject: [PATCH] New unit test to validate a fresh installation. --- tests/install_from_scratch.py | 65 +++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 tests/install_from_scratch.py diff --git a/tests/install_from_scratch.py b/tests/install_from_scratch.py new file mode 100644 index 000000000..cb7247656 --- /dev/null +++ b/tests/install_from_scratch.py @@ -0,0 +1,65 @@ +# coding: utf-8 + +import os +import sys +import subprocess +import tempfile +import pexpect +import shutil +import unittest + + +def runcmd(cmd, **kwargs): + p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, + shell=True, **kwargs) + output = p.communicate()[0] + return p.returncode, output + +class DeployTest(unittest.TestCase): + dbtype = "mysql" + dbhost = "localhost" + projname = "modoboa_test" + dbuser = "root" + dbpassword = "toto" + + def setUp(self): + cmd = "mysqladmin -u %s -p%s create %s" % (self.dbuser, self.dbpassword, self.projname) + code, out = runcmd(cmd) + self.assertEqual(code, 0) + self.workdir = tempfile.mkdtemp() + + def tearDown(self): + if hasattr(self, "workdir"): + shutil.rmtree(self.workdir) + child = pexpect.spawn("mysqladmin -u root -p%s drop %s" % (self.dbpassword, self.projname)) + child.expect("\[y/N\]") + child.sendline("y") + child.expect('Database "%s" dropped' % self.projname) + + def test(self): + timeout = 2 + cmd = "modoboa-admin.py deploy --syncdb --collectstatic %s" % self.projname + child = pexpect.spawn(cmd, cwd=self.workdir) + fout = open('install_from_scratch.log','w') + child.logfile = fout + child.expect("Database type \(mysql or postgres\):", timeout=timeout) + child.sendline(self.dbtype) + child.expect("Database host \(default: localhost\):", timeout=timeout) + child.sendline(self.dbhost) + child.expect("Database name:", timeout=timeout) + child.sendline(self.projname) + child.expect("Username:", timeout=timeout) + child.sendline(self.dbuser) + child.expect("Password:", timeout=timeout) + child.sendline(self.dbpassword) + child.wait() + fout.close() + self.assertEqual(child.exitstatus, 0) + + path = os.path.join(self.workdir, self.projname) + code, output = runcmd("python manage.py test admin", cwd=path) + self.assertEqual(code, 0) + + +if __name__ == "__main__": + unittest.main()