~gary-lasker/software-center/cherrypick-for-5.2.2.1

« back to all changes in this revision

Viewing changes to test/test_logging.py

  • Committer: Michael Vogt
  • Date: 2012-05-15 07:51:29 UTC
  • mfrom: (2989.17.8 software-center)
  • Revision ID: michael.vogt@ubuntu.com-20120515075129-szlkcz1nqcs0qu46
merge lp:~gary-lasker/software-center/fix-makedirs-race-crashes and add small test for test_safe_makedirs

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/python
 
2
 
 
3
import os
 
4
import stat
 
5
import unittest
 
6
 
 
7
from testutils import setup_test_env
 
8
setup_test_env()
 
9
 
 
10
 
 
11
class TestLogging(unittest.TestCase):
 
12
    """ tests the sc logging facilities """
 
13
 
 
14
    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))
 
31
 
 
32
 
 
33
if __name__ == "__main__":
 
34
    import logging
 
35
    logging.basicConfig(level=logging.DEBUG)
 
36
    unittest.main()