~ubuntu-branches/ubuntu/wily/system-image/wily-proposed

« back to all changes in this revision

Viewing changes to systemimage/tests/test_settings.py

  • Committer: Package Import Robot
  • Author(s): Ubuntu daily release, Barry Warsaw, Ubuntu daily release
  • Date: 2014-08-01 18:33:39 UTC
  • mfrom: (1.2.25)
  • Revision ID: package-import@ubuntu.com-20140801183339-2h07hrgk8y8eibkn
Tags: 2.3.2-0ubuntu2
[ Barry Warsaw ]
* New upstream release.
  - LP: #1349478 - When system-image-{cli,dbus} is run as non-root, use
    a fallback location for the settings.db file, if the parent
    directory isn't writable.
* d/control:
  - Bump X-Python3-Version to (Python) 3.4.
  - Update run-time dependencies so that system-image-common now depends
    on python3-dbus and python3-xdg, while -dbus and -cli only need to
    depend on system-image-common.

[ Ubuntu daily release ]
* New rebuild forced

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
import os
24
24
import unittest
25
25
 
 
26
from contextlib import ExitStack
 
27
from pathlib import Path
26
28
from systemimage.config import Configuration
 
29
from systemimage.helpers import temporary_directory
27
30
from systemimage.settings import Settings
28
 
from systemimage.testing.helpers import configuration
 
31
from systemimage.testing.helpers import chmod, configuration
 
32
from unittest.mock import patch
29
33
 
30
34
 
31
35
class TestSettings(unittest.TestCase):
99
103
        keyval = list(settings)
100
104
        keyval.sort()
101
105
        self.assertEqual(keyval, [('a', 'ant'), ('b', 'bee'), ('c', 'cat')])
 
106
 
 
107
    @configuration
 
108
    def test_settings_db_permission_denied(self, ini_file):
 
109
        # LP: #1349478 - some tests are run as non-root, meaning they don't
 
110
        # have write permission to /var/lib/system-image.  This is where
 
111
        # settings.db gets created, but if the process can't create files
 
112
        # there, we get a sqlite3 exception.
 
113
        config = Configuration(ini_file)
 
114
        db_file = Path(config.system.settings_db)
 
115
        self.assertFalse(db_file.exists())
 
116
        with ExitStack() as resources:
 
117
            resources.enter_context(chmod(str(db_file.parent), 0o555))
 
118
            # With no fallback, this will fail.
 
119
            with patch('systemimage.settings.Settings._check_fallback',
 
120
                       side_effect=RuntimeError):
 
121
                self.assertRaises(RuntimeError, Settings)
 
122
            # Now, set the XDG cache directory to a temporary directory, allow
 
123
            # the fallback to work and try again.
 
124
            tmpdir = resources.enter_context(temporary_directory())
 
125
            resources.enter_context(
 
126
                patch('systemimage.settings.xdg_cache_home', tmpdir))
 
127
            settings = Settings()
 
128
            settings.set('bar', 'baz')
 
129
            self.assertEqual(Settings().get('bar'), 'baz')
 
130
        # The settings.db file still doesn't exist because it got
 
131
        # created in a different place.
 
132
        self.assertFalse(db_file.exists())