Ejemplo n.º 1
0
async def test_client_initializes_automatically_with_every_api_method(
        method, server, client):
    client.format_order_requests = True
    global received
    global status

    data = tuple(
        get_valid_primitive_data(param.annotation)
        for param in method[1].__signature__.parameters.values()
        if param.name != "self")
    status = 200
    method = getattr(client, method[0])
    try:
        resp = await method(*data)
    except (
            KeyError,
            ServerDisconnectedError,
            ContentTypeError,
            AttributeError,
            UnexpectedStatus,
    ):
        pass  # Caused by incorrect response status being returned
        # Server not keeping a data stream open
        # Response Not containing expected data
    if getattr(method, "initialize_required", True):
        assert client.initialized
    else:
        assert not client.initialized
Ejemplo n.º 2
0
async def test_client_methods_send_correct_data(method, server, client):
    client.format_order_requests = True
    data = tuple(
        get_valid_primitive_data(param.annotation)
        for param in method[1].__signature__.parameters.values()
        if param.name != 'self')
    async with client as client:  # initialize first
        method = getattr(client, method[0])
        server_module.status = next(iter(method.endpoint.responses))
        try:
            resp = await method(*data)
        except (KeyError, ServerDisconnectedError, ContentTypeError,
                AttributeError):
            pass  # Caused by incorrect response status being returned
Ejemplo n.º 3
0
async def test_client_methods_send_correct_data(method, server, client):
    data = tuple(get_valid_primitive_data(param.annotation)
                 for param in method[1].__signature__.parameters.values()
                 if param.name != 'self')
    async with client as client:  # initialize first
        method = getattr(client, method[0])
        server_module.status = next(iter(method.endpoint.responses))
        try:
            resp = await method(*data)
        except (KeyError, ServerDisconnectedError, ContentTypeError, AttributeError):
            pass  # Caused by incorrect response status being returned
            # Server not keeping a data stream open
            # Response Not containing expected data
        # TODO Added meaning full asserts
        print(server_module.received)
Ejemplo n.º 4
0
from async_v20.definitions.base import create_attribute
from async_v20.definitions.types import OrderRequest
from tests.test_definitions.helpers import get_valid_primitive_data, create_cls_annotations
from async_v20.exceptions import UnknownKeywordArgument, InstantiationFailure
import logging
logger = logging.getLogger('async_v20')
logger.disabled = True

model_classes = (cls for cls in (getattr(types, typ) for typ in types.__all__)
                 if issubclass(cls, Model))

model_classes_data = []

for cls in model_classes:
    try:
        model_classes_data.append((cls, get_valid_primitive_data(cls)))
    except Exception as ex:
        ...


@pytest.mark.parametrize('cls, data', model_classes_data)
def test_all_order_requests_have_an_instrument_parameter(cls, data):
    if issubclass(cls, OrderRequest):
        assert hasattr(cls, 'instrument')

        result = cls(**data)
        assert getattr(result, 'instrument')


# @pytest.mark.parametrize('cls, data', model_classes_data)
# def test_class_annotations_match_the_parents_class_annotations(cls, data):
Ejemplo n.º 5
0
def test_get_valid_primitive_data(primitive):
    """Test the helper function can provide valid data for all primitives"""
    assert get_valid_primitive_data(primitive)
Ejemplo n.º 6
0
def test_primitives_return_correct_type_when_initialized_with_value(primitive):
    if primitive == DateTime:
        assert type(primitive(get_valid_primitive_data(primitive))) == pd.Timestamp
    else:
        assert type(primitive(get_valid_primitive_data(primitive))) == primitive
Ejemplo n.º 7
0
def test_primitives_return_correct_type_when_initialized_with_value(primitive):
    assert type(primitive(get_valid_primitive_data(primitive))) == primitive
Ejemplo n.º 8
0
import pytest

from async_v20.definitions import types
from async_v20.definitions.base import Model
from async_v20.definitions.base import create_attribute
from async_v20.definitions.types import OrderRequest
from tests.test_definitions.helpers import get_valid_primitive_data, create_cls_annotations
from async_v20.exceptions import UnknownKeywordArgument, InstantiationFailure
import logging
logger = logging.getLogger('async_v20')
logger.disabled = True

model_classes = (cls for cls in (getattr(types, typ) for typ in types.__all__)
                 if issubclass(cls, Model))

model_classes_data = [(cls, get_valid_primitive_data(cls))
                      for cls in model_classes]


@pytest.mark.parametrize('cls, data', model_classes_data)
def test_all_order_requests_have_an_instrument_parameter(cls, data):
    if issubclass(cls, OrderRequest):
        assert hasattr(cls, 'instrument')

        result = cls(**data)
        assert getattr(result, 'instrument')


@pytest.mark.parametrize('cls, data', model_classes_data)
def test_class_annotations_match_the_parents_class_annotations(cls, data):
    if not cls.__bases__[0] == Model: