Пример #1
0
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')
Пример #2
0
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')
Пример #3
0
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')
Пример #4
0
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)
Пример #5
0
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')
Пример #6
0
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)
Пример #7
0
def test_argument_content_type_url_scheme_empty_combination_invalid():
    with pytest.raises(ValueError):
        Handler(path='/Applications/Sublime Text.app')
Пример #8
0
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'
Пример #9
0
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'
Пример #10
0
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')
Пример #11
0
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