7
from testutils import setup_test_env
8
from tests.utils import (
13
import softwarecenter.log
14
import softwarecenter.paths
11
17
class TestLogging(unittest.TestCase):
12
""" tests the sc logging facilities """
18
"""Tests for the sc logging facilities."""
14
20
def test_no_write_access_for_cache_dir(self):
15
""" test for bug LP: #688682 """
16
# make the test cache dir non-writeable
17
import softwarecenter.paths
18
cache_dir = softwarecenter.paths.SOFTWARE_CENTER_CACHE_DIR
19
# set not-writable (mode 0400)
20
os.chmod(cache_dir, stat.S_IRUSR)
21
self.assertFalse(os.access(cache_dir, os.W_OK))
22
# and then start up the logger
23
import softwarecenter.log
24
softwarecenter.log # pyflakes
25
# check that the old directory was moved aside (renamed with a ".0" appended)
26
self.assertTrue(os.path.exists(cache_dir + ".0"))
27
self.assertFalse(os.path.exists(cache_dir + ".1"))
28
# and check that the new directory was created and is now writable
29
self.assertTrue(os.path.exists(cache_dir))
30
self.assertTrue(os.access(cache_dir, os.W_OK))
21
"""Test for bug LP: #688682."""
24
self.addCleanup(shutil.rmtree, cache_dir)
25
with patch('softwarecenter.paths.SOFTWARE_CENTER_CACHE_DIR',
27
# make the test cache dir non-writeable
28
os.chmod(cache_dir, stat.S_IRUSR)
29
self.addCleanup(os.chmod, cache_dir,
30
stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR)
31
self.assertFalse(os.access(cache_dir, os.W_OK))
33
# and then start up the logger
34
reload(softwarecenter.log)
35
new_cache_dir = cache_dir + ".0"
36
self.addCleanup(shutil.rmtree, new_cache_dir)
38
# check that the old directory was moved aside
39
# (renamed with a ".0" appended)
40
self.assertTrue(os.path.exists(new_cache_dir))
41
self.assertFalse(os.path.exists(cache_dir + ".1"))
42
# and check that the new directory was created and is now writable
43
self.assertTrue(os.access(new_cache_dir, os.R_OK | os.W_OK))
33
46
if __name__ == "__main__":
35
logging.basicConfig(level=logging.DEBUG)