def test_integrated_shift_dir_dry_run(self, mock_walk, mock_join, mock_lstat, mock_lchown): mock_walk.return_value = [('/tmp/test', ['a', 'b', 'c'], ['d']), ('/tmp/test/d', ['1', '2'], [])] mock_join.side_effect = join_side_effect def lstat(path): stats = { 't': FakeStat(0, 0), 'a': FakeStat(0, 0), 'b': FakeStat(0, 2), 'c': FakeStat(30000, 30000), 'd': FakeStat(100, 100), '1': FakeStat(0, 100), '2': FakeStat(100, 100), } return stats[path[-1]] mock_lstat.side_effect = lstat idmapshift.shift_dir('/tmp/test', self.uid_maps, self.gid_maps, idmapshift.NOBODY_ID, dry_run=True, verbose=True) self.assertEqual(0, len(mock_lchown.mock_calls))
def test_shift_dir_dry_run(self, mock_walk, mock_join, mock_shift_path): mock_walk.return_value = [('/', ['a', 'b'], ['c', 'd'])] mock_join.side_effect = join_side_effect idmapshift.shift_dir('/', self.uid_maps, self.gid_maps, idmapshift.NOBODY_ID, dry_run=True) mock_walk.assert_has_calls([mock.call('/')]) files = ['a', 'b', 'c', 'd'] mock_join_calls = [mock.call('/', x) for x in files] mock_join.assert_has_calls(mock_join_calls) args = (self.uid_maps, self.gid_maps, idmapshift.NOBODY_ID) kwargs = dict(dry_run=True, verbose=False, uid_memo=dict(), gid_memo=dict()) shift_path_calls = [mock.call('/', *args, **kwargs)] shift_path_calls += [ mock.call('/' + x, *args, **kwargs) for x in files ] mock_shift_path.assert_has_calls(shift_path_calls)
def test_integrated_shift_dir(self, mock_walk, mock_join, mock_lstat, mock_lchown): mock_walk.return_value = [('/tmp/test', ['a', 'b', 'c'], ['d']), ('/tmp/test/d', ['1', '2'], [])] mock_join.side_effect = join_side_effect def lstat(path): stats = { 't': FakeStat(0, 0), 'a': FakeStat(0, 0), 'b': FakeStat(0, 2), 'c': FakeStat(30000, 30000), 'd': FakeStat(100, 100), '1': FakeStat(0, 100), '2': FakeStat(100, 100), } return stats[path[-1]] mock_lstat.side_effect = lstat idmapshift.shift_dir('/tmp/test', self.uid_maps, self.gid_maps, idmapshift.NOBODY_ID, verbose=True) lchown_calls = [ mock.call('/tmp/test', 10000, 10000), mock.call('/tmp/test/a', 10000, 10000), mock.call('/tmp/test/b', 10000, 10002), mock.call('/tmp/test/c', idmapshift.NOBODY_ID, idmapshift.NOBODY_ID), mock.call('/tmp/test/d', 20090, 20090), mock.call('/tmp/test/d/1', 10000, 20090), mock.call('/tmp/test/d/2', 20090, 20090), ] mock_lchown.assert_has_calls(lchown_calls)
def test_shift_dir(self, mock_walk, mock_join, mock_shift_path): mock_walk.return_value = [('/', ['a', 'b'], ['c', 'd'])] mock_join.side_effect = join_side_effect idmapshift.shift_dir('/', self.uid_maps, self.gid_maps, idmapshift.NOBODY_ID) files = ['a', 'b', 'c', 'd'] mock_walk.assert_has_calls([mock.call('/')]) mock_join_calls = [mock.call('/', x) for x in files] mock_join.assert_has_calls(mock_join_calls) args = (self.uid_maps, self.gid_maps, idmapshift.NOBODY_ID) kwargs = dict(dry_run=False, verbose=False, uid_memo=dict(), gid_memo=dict()) shift_path_calls = [mock.call('/', *args, **kwargs)] shift_path_calls += [mock.call('/' + x, *args, **kwargs) for x in files] mock_shift_path.assert_has_calls(shift_path_calls)