185
205
self.assertFalse(os.path.exists(b_path))
186
206
self.assertTrue(os.path.exists(c_path))
208
def _make_ownership_test(self):
209
path = os.path.join(self.temp_dir, "a", "1.0")
210
touch(os.path.join(path, ".click", "info", "a.manifest"))
211
os.symlink("1.0", os.path.join(self.temp_dir, "a", "current"))
212
user_path = os.path.join(
213
self.temp_dir, ".click", "users", "test-user", "a")
214
os.makedirs(os.path.dirname(user_path))
215
os.symlink(path, user_path)
216
touch(os.path.join(self.temp_dir, ".click", "log"))
218
def test_clickpkg_paths(self):
219
self._make_ownership_test()
220
self.assertCountEqual([
222
os.path.join(self.temp_dir, ".click"),
223
os.path.join(self.temp_dir, ".click", "log"),
224
os.path.join(self.temp_dir, ".click", "users"),
225
os.path.join(self.temp_dir, "a"),
226
os.path.join(self.temp_dir, "a", "1.0"),
227
os.path.join(self.temp_dir, "a", "1.0", ".click"),
228
os.path.join(self.temp_dir, "a", "1.0", ".click", "info"),
230
self.temp_dir, "a", "1.0", ".click", "info", "a.manifest"),
231
os.path.join(self.temp_dir, "a", "current"),
232
], list(self.db._clickpkg_paths()))
234
@mock.patch("pwd.getpwnam")
235
@mock.patch("os.chown")
236
def test_ensure_ownership_quick_if_correct(self, mock_chown,
238
mock_getpwnam.return_value = MockPasswd(pw_uid=1, pw_gid=1)
239
self._make_ownership_test()
240
with mock.patch("os.stat") as mock_stat:
241
mock_stat.side_effect = (
242
lambda path, *args, **kwargs: MockStatResult(
243
path, st_uid=1, st_gid=1))
244
self.db.ensure_ownership()
245
self.assertFalse(mock_chown.called)
247
@mock.patch("pwd.getpwnam")
248
@mock.patch("os.chown")
249
def test_ensure_ownership(self, mock_chown, mock_getpwnam):
250
mock_getpwnam.return_value = MockPasswd(pw_uid=1, pw_gid=1)
251
self._make_ownership_test()
252
with mock.patch("os.stat") as mock_stat:
253
mock_stat.side_effect = (
254
lambda path, *args, **kwargs: MockStatResult(
255
path, st_uid=2, st_gid=2))
256
self.db.ensure_ownership()
257
self.assertCountEqual([
259
os.path.join(self.temp_dir, ".click"),
260
os.path.join(self.temp_dir, ".click", "log"),
261
os.path.join(self.temp_dir, ".click", "users"),
262
os.path.join(self.temp_dir, "a"),
263
os.path.join(self.temp_dir, "a", "1.0"),
264
os.path.join(self.temp_dir, "a", "1.0", ".click"),
265
os.path.join(self.temp_dir, "a", "1.0", ".click", "info"),
267
self.temp_dir, "a", "1.0", ".click", "info", "a.manifest"),
268
os.path.join(self.temp_dir, "a", "current"),
269
], [args[0][0] for args in mock_chown.call_args_list])
270
self.assertCountEqual(
271
[(1, 1)], set(args[0][1:] for args in mock_chown.call_args_list))
189
274
class TestClickDB(TestCase):