def test_create_ioerror(chown): chown.side_effect = IOError('Disk is borked') with temporary_dir() as d: ds = DirectorySandbox(d) with pytest.raises(DirectorySandbox.CreationError): ds.create()
def test_create_ioerror(chown): chown.side_effect = IOError('Disk is borked') with temporary_dir() as d: real_path = os.path.join(d, 'sandbox') ds = DirectorySandbox(real_path) with pytest.raises(DirectorySandbox.CreationError): ds.create()
def test_create_no_user(*args): with temporary_dir() as d: ds = DirectorySandbox(d) ds.create() assert os.path.exists(ds.root) for mocked in args: mocked.assert_not_called()
def test_destroy_ioerror(): with temporary_dir() as d: ds = DirectorySandbox(d) ds.create() with mock.patch('shutil.rmtree') as shutil_rmtree: shutil_rmtree.side_effect = IOError('What even are you doing?') with pytest.raises(DirectorySandbox.DeletionError): ds.destroy()
def test_user_does_not_exist(getpwnam): getpwnam.side_effect = KeyError('johndoe') with temporary_dir() as d: ds = DirectorySandbox(d, 'cletus') with pytest.raises(DirectorySandbox.CreationError): ds.create() getpwnam.assert_called_with('cletus')
def test_create_no_user(*args): with temporary_dir() as d: real_path = os.path.join(d, 'sandbox') ds = DirectorySandbox(real_path) ds.create() assert os.path.exists(real_path) for mocked in args: mocked.assert_not_called()
def test_user_does_not_exist(getpwnam): getpwnam.side_effect = KeyError("johndoe") with temporary_dir() as d: real_path = os.path.join(d, "sandbox") ds = DirectorySandbox(real_path, "cletus") with pytest.raises(DirectorySandbox.CreationError): ds.create() getpwnam.assert_called_with("cletus")
def test_destroy_ioerror(): with temporary_dir() as d: real_path = os.path.join(d, "sandbox") ds = DirectorySandbox(real_path) ds.create() with mock.patch("shutil.rmtree") as shutil_rmtree: shutil_rmtree.side_effect = IOError("What even are you doing?") with pytest.raises(DirectorySandbox.DeletionError): ds.destroy()
def test_directory_sandbox(): with temporary_dir() as d: ds1 = DirectorySandbox(os.path.join(d, 'task1')) ds2 = DirectorySandbox(os.path.join(d, 'task2')) ds1.create() ds2.create() assert os.path.exists(ds1.root) assert os.path.exists(ds2.root) ds1.destroy() assert not os.path.exists(ds1.root) assert os.path.exists(ds2.root) ds2.destroy() assert not os.path.exists(ds2.root)
def test_create(chmod, chown, getpwnam, getgrgid): getgrgid.return_value.gr_name = 'foo' getpwnam.return_value.pw_gid = 123 getpwnam.return_value.pw_uid = 456 with temporary_dir() as d: real_path = os.path.join(d, 'sandbox') ds = DirectorySandbox(real_path, 'cletus') ds.create() assert os.path.exists(real_path) getpwnam.assert_called_with('cletus') getgrgid.assert_called_with(123) chown.assert_called_with(real_path, 456, 123) chmod.assert_called_with(real_path, 0700)
def test_create(chmod, chown, getpwnam, getgrgid): getgrgid.return_value.gr_name = 'foo' getpwnam.return_value.pw_gid = 123 getpwnam.return_value.pw_uid = 456 with temporary_dir() as mesos_dir: ds = DirectorySandbox(mesos_dir, 'cletus') ds.create() assert os.path.exists(ds.root) getpwnam.assert_called_with('cletus') getgrgid.assert_called_with(123) chown.assert_any_call(mesos_dir, 456, 123) chown.assert_any_call(ds.root, 456, 123) chmod.assert_called_with(ds.root, 0700)