Ejemplo n.º 1
0
async def test_construct_arguments(signature, bound_arguments, args):
    """Ensure that the annotation lookup dictionary is built correctly"""
    result = construct_arguments(signature, bound_arguments)
    for annotation, instance in result.items():
        if isinstance(instance, bool):
            assert issubclass(annotation, Bool)
        else:
            assert type(instance) == annotation
Ejemplo n.º 2
0
async def test_construct_arguments(client, server, signature, arguments):
    """Ensure that the annotation lookup dictionary is built correctly"""
    await client.initialize()
    result = construct_arguments(client, signature, **arguments)
    for annotation, instance in result.items():
        if isinstance(instance, bool):
            assert issubclass(annotation, Bool)
        elif isinstance(instance, pd.Timestamp):
            assert issubclass(annotation, DateTime)
        else:
            assert type(instance) == annotation
Ejemplo n.º 3
0
async def test_create_request_params(client, method, signature, kwargs):
    """Test that all every argument supplied to an endpoint goes into the HTTP request"""

    endpoint = method.endpoint
    arguments = construct_arguments(client, signature, **kwargs)
    total_params = []
    for location in locations:
        result = _create_request_params(client, endpoint, arguments, location)
        total_params.extend(result)

    # These parameters are set by default in the client.
    # They will appear in total_arguments even though they were not passed
    # therefore We will remove them
    for default_param in ['Authorization', 'LastTransactionID', 'Accept-Datetime-Format',
                          'accountID']:
        try:
            total_params.remove(default_param)
        except ValueError:
            continue

    assert len(total_params) == len(arguments) - len(list(endpoint.request_schema))
Ejemplo n.º 4
0
async def test_create_request_kwargs(client, server, method, signature, kwargs):

    await client.initialize()
    client.format_order_requests = True
    args = construct_arguments(client, signature, **kwargs)
    if OrderRequest in args:
        args.update({OrderRequest: OrderRequest(instrument='AUD_USD', units=1)})

    request_kwargs = create_request_kwargs(client, method.endpoint, args)

    # Make sure args are not empty
    assert request_kwargs.get('method', 1)
    assert request_kwargs.get('url', 1)
    assert request_kwargs.get('headers', 1)
    assert request_kwargs.get('params', 1)
    assert request_kwargs.get('json', 1)

    assert [request_kwargs['method']] in [['POST'], ['GET'], ['PUT'], ['PATCH'], ['DELETE']]

    auth_in_header = 'Authorization' in request_kwargs.get('headers', '')
    if Authorization in method.endpoint.parameters:
        assert auth_in_header
    else:
        assert not auth_in_header
Ejemplo n.º 5
0
async def test_create_request_params(client, interface_method):
    """Test that all every argument supplied to an endpoint goes into the HTTP request"""

    endpoint = interface_method.endpoint
    sig = interface_method.__signature__
    print(interface_method.__name__)
    args = tuple(
        get_valid_primitive_data(param.annotation)
        for param in sig.parameters.values() if param.kind == 1)
    bound = dict(sig.bind(*args).arguments)
    arguments = construct_arguments(sig, bound)
    total_params = []
    print(endpoint.request_schema)
    for location in locations:
        print('Endpoint: ', endpoint)
        print('Arguments: ', arguments)
        print('Location: ', location)
        result = _create_request_params(client, endpoint, arguments, location)
        print('Possible Arguments', list(_arguments(endpoint, arguments)))
        print(location, ': ', result)
        total_params.extend(result)

    # These parameters are set by default in the client.
    # They will appear in total_arguments even though they were not passed
    # therefore We will remove them
    for default_param in [
            'Authorization', 'LastTransactionID', 'Accept-Datetime-Format',
            'accountID'
    ]:
        try:
            total_params.remove(default_param)
        except ValueError:
            continue

    assert len(total_params) == len(arguments) - len(
        list(endpoint.request_schema))