Пример #1
0
def test_pykafka_config(mocker: mock, config: Config):
    ssl_config_sentinel = mock.sentinel.ssl_config
    ssl_config_mock = mocker.patch("esque.config.SslConfig", return_value=ssl_config_sentinel)
    plain_authenticator_sentinel = mock.sentinel.plain_authenticator
    plain_authenticator_mock = mocker.patch(
        "pykafka.sasl_authenticators.PlainAuthenticator", return_value=plain_authenticator_sentinel
    )

    config.context_switch("context_5")
    expected_config = {
        "hosts": "kafka:9094,kafka1:9094,kafka2:9094,kafka3:9094",
        "sasl_authenticator": plain_authenticator_sentinel,
        "ssl_config": ssl_config_sentinel,
    }
    actual_config = config.create_pykafka_config()
    assert expected_config == actual_config
    ssl_config_mock.assert_called_with(
        **{
            "cafile": "/my/ca.crt",
            "certfile": "/my/certificate.crt",
            "keyfile": "/my/certificate.key",
            "password": "******",
        }
    )
    plain_authenticator_mock.assert_called_with(user="******", password="******", security_protocol="SASL_SSL")
Пример #2
0
def test_kafka_python_config(config: Config):
    config.context_switch("context_5")
    expected_config = {
        "bootstrap_servers":
        ["kafka:9094", "kafka1:9094", "kafka2:9094", "kafka3:9094"],
        "security_protocol":
        "SASL_SSL",
        "sasl_mechanism":
        "PLAIN",
        "sasl_plain_username":
        "******",
        "sasl_plain_password":
        "******",
        "ssl_cafile":
        "/my/ca.crt",
        "ssl_certfile":
        "/my/certificate.crt",
        "ssl_keyfile":
        "/my/certificate.key",
        "ssl_password":
        "******",
    }

    actual_config = config.create_kafka_python_config()
    assert expected_config == actual_config
Пример #3
0
def test_ssl_params(config: Config):
    assert config.ssl_params == {}
    config.context_switch("context_5")
    assert config.ssl_params == {
        "cafile": "/my/ca.crt",
        "certfile": "/my/certificate.crt",
        "keyfile": "/my/certificate.key",
        "password": "******",
    }
Пример #4
0
def test_sasl_params(config: Config):
    assert config.sasl_params == {}
    config.context_switch("context_5")
    assert config.sasl_params == {
        "mechanism": "PLAIN",
        "user": "******",
        "password": "******"
    }
    assert config.sasl_mechanism == "PLAIN"
Пример #5
0
def test_current_context_bootstrap_servers(config: Config):
    assert config.bootstrap_servers == ["localhost:9091"]

    config.context_switch("context_3")

    assert config.bootstrap_servers == [
        "node01.cool-domain.com:9093",
        "node02.cool-domain.com:9093",
        "node03.cool-domain.com:9093",
    ]
Пример #6
0
def test_confluent_config(config: Config):
    config.context_switch("context_5")
    expected_config = {
        "bootstrap.servers": "kafka:9094,kafka1:9094,kafka2:9094,kafka3:9094",
        "security.protocol": "SASL_SSL",
        "schema.registry.url": "http://schema-registry.example.com",
        "sasl.mechanisms": "PLAIN",
        "sasl.username": "******",
        "sasl.password": "******",
        "ssl.ca.location": "/my/ca.crt",
        "ssl.certificate.location": "/my/certificate.crt",
        "ssl.key.location": "/my/certificate.key",
        "ssl.key.password": "******",
    }

    actual_config = config.create_confluent_config(include_schema_registry=True)
    assert expected_config == actual_config
Пример #7
0
def test_current_context_hosts(config: Config):
    assert config.bootstrap_hosts == ["localhost"]

    config.context_switch("context_3")

    assert config.bootstrap_hosts == ["node01", "node02", "node03"]
Пример #8
0
def test_context_switch_to_not_existing_context_fails(config: Config):
    assert config.current_context == "context_1"
    with pytest.raises(ContextNotDefinedException):
        config.context_switch("bla")
Пример #9
0
def test_context_switch(config: Config):
    assert config.current_context == "context_1"
    config.context_switch("context_2")
    assert config.current_context == "context_2"
Пример #10
0
def test_current_context_bootstrap_domain(config: Config):
    assert config.bootstrap_domain is None

    config.context_switch("context_2")

    assert config.bootstrap_domain == "dummy_domain"
Пример #11
0
def test_current_context_schema_registry(config: Config):
    with pytest.raises(KeyError):
        _ = config.schema_registry
    config.context_switch("context_5")
    assert config.schema_registry == "http://schema-registry.example.com"
Пример #12
0
def test_default_values(config: Config):
    config.context_switch("context_3")
    assert config.default_num_partitions == 2
    assert config.default_replication_factor == 2
Пример #13
0
def test_config(test_config_path, request):
    esque_config = Config()
    if request.config.getoption("--local"):
        esque_config.context_switch("local")
    yield esque_config