示例#1
0
def test_process_on_insanity(mocker):
    fake_root = model.Root(1)  # mock, insane
    fake_document = document.Meta(fake_root.primary)
    mocker.patch('furrycorn.toolkit.document.mk_data')
    mocker.patch('furrycorn.toolkit.document.mk_errors')
    mocker.patch('furrycorn.toolkit.document.mk_meta')

    with pytest.raises(RuntimeError):
        toolkit.process(fake_root)

    assert document.mk_data.call_count == 0
    assert document.mk_errors.call_count == 0
    assert document.mk_meta.call_count == 0
示例#2
0
def test_process_on_data(mocker):
    fake_root = model.Root(data.Data(None))  # mock
    fake_document = document.Data(fake_root.primary)
    mocker.patch('furrycorn.toolkit.document.mk_data',
                 return_value=fake_document,
                 autospec=True)

    result = toolkit.process(fake_root)

    assert document.mk_data.call_count == 1
    assert type(result) is document.Data
示例#3
0
def test_process_on_errors(mocker):
    fake_root = model.Root(errors.Errors([]))  # mock
    fake_document = document.Errors(fake_root.primary)
    mocker.patch('furrycorn.toolkit.document.mk_errors',
                 return_value=fake_document,
                 autospec=True)

    result = toolkit.process(fake_root)

    assert document.mk_errors.call_count == 1
    assert type(result) is document.Errors
示例#4
0
from furrycorn.location import mk_origin, mk_path, mk_query, to_url
from furrycorn.toolkit.document import Data, Errors, Meta

api_key = os.environ['BATTLERITE_API_KEY']
origin = mk_origin('https', 'api.dc01.gamelockerapp.com', '/shards/global')
headers = {
    'Accept': 'application/vnd.api+json',
    'Authorization': 'Bearer {0}'.format(api_key)
}
url = to_url(origin, mk_path('/matches'))
request = Request('GET', url, headers=headers).prepare()

with Session() as session:
    response = session.send(request)
    root = model.build(response.json(), config)
    document = toolkit.process(root)

    if type(document) is Data:
        for match in document:
            print('match id "{0}"'.format(match.resource_id.r_id))

            # We know before the 'assets' has one entry--the telmetry. But...
            # madglory exposes this as 'to many', so we dig.
            for asset in match.traverse('assets'):
                if asset.maybe_dict_attrs.get('name', None):
                    url = asset.maybe_dict_attrs['URL']
                    print('  telemetry at: {0}'.format(url))

            # Let's see how many rounds happened this match:
            round_ct = len(match.traverse('rounds'))
            print('  round count: {0}'.format(round_ct))