def test_bundle_path_invalid(bundle_mock): bundle_mock.bundleWithPath_.return_value = None handler = Handler(path='/Applications/Boo.app', content_type='public.plain-text') with pytest.raises(ActionError): handler.process() assert bundle_mock.bundleWithPath_.call_args == mock.call( '/Applications/Boo.app')
def test_url_scheme_same(bundle_mock, copy_url_scheme_mock): bundle_mock.bundleWithPath_( ).bundleIdentifier.return_value = 'com.apple.Safari' copy_url_scheme_mock.return_value = 'com.apple.Safari' handler = Handler(path='/Applications/Safari.app', url_scheme='http') assert handler.process() == ActionResponse(changed=False) assert bundle_mock.bundleWithPath_.call_args == mock.call( '/Applications/Safari.app') assert copy_url_scheme_mock.call_args == mock.call('http')
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_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_url_scheme_invalid(bundle_mock, copy_url_scheme_mock): bundle_mock.bundleWithPath_( ).bundleIdentifier.return_value = 'com.apple.Safari' copy_url_scheme_mock.return_value = None handler = Handler(path='/Applications/Safari.app', url_scheme='hwow') with pytest.raises(ActionError): handler.process() assert bundle_mock.bundleWithPath_.call_args == mock.call( '/Applications/Safari.app') assert copy_url_scheme_mock.call_args == mock.call('hwow')
def test_content_type_invalid(bundle_mock, copy_content_type_mock): bundle_mock.bundleWithPath_( ).bundleIdentifier.return_value = 'com.sublimetext.3' copy_content_type_mock.return_value = None handler = Handler(path='/Applications/Sublime Text.app', content_type='public.boo') with pytest.raises(ActionError): handler.process() assert bundle_mock.bundleWithPath_.call_args == mock.call( '/Applications/Sublime Text.app') assert copy_content_type_mock.call_args == mock.call( 'public.boo', kLSRolesAll)
def test_argument_content_type_url_scheme_empty_combination_invalid(): with pytest.raises(ValueError): Handler(path='/Applications/Sublime Text.app')
def test_argument_url_scheme_after_init_invalid(): handler = Handler(path='/Applications/Sublime Text.app', content_type='public.plain-text') with pytest.raises(ValueError): handler.url_scheme = 'public.plain-text'
def test_argument_content_type_after_init_invalid(): handler = Handler(path='/Applications/Safari.app', url_scheme='http') with pytest.raises(ValueError): handler.content_type = 'public.plain-text'
def test_argument_content_type_url_scheme_combination_invalid(): with pytest.raises(ValueError): Handler(path='/Applications/Safari.app', content_type='public.plain-text', url_scheme='http')
def test_argument_url_scheme_empty_after_init_invalid(): handler = Handler(path='/Applications/Safari.app', url_scheme='http') with pytest.raises(ValueError): handler.url_scheme = None