def test_empty_file_has_correct_permissions(): from burlap.files import owner, group, mode from burlap.require.files import file as require_file try: run_as_root('touch foo') require_file('bar', use_sudo=True) assert owner('foo') == owner('bar') assert group('foo') == group('bar') assert mode('foo') == mode('bar') finally: run_as_root('rm -f foo bar')
def test_file_with_contents_has_correct_permissions(): from burlap.files import owner, group, mode from burlap.require.files import file as require_file try: run_as_root('echo "something" > foo') require_file('bar', contents='something', use_sudo=True) assert owner('foo') == owner('bar') assert group('foo') == group('bar') assert mode('foo') == mode('bar') finally: run_as_root('rm -f foo bar')
def test_permissions(): from burlap.files import owner, group, mode from burlap.require.files import directory as require_directory try: run_as_root('mkdir foo') require_directory('bar', use_sudo=True) assert owner('foo') == owner('bar') assert group('foo') == group('bar') assert mode('foo') == mode('bar') finally: run_as_root('rmdir foo bar')
def test_git_require_sudo_user(gituser): """ Test working_copy() with sudo as a user """ from burlap.require.git import working_copy username, groupname = gituser with cd('/tmp'): try: working_copy(REMOTE_URL, path='wc_nobody', use_sudo=True, user=username) assert is_dir('wc_nobody') assert is_dir('wc_nobody/.git') with cd('wc_nobody'): remotes = sudo('git remote -v', user=username) assert remotes == \ 'origin\thttps://github.com/chrisspen/burlap.git (fetch)\r\n' \ 'origin\thttps://github.com/chrisspen/burlap.git (push)' assert _current_branch() == 'master' assert owner('wc_nobody') == username assert group('wc_nobody') == groupname finally: run_as_root('rm -rf wc_nobody')
def test_git_require_sudo(): """ Test working_copy() with sudo """ from burlap.require.git import working_copy try: working_copy(REMOTE_URL, path='wc_root', use_sudo=True) assert is_dir('wc_root') assert is_dir('wc_root/.git') with cd('wc_root'): remotes = run('git remote -v') assert remotes == \ 'origin\thttps://github.com/chrisspen/burlap.git (fetch)\r\n' \ 'origin\thttps://github.com/chrisspen/burlap.git (push)' assert _current_branch() == 'master' assert owner('wc_root') == 'root' assert group('wc_root') == 'root' finally: run_as_root('rm -rf wc_root')