| 1 | # This file is part of the "Cleverbox" program. |
|---|
| 2 | # |
|---|
| 3 | # Cleverbox is free software: you can redistribute it and/or modify |
|---|
| 4 | # it under the terms of the GNU General Public License as published by |
|---|
| 5 | # the Free Software Foundation, either version 3 of the License, or |
|---|
| 6 | # (at your option) any later version. |
|---|
| 7 | # |
|---|
| 8 | # Cleverbox is distributed in the hope that it will be useful, |
|---|
| 9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 11 | # GNU General Public License for more details. |
|---|
| 12 | # |
|---|
| 13 | # You should have received a copy of the GNU General Public License |
|---|
| 14 | # along with Cleverbox. If not, see <http://www.gnu.org/licenses/>. |
|---|
| 15 | # |
|---|
| 16 | # Copyright 2008, Tristan Rivoallan |
|---|
| 17 | |
|---|
| 18 | import unittest |
|---|
| 19 | from cleverbox.tests import client_test, project_test, environment_test, upgrade_test |
|---|
| 20 | |
|---|
| 21 | def validate_layout(layout): |
|---|
| 22 | |
|---|
| 23 | import grp, os, pwd, stat |
|---|
| 24 | |
|---|
| 25 | for (entry, spec) in layout.items(): |
|---|
| 26 | st = os.stat(entry) |
|---|
| 27 | mode = st[stat.ST_MODE] |
|---|
| 28 | |
|---|
| 29 | # Validate file type |
|---|
| 30 | func = getattr(stat, spec[0]) |
|---|
| 31 | assert func.__call__(mode), '"%s" type is correct (%s)' % (entry, spec[0]) |
|---|
| 32 | |
|---|
| 33 | # Validate file mode |
|---|
| 34 | assert oct(stat.S_IMODE(mode)) == spec[1], '"%s" mode is correct (expected %s, got %s)' % (entry, spec[1], oct(stat.S_IMODE(mode))) |
|---|
| 35 | |
|---|
| 36 | # Validate ownership |
|---|
| 37 | uid = st[stat.ST_UID] |
|---|
| 38 | gid = st[stat.ST_GID] |
|---|
| 39 | expected_uid = pwd.getpwnam(spec[2])[2] |
|---|
| 40 | expected_gid = grp.getgrnam(spec[3])[2] |
|---|
| 41 | assert uid == expected_uid, '"%s" owner is correct (expected %s, got %s)' % (entry, spec[2], pwd.getpwuid(uid)[0]) |
|---|
| 42 | assert gid == expected_gid, '"%s" group is correct (expected %s, got %s)' % (entry, spec[3], grp.getgrgid(uid)[0]) |
|---|
| 43 | |
|---|
| 44 | def create_environment(version): |
|---|
| 45 | |
|---|
| 46 | import os, tempfile |
|---|
| 47 | from cleverbox.model.environment import Environment |
|---|
| 48 | |
|---|
| 49 | test_root = os.path.join(tempfile.gettempdir(), 'cleverbox-tempenv') |
|---|
| 50 | env_path = os.path.join(test_root, 'etc', 'cleverbox') |
|---|
| 51 | os.makedirs(env_path) |
|---|
| 52 | env = Environment(env_path) |
|---|
| 53 | parameters = {'general' : |
|---|
| 54 | {'clients_root' : os.path.join(test_root, 'var', 'cleverbox'), |
|---|
| 55 | 'assets_dir' : os.path.join('/home/trivoallan/workspace/cleverbox-trunk/assets'), |
|---|
| 56 | 'apache_group' : 'www-data', |
|---|
| 57 | 'ssh_user' : 'root', |
|---|
| 58 | 'ssh_group' : 'root', |
|---|
| 59 | 'default_profile' : 'default', |
|---|
| 60 | 'authbackend_pass' : '', |
|---|
| 61 | 'domain' : 'test.domain.tld', |
|---|
| 62 | 'apache_user' : 'www-data', |
|---|
| 63 | 'apache_group' : 'www-data'}, |
|---|
| 64 | 'trac' : |
|---|
| 65 | {'lib_dir' : '/usr/share/python-support/trac', |
|---|
| 66 | 'assets_dir' : '/usr/share/trac'}} |
|---|
| 67 | env.create(version, parameters) |
|---|
| 68 | |
|---|
| 69 | return env |
|---|
| 70 | |
|---|
| 71 | |
|---|
| 72 | def suite(): |
|---|
| 73 | suite = unittest.TestSuite() |
|---|
| 74 | suite.addTest(client_test.suite()) |
|---|
| 75 | suite.addTest(project_test.suite()) |
|---|
| 76 | suite.addTest(environment_test.suite()) |
|---|
| 77 | suite.addTest(upgrade_test.suite()) |
|---|
| 78 | |
|---|
| 79 | return suite |
|---|
| 80 | |
|---|
| 81 | if __name__ == '__main__': |
|---|
| 82 | unittest.main(defaultTest='suite') |
|---|