Example #1
0
def test_get_configuration_mutliple_list_success(**kwargs):
    from python_moonutilities import configuration

    kwargs['mock'].get('http://consul:8500/v1/kv/components/port_start',
                       json=[
                           {'Key': 'port_start', 'Value': comp_util.get_b64_conf("components/port_start")},
                           {'Key': 'port_start', 'Value': comp_util.get_b64_conf("components/port_start")}
                             ]
                       )

    assert len(configuration.get_configuration("components/port_start")) == 2
Example #2
0
def test_get_configuration_mutliple_list_failure(**kwargs):
    from python_moonutilities import configuration

    kwargs['mock'].get('http://consul:8500/v1/kv/components/port_start',
                       json=[
                           {'Key': 'port_start', 'Value': comp_util.get_b64_conf("components/port_start")},
                           {'invalidKey': 'port_start', 'Value': comp_util.get_b64_conf("components/port_start")}
                             ]
                       )
    with pytest.raises(Exception) as exception_info:
        configuration.get_configuration("components/port_start")
    assert str(exception_info.value) == '500: Consul Content error'
Example #3
0
def test_put_increment_port_failure(**kwargs):
    from python_moonutilities import configuration
    kwargs['mock'].put('http://consul:8500/v1/kv/components/port_start', json=[], status_code=400)
    kwargs['mock'].get('http://consul:8500/v1/kv/components/port_start', json=[
        {'Key': 'port_start', 'Value': comp_util.get_b64_conf("components/port_start")}
    ], status_code=200)
    with pytest.raises(Exception) as exception_info:
        configuration.increment_port()
    assert str(exception_info.value) == '500: Consul Content error'
Example #4
0
def register_components(m):
    for component in data_mock.components:
        m.register_uri('GET',
                       'http://consul:8500/v1/kv/{}'.format(component),
                       json=[{
                           'Key': component,
                           'Value': comp_util.get_b64_conf(component)
                       }])

    m.register_uri('PUT',
                   'http://consul:8500/v1/kv/components/port_start',
                   json=[])

    m.register_uri(
        'GET',
        'http://consul:8500/v1/kv/components?recurse=true',
        json=[{
            "Key": key,
            "Value": comp_util.get_b64_conf(key)
        } for key in data_mock.components],
        # json={'Key': "components", 'Value': get_b64_comp_util.CONF("components")}
    )