コード例 #1
0
def test_cannot_connect_with_selfsigned_cert_by_default():
    with start_secure_server() as server:
        server.for_path('/sdk/latest-all', poll_content())
        config = Config(sdk_key='sdk_key',
                        base_uri=server.uri,
                        stream=False,
                        send_events=False)
        with LDClient(config=config, start_wait=1.5) as client:
            assert not client.is_initialized()
コード例 #2
0
def test_can_connect_with_selfsigned_cert_by_setting_ca_certs():
    with start_secure_server() as server:
        server.for_path('/sdk/latest-all', poll_content())
        config = Config(sdk_key='sdk_key',
                        base_uri=server.uri,
                        stream=False,
                        send_events=False,
                        http=HTTPConfig(ca_certs='./testing/selfsigned.pem'))
        with LDClient(config=config) as client:
            assert client.is_initialized()
コード例 #3
0
def test_can_connect_with_selfsigned_cert_if_ssl_verify_is_false():
    with start_secure_server() as server:
        server.for_path('/sdk/latest-all', poll_content())
        config = Config(sdk_key='sdk_key',
                        base_uri=server.uri,
                        stream=False,
                        send_events=False,
                        verify_ssl=False)
        with LDClient(config=config) as client:
            assert client.is_initialized()
コード例 #4
0
def test_can_connect_with_selfsigned_cert_if_disable_ssl_verification_is_true(
):
    with start_secure_server() as server:
        server.for_path('/sdk/latest-all', poll_content())
        config = Config(sdk_key='sdk_key',
                        base_uri=server.uri,
                        stream=False,
                        send_events=False,
                        http=HTTPConfig(disable_ssl_verification=True))
        with LDClient(config=config) as client:
            assert client.is_initialized()
コード例 #5
0
def test_client_starts_in_polling_mode():
    with start_server() as poll_server:
        poll_server.for_path('/sdk/latest-all',
                             poll_content([always_true_flag]))
        config = Config(sdk_key=sdk_key,
                        base_uri=poll_server.uri,
                        stream=False,
                        send_events=False)

        with LDClient(config=config) as client:
            assert client.is_initialized()
            assert client.variation(always_true_flag['key'], user,
                                    False) == True

            r = poll_server.await_request()
            assert r.headers['Authorization'] == sdk_key
コード例 #6
0
def test_client_sends_diagnostics():
    with start_server() as poll_server:
        with start_server() as events_server:
            poll_server.for_path('/sdk/latest-all',
                                 poll_content([always_true_flag]))
            events_server.for_path('/diagnostic', BasicResponse(202))

            config = Config(sdk_key=sdk_key,
                            base_uri=poll_server.uri,
                            events_uri=events_server.uri,
                            stream=False)
            with LDClient(config=config) as client:
                assert client.is_initialized()

                r = events_server.await_request()
                assert r.headers['Authorization'] == sdk_key
                data = json.loads(r.body)
                assert data['kind'] == 'diagnostic-init'
コード例 #7
0
def test_client_sends_event_without_diagnostics():
    with start_server() as poll_server:
        with start_server() as events_server:
            poll_server.for_path('/sdk/latest-all',
                                 poll_content([always_true_flag]))
            events_server.for_path('/bulk', BasicResponse(202))

            config = Config(sdk_key=sdk_key,
                            base_uri=poll_server.uri,
                            events_uri=events_server.uri,
                            stream=False,
                            diagnostic_opt_out=True)
            with LDClient(config=config) as client:
                assert client.is_initialized()
                client.identify(user)
                client.flush()

                r = events_server.await_request()
                assert r.headers['Authorization'] == sdk_key
                data = json.loads(r.body)
                assert len(data) == 1
                assert data[0]['kind'] == 'identify'