Пример #1
0
def test_build(
    mocker,
    http_client_mock,
    converter_factory_mock,
    fake_service_cls,
    transaction_hook_mock,
):
    # Monkey-patch the Builder class.
    builder_cls_mock = mocker.Mock()
    builder_mock = builder.Builder()
    builder_cls_mock.return_value = builder_mock
    mocker.patch.object(builder, "Builder", builder_cls_mock)

    builder.build(
        fake_service_cls,
        base_url="example.com",
        client=http_client_mock,
        converter=converter_factory_mock,
        auth=("username", "password"),
        hook=transaction_hook_mock,
    )
    assert builder_mock.base_url == "example.com"
    assert builder_mock.client is http_client_mock
    assert list(builder_mock.converters)[0] is converter_factory_mock
    assert isinstance(builder_mock.auth, auth.BasicAuth)
Пример #2
0
def test_build(mocker, http_client_mock, fake_service_cls):
    # Monkey-patch the Builder class.
    builder_cls_mock = mocker.Mock()
    builder_mock = mocker.Mock(spec=builder.Builder)
    builder_cls_mock.return_value = builder_mock
    mocker.patch.object(builder, "Builder", builder_cls_mock)

    builder.build(fake_service_cls,
                  base_url="example.com",
                  client=http_client_mock)
    assert builder_mock.base_url == "example.com"
    builder_mock.add_converter_factory.assert_called_with()
    assert builder_mock.client is http_client_mock
Пример #3
0
def test_build(mocker, http_client_mock, converter_factory_mock,
               fake_service_cls):
    # Monkey-patch the Builder class.
    builder_cls_mock = mocker.Mock()
    builder_mock = builder.Builder()
    builder_cls_mock.return_value = builder_mock
    mocker.patch.object(builder, "Builder", builder_cls_mock)

    builder.build(fake_service_cls,
                  base_url="example.com",
                  client=http_client_mock,
                  converter=converter_factory_mock)
    assert builder_mock.base_url == "example.com"
    assert builder_mock.client is http_client_mock
    assert list(builder_mock.converters)[0] is converter_factory_mock
Пример #4
0
def test_inject(mocker, fake_service_cls, transaction_hook_mock):
    # Monkey-patch the Builder class.
    builder_cls_mock = mocker.Mock()
    builder_mock = mocker.Mock(wraps=builder.Builder())
    builder_cls_mock.return_value = builder_mock
    mocker.patch.object(builder, "Builder", builder_cls_mock)

    service = builder.build(fake_service_cls)

    # Verify
    service._inject(transaction_hook_mock)
    builder_mock.add_hook.assert_called_with(transaction_hook_mock)
Пример #5
0
def test_build_failure(fake_service_cls):
    exception = exceptions.InvalidRequestDefinition()
    fake_service_cls.builder.build.side_effect = exception
    fake_service_cls.builder.__name__ = "builder"
    with pytest.raises(exceptions.UplinkBuilderError):
        builder.build(fake_service_cls, base_url="example.com")