def test_alias_path_inexistent(tmpdir): dp = tmpdir.join('testing.txt') sp = tmpdir.join('source.txt').ensure() file = File(path=dp.strpath, source=sp.strpath, state='alias') assert file.process() == ActionResponse(changed=True, data={'path': dp.strpath}) assert dp.isfile() alias_data = dp.read_binary() assert alias_data.startswith(b'book') assert b'source.txt' in alias_data
def test_filename_from_url(tmpdir): p = tmpdir.mkdir('directory') download = Download( url= 'https://uhedownloads-heckmannaudiogmb.netdna-ssl.com/releases/Zebra2_28_7422_Mac.zip', path=p.strpath) with vcr.use_cassette(os.path.join(FIXTURE_PATH, 'download', 'u-he.yaml')): assert download.process() == ActionResponse( changed=True, data={'path': os.path.join(p.strpath, 'Zebra2_28_7422_Mac.zip')})
def test_path_inexistent(tmpdir): p = tmpdir.join('test.json') json = JSON(path=p.strpath, values={'python_lover': False}) assert json.process() == ActionResponse(changed=True, data={'path': p.strpath}) assert p.read() == textwrap.dedent('''\ { "python_lover": false } ''')
def test_spotify_string_inexistent(tmpdir, monkeypatch): p = tmpdir.join('prefs').ensure() monkeypatch.setattr(Spotify, 'determine_pref_path', lambda self: p.strpath) spotify = Spotify(values={'autologin.username': '******'}) assert spotify.process() == ActionResponse(changed=True, data={'path': p.strpath}) assert p.read() == textwrap.dedent('''\ autologin.username="******" ''')
def test_url_scheme_different(bundle_mock, copy_url_scheme_mock, set_url_scheme_mock): bundle_mock.bundleWithPath_( ).bundleIdentifier.return_value = 'com.apple.Safari' copy_url_scheme_mock.return_value = 'org.mozilla.firefox' handler = Handler(path='/Applications/Safari.app', url_scheme='http') assert handler.process() == ActionResponse(changed=True) assert copy_url_scheme_mock.call_args == mock.call('http') assert set_url_scheme_mock.call_args == mock.call('http', 'com.apple.Safari')
def test_sound_same(tmpdir, monkeypatch): p = tmpdir.join('com.apple.ncprefs.plist') shutil.copy( os.path.join(FIXTURE_PATH, 'notifications', 'com.apple.ncprefs.plist'), p.strpath) monkeypatch.setattr('elite.actions.notifications.get_ncprefs_plist_path', lambda: p.strpath) notifications = Notifications(path='/Applications/Dropbox.app', sound=True) assert notifications.process() == ActionResponse(changed=False)
def test_spotify_boolean_inexistent(tmpdir, monkeypatch): p = tmpdir.join('prefs').ensure() monkeypatch.setattr(Spotify, 'determine_pref_path', lambda self: p.strpath) spotify = Spotify(values={'ui.show_friend_feed': False}) assert spotify.process() == ActionResponse(changed=True, data={'path': p.strpath}) assert p.read() == textwrap.dedent('''\ ui.show_friend_feed=false ''')
def test_archive_different(tmpdir): dp = tmpdir.mkdir('destination') dp.join('file1.txt').ensure() sp = tmpdir.mkdir('source') sp.join('file2.txt').ensure() sp.join('file3.txt').ensure() rsync = Rsync(dp.strpath, sp.strpath + sp.sep) assert rsync.process() == ActionResponse( changed=True, data={'changes': [('send', 'file2.txt'), ('send', 'file3.txt')]})
def test_path_inexistent(tmpdir): p = tmpdir.join('test.txt') file_info = FileInfo(path=p.strpath) assert file_info.process() == ActionResponse(changed=False, data={ 'exists': False, 'file_type': None, 'source': None, 'mount': None, 'flags': None })
def test_file_without_aliases(tmpdir): p = tmpdir.join('test.txt').ensure() file_info = FileInfo(path=p.strpath, aliases=False) assert file_info.process() == ActionResponse(changed=False, data={ 'exists': True, 'file_type': 'file', 'source': None, 'mount': False, 'flags': [] })
def test_directory(tmpdir): p = tmpdir.mkdir('directory') file_info = FileInfo(path=p.strpath) assert file_info.process() == ActionResponse(changed=False, data={ 'exists': True, 'file_type': 'directory', 'source': None, 'mount': False, 'flags': [] })
def test_alias_exists_different(tmpdir): dp = tmpdir.join('test.alias') shutil.copy(os.path.join(FIXTURE_PATH, 'file', 'test.alias'), dp.strpath) sp = tmpdir.join('source.txt').ensure() file = File(path=dp.strpath, source=sp.strpath, state='alias') assert file.process() == ActionResponse(changed=True, data={'path': dp.strpath}) alias_data = dp.read_binary() assert alias_data.startswith(b'book') assert b'source.txt' in alias_data
def test_absent_not_installed(monkeypatch): monkeypatch.setattr( Pip, 'run', build_run(fixture_subpath='pip', command_mappings=[ CommandMapping( command=['pip', 'list', '--format', 'json'], stdout_filename='pip_list_not_installed.stdout') ])) pip = Pip(name='pycodestyle', state='absent', executable='pip') assert pip.process() == ActionResponse(changed=False)
def test_alert_style_same_modified(tmpdir, monkeypatch): p = tmpdir.join('com.apple.ncprefs.plist') shutil.copy( os.path.join(FIXTURE_PATH, 'notifications', 'com.apple.ncprefs.plist'), p.strpath) monkeypatch.setattr('elite.actions.notifications.get_ncprefs_plist_path', lambda: p.strpath) notifications = Notifications(path='/Applications/Cog.app', alert_style='None') assert notifications.process() == ActionResponse(changed=False)
def test_absent_with_version_not_installed(monkeypatch): monkeypatch.setattr( Gem, 'run', build_run(fixture_subpath='gem', command_mappings=[ CommandMapping( command=['gem', 'specification', '--all', 'rails'], returncode=1) ])) gem = Gem(name='rails', version='5.1.6', state='absent', executable='gem') assert gem.process() == ActionResponse(changed=False)
def test_file_flags(tmpdir): p = tmpdir.join('test.txt').ensure() os.chflags(p.strpath, 0b1000000000000000) file_info = FileInfo(path=p.strpath) assert file_info.process() == ActionResponse(changed=False, data={ 'exists': True, 'file_type': 'file', 'source': None, 'mount': False, 'flags': ['hidden'] })
def test_alias_inexistent(tmpdir): p = tmpdir.join('test.alias') shutil.copy(os.path.join(FIXTURE_PATH, 'file', 'test.alias'), p.strpath) file_info = FileInfo(path=p.strpath) assert file_info.process() == ActionResponse(changed=False, data={ 'exists': True, 'file_type': 'alias', 'source': None, 'mount': False, 'flags': [] })
def test_symlink_inexistent(tmpdir): p = tmpdir.join('testing.txt') p.mksymlinkto('something.txt') file_info = FileInfo(path=p.strpath) assert file_info.process() == ActionResponse(changed=False, data={ 'exists': False, 'file_type': 'symlink', 'source': 'something.txt', 'mount': False, 'flags': [] })
def test_spotify_integer_inexistent(tmpdir, monkeypatch): p = tmpdir.join('prefs').ensure() monkeypatch.setattr(Spotify, 'determine_pref_path', lambda self: p.strpath) spotify = Spotify(values={'audio.sync_bitrate_enumeration': 4}, username='******') assert spotify.process() == ActionResponse(changed=True, data={'path': p.strpath}) assert p.read() == textwrap.dedent('''\ audio.sync_bitrate_enumeration=4 ''')
def test_normal(tmpdir, monkeypatch): kp = tmpdir.join('Damage 1.5.0 Installer Mac.pkg').ensure() cp = tmpdir.join('choices') monkeypatch.setattr( PackageChoices, 'run', build_run(fixture_subpath='package_choices', command_mappings=[ CommandMapping( command=[ 'installer', '-showChoicesAfterApplyingChangesXML', cp.strpath, '-package', kp.strpath, '-target', '/' ], stdout_filename='installer_show_choices_xml.stdout') ])) monkeypatch.setattr('tempfile.mkstemp', lambda: (11, cp.strpath)) package_choices = PackageChoices(kp.strpath) assert package_choices.process() == ActionResponse( changed=False, data={ 'choices': [{ 'attributeSetting': False, 'choiceAttribute': 'visible', 'choiceIdentifier': 'Damage_FactoryContent' }, { 'attributeSetting': False, 'choiceAttribute': 'enabled', 'choiceIdentifier': 'Damage_FactoryContent' }, { 'attributeSetting': 1, 'choiceAttribute': 'selected', 'choiceIdentifier': 'Damage_FactoryContent' }, { 'attributeSetting': True, 'choiceAttribute': 'visible', 'choiceIdentifier': 'Damage_Library' }, { 'attributeSetting': False, 'choiceAttribute': 'enabled', 'choiceIdentifier': 'Damage_Library' }, { 'attributeSetting': 1, 'choiceAttribute': 'selected', 'choiceIdentifier': 'Damage_Library' }, { 'attributeSetting': '/Users/Shared', 'choiceAttribute': 'customLocation', 'choiceIdentifier': 'Damage_Library' }] })
def test_present_installed(monkeypatch): monkeypatch.setattr( Cask, 'run', build_run(fixture_subpath='cask', command_mappings=[ CommandMapping( command=['brew', 'cask', 'list'], stdout_filename='brew_cask_list_installed.stdout') ])) cask = Cask(name='musescore', state='present') assert cask.process() == ActionResponse(changed=False)
def test_present_installed(monkeypatch): monkeypatch.setattr( Brew, 'run', build_run(fixture_subpath='brew', command_mappings=[ CommandMapping( command=['brew', 'list'], stdout_filename='brew_list_installed.stdout') ])) brew = Brew(name='youtube-dl', state='present') assert brew.process() == ActionResponse(changed=False)
def test_content_type_same(bundle_mock, copy_content_type_mock): bundle_mock.bundleWithPath_( ).bundleIdentifier.return_value = 'com.sublimetext.3' copy_content_type_mock.return_value = 'com.sublimetext.3' handler = Handler(path='/Applications/Sublime Text.app', content_type='public.plain-text') assert handler.process() == ActionResponse(changed=False) assert bundle_mock.bundleWithPath_.call_args == mock.call( '/Applications/Sublime Text.app') assert copy_content_type_mock.call_args == mock.call( 'public.plain-text', kLSRolesAll)
def test_choices(tmpdir, monkeypatch): kp = tmpdir.join('West Africa 1.3.0 Installer Mac.pkg').ensure() pp = tmpdir.join('package') shutil.copytree(os.path.join(FIXTURE_PATH, 'package', 'pkg'), pp.strpath) rp = tmpdir.mkdir('receipts') cp = tmpdir.join('choices') monkeypatch.setattr( Package, 'run', build_run(fixture_subpath='cask', command_mappings=[ CommandMapping(command=[ 'xar', '-xf', kp.strpath, '-C', pp.strpath, '^Distribution$', '^PackageInfo$', '/PackageInfo$' ], returncode=0), CommandMapping(command=[ 'installer', '-applyChoiceChangesXML', cp.strpath, '-package', kp.strpath, '-target', '/' ], returncode=0) ])) monkeypatch.setattr('tempfile.mkdtemp', lambda: pp.strpath) monkeypatch.setattr('tempfile.mkstemp', lambda: (11, cp.strpath)) monkeypatch.setattr('os.geteuid', lambda: 0) monkeypatch.setattr('os.remove', lambda path, *, dir_fd=None: None) Package.receipts_dirs = [rp.strpath] package = Package( path=kp.strpath, choices=[{ 'choiceIdentifier': 'WestAfrica_Library', 'choiceAttribute': 'customLocation', 'attributeSetting': '/Volumes/Sample Libraries/Kontakt/Native Instruments' }]) assert package.process() == ActionResponse(changed=True) assert cp.read() == PLIST_HEADER + textwrap.dedent('''\ <plist version="1.0"> <array> <dict> <key>attributeSetting</key> <string>/Volumes/Sample Libraries/Kontakt/Native Instruments</string> <key>choiceAttribute</key> <string>customLocation</string> <key>choiceIdentifier</key> <string>WestAfrica_Library</string> </dict> </array> </plist> '''.replace(' ' * 4, '\t'))
def test_timezone_same(monkeypatch): monkeypatch.setattr( SystemSetup, 'run', build_run(fixture_subpath='system_setup', command_mappings=[ CommandMapping( command=['systemsetup', '-gettimezone'], stdout_filename='systemsetup_timezone_same.stdout') ])) system_setup = SystemSetup(timezone='Australia/Brisbane') assert system_setup.process() == ActionResponse(changed=False)
def test_absent_not_installed(monkeypatch): monkeypatch.setattr( Go, 'run', build_run(fixture_subpath='go', command_mappings=[ CommandMapping( command=['go', 'list', 'all'], stdout_filename='go_list_not_installed.stdout') ])) go = Go(name='github.com/gin-gonic/gin', state='absent') assert go.process() == ActionResponse(changed=False)
def test_absent_not_installed(monkeypatch): monkeypatch.setattr( Tap, 'run', build_run(fixture_subpath='tap', command_mappings=[ CommandMapping( command=['brew', 'tap'], stdout_filename='brew_tap_untapped.stdout') ])) tap = Tap(name='homebrew/cask-fonts', state='absent') assert tap.process() == ActionResponse(changed=False)
def test_display_sleep_time_same(monkeypatch): monkeypatch.setattr( SystemSetup, 'run', build_run( fixture_subpath='system_setup', command_mappings=[ CommandMapping( command=['systemsetup', '-getdisplaysleep'], stdout_filename='systemsetup_display_sleep_same.stdout') ])) system_setup = SystemSetup(display_sleep_time=10) assert system_setup.process() == ActionResponse(changed=False)
def test_local_host_name_same(monkeypatch): monkeypatch.setattr( Hostname, 'run', build_run( fixture_subpath='hostname', command_mappings=[ CommandMapping( command=['scutil', '--get', 'LocalHostName'], stdout_filename='systemsetup_local_host_name_same.stdout') ])) hostname = Hostname(local_host_name='Fotsies-MacBook-Pro') assert hostname.process() == ActionResponse(changed=False)
def test_up_to_date(monkeypatch): monkeypatch.setattr(BrewUpdate, 'run', build_run( fixture_subpath='brew_update', command_mappings=[ CommandMapping( command=['brew', 'update'], stdout_filename='brew_update_up_to_date.stdout' ) ] )) brew_update = BrewUpdate() assert brew_update.process() == ActionResponse(changed=False)