def test_service_list_replace_from_decription():
    expected = [
        BaseService(name='ReplacedService',
                    hosts_list=['replaced_host.local']),
        WhitelistService(name='WhitelistService',
                         hosts_list=['whitelist_me.local']),
    ]

    service_list = ServiceList([
        BaseService(name='OriginalService',
                    hosts_list=['original_host.local']),
    ])

    service_list.replace_from_descrition([{
        'type':
        'BaseService',
        'name':
        'ReplacedService',
        'hosts_list': ['replaced_host.local'],
    }, {
        'type': 'WhitelistService',
        'name': 'WhitelistService',
        'hosts_list': ['whitelist_me.local'],
    }])

    assert list(service_list) == expected
def test_service_list_prepend():
    expected = [
        BaseService(name='Service', hosts_list=['host.local']),
        WhitelistService(name='WhitelistService',
                         hosts_list=['whitelist_me.local']),
    ]

    service_list = ServiceList([
        WhitelistService(name='WhitelistService',
                         hosts_list=['whitelist_me.local']),
    ])

    service_list.prepend(BaseService(name='Service',
                                     hosts_list=['host.local']))

    assert list(service_list) == expected
def dispatcher() -> Dispatcher:
    return Dispatcher(service_list=[
        WhitelistService(
            name='WhitelistService',
            hosts_list=['test-indexer'],
        ),
    ])
Esempio n. 4
0
def test_load_services_from_os():
    expected_whitelist = ['my-indexer', 'my-worker']
    custom_environ = {'MITM_PROXY_WHITELIST': 'my-indexer my-worker'}

    with patch.dict(os.environ, custom_environ):
        service = WhitelistService(name='WhitelistService')
        whitelist = service.hosts_list

    assert whitelist == expected_whitelist
Esempio n. 5
0
def test_env_services_have_priority():
    expected_whitelist = ['test-indexer', 'test-scrapyd', 'test-web-e2e.local']

    custom_environ = {'MITM_PROXY_WHITELIST': ' '.join(expected_whitelist)}

    with patch.dict(os.environ, custom_environ):
        service = WhitelistService(name='WhitelistService', hosts_list=[])

    whitelist = service.hosts_list

    assert whitelist == expected_whitelist
def test_service_list_to_dict():
    service_list = ServiceList([
        BaseService(name='TestName',
                    hosts_list=['test_host.local', 'test_host2.local']),
        WhitelistService(name='TestWhitelist', hosts_list=['test_host.local']),
    ])

    expected_description = [
        {
            'type': 'BaseService',
            'name': 'TestName',
            'hosts_list': ['test_host.local', 'test_host2.local'],
        },
        {
            'type': 'WhitelistService',
            'name': 'TestWhitelist',
            'hosts_list': ['test_host.local'],
        },
    ]

    result_service = service_list.to_list()

    assert expected_description == result_service
                    hosts_list=['test_host.local', 'test_host2.local']),
    ),
    (
        {
            'name': 'TestName',
            'hosts_list': ['test_host.local'],
        },
        BaseService(name='TestName', hosts_list=['test_host.local']),
    ),
    (
        {
            'type': 'WhitelistService',
            'name': 'TestWhitelist',
            'hosts_list': ['test_host.local'],
        },
        WhitelistService(name='TestWhitelist', hosts_list=['test_host.local']),
    ),
],
                  ids=(
                      'base service with two hosts',
                      'base service with implicit BaseService type',
                      'whitelist service',
                  ))
def test_service_list_instantiate_service_from_dict(
    service_description: Dict[str, Any],
    expected_service: BaseService,
):
    service_list = ServiceList([])

    result_service = service_list._instantiate_service_from_dict(
        service_description)