| 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 grp, logging, os, pwd, shutil, stat, tempfile, unittest |
|---|
| 19 | from cleverbox.model.environment import Environment |
|---|
| 20 | import cleverbox.tests |
|---|
| 21 | |
|---|
| 22 | # Don't bother with output from scripts |
|---|
| 23 | logging.basicConfig(stream=open('/dev/null', 'w+')) |
|---|
| 24 | |
|---|
| 25 | class EnvironmentTestCase(unittest.TestCase): |
|---|
| 26 | |
|---|
| 27 | # Fixtures |
|---|
| 28 | def setUp(self): |
|---|
| 29 | self.env = cleverbox.tests.create_environment('0.5test') |
|---|
| 30 | |
|---|
| 31 | def tearDown(self): |
|---|
| 32 | pass |
|---|
| 33 | shutil.rmtree(self.env.path) |
|---|
| 34 | shutil.rmtree(self.env.config.get('general', 'clients_root')) |
|---|
| 35 | |
|---|
| 36 | def test_create(self): |
|---|
| 37 | """Environment.create() generates a correct directory layout.""" |
|---|
| 38 | |
|---|
| 39 | expected = {self.env.get_path('VERSION') : ('S_ISREG', '0640', 'root', 'www-data'), |
|---|
| 40 | self.env.get_path('cleverbox.ini') : ('S_ISREG', '0640', 'root', 'www-data'), |
|---|
| 41 | self.env.get_path('clients-available') : ('S_ISDIR', '0750', 'root', 'www-data'), |
|---|
| 42 | self.env.get_path('clients-enabled') : ('S_ISDIR', '0750', 'root', 'www-data'), |
|---|
| 43 | self.env.get_path('projects-available') : ('S_ISDIR', '0750', 'root', 'www-data'), |
|---|
| 44 | self.env.get_path('projects-enabled') : ('S_ISDIR', '0750', 'root', 'www-data'), |
|---|
| 45 | self.env.get_path('profiles') : ('S_ISDIR', '0750', 'root', 'www-data'), |
|---|
| 46 | self.env.get_path('profiles/default') : ('S_ISDIR', '0750', 'root', 'www-data'), |
|---|
| 47 | self.env.get_path('profiles/default/trac-defaults.ini') : ('S_ISREG', '0640', 'root', 'www-data'), |
|---|
| 48 | self.env.get_path('profiles/default/project.apache.conf') : ('S_ISREG', '0640', 'root', 'www-data'), |
|---|
| 49 | self.env.get_path('profiles/default/permissions.ini') : ('S_ISREG', '0640', 'root', 'www-data'), |
|---|
| 50 | self.env.config.get('general', 'clients_root') : ('S_ISDIR', '0750', 'root', 'www-data')} |
|---|
| 51 | |
|---|
| 52 | cleverbox.tests.validate_layout(expected) |
|---|
| 53 | |
|---|
| 54 | def test_create_creates_enough_elements(self): |
|---|
| 55 | """Environment.create() creates the right number of elements on filesystem.""" |
|---|
| 56 | assert len(os.listdir(self.env.path)) == 7 |
|---|
| 57 | assert len(os.listdir(os.path.join(self.env.path, 'profiles'))) == 1 |
|---|
| 58 | assert len(os.listdir(os.path.join(self.env.path, 'profiles', 'default'))) == 3 |
|---|
| 59 | |
|---|
| 60 | def test_needs_upgrade_triggers_when_needs(self): |
|---|
| 61 | """Environment.needs_upgrade() returns true if environment needs an upgrade.""" |
|---|
| 62 | assert self.env.needs_upgrade('0.6') |
|---|
| 63 | |
|---|
| 64 | def test_needs_upgrade_does_not_trigger_when_unneeded(self): |
|---|
| 65 | """Environment.needs_upgrade() returns false if environment does not need an upgrade.""" |
|---|
| 66 | assert self.env.needs_upgrade('0.4') == False |
|---|
| 67 | |
|---|
| 68 | def test_get_version(self): |
|---|
| 69 | """Environment.get_version() returns the right version number.""" |
|---|
| 70 | assert self.env.get_version() == '0.5test' |
|---|
| 71 | |
|---|
| 72 | def test_get_path(self): |
|---|
| 73 | """Environment.get_path() returns the right path.""" |
|---|
| 74 | assert self.env.get_path('TEST') == os.path.join(self.env.path, 'TEST') |
|---|
| 75 | |
|---|
| 76 | |
|---|
| 77 | def suite(): |
|---|
| 78 | return unittest.makeSuite(EnvironmentTestCase, 'test') |
|---|
| 79 | |
|---|
| 80 | if __name__ == '__main__': |
|---|
| 81 | unittest.main(defaultTest='suite') |
|---|