~nataliabidart/software-center/birth-of-a-website.1

« back to all changes in this revision

Viewing changes to tests/test_logging.py

  • Committer: Michael Vogt
  • Date: 2012-06-11 15:58:19 UTC
  • mfrom: (3020.1.9 the-organizer)
  • Revision ID: michael.vogt@ubuntu.com-20120611155819-rfz96g7s7bysskrt
mergedĀ lp:~nataliabidart/software-center/the-organizer

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/python
2
 
 
3
1
import os
 
2
import shutil
4
3
import stat
5
4
import unittest
6
5
 
7
 
from testutils import setup_test_env
 
6
from mock import patch
 
7
 
 
8
from tests.utils import (
 
9
    setup_test_env,
 
10
)
8
11
setup_test_env()
9
12
 
 
13
import softwarecenter.log
 
14
import softwarecenter.paths
 
15
 
10
16
 
11
17
class TestLogging(unittest.TestCase):
12
 
    """ tests the sc logging facilities """
 
18
    """Tests for the sc logging facilities."""
13
19
 
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."""
 
22
        cache_dir = './foo'
 
23
        os.mkdir(cache_dir)
 
24
        self.addCleanup(shutil.rmtree, cache_dir)
 
25
        with patch('softwarecenter.paths.SOFTWARE_CENTER_CACHE_DIR',
 
26
                    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))
 
32
 
 
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)
 
37
 
 
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))
31
44
 
32
45
 
33
46
if __name__ == "__main__":
34
 
    import logging
35
 
    logging.basicConfig(level=logging.DEBUG)
36
47
    unittest.main()