Пример #1
0
async def test_fill_queue(service: EventService):

    queue = []
    service.record_event('1-2-3', 1, queue)
    service.record_event('2-3-4', 4, queue)

    assert queue == [
        dict(event_id='1-2-3', count=1),
        dict(event_id='2-3-4', count=4),
    ]
Пример #2
0
async def test_fill_queue(service: EventService):

    queue = []
    service.record_event("1-2-3", 0, queue)
    service.record_event("1-2-3", 1, queue)
    service.record_event("2-3-4", 4, queue)

    assert queue == [
        dict(event_id="1-2-3", count=1),
        dict(event_id="2-3-4", count=4),
    ]
Пример #3
0
async def test_record_multiple(service: EventService):
    content = '''{"updated_events": [
        { "event_id": "1-2-3", "count": 1},
        { "event_id": "2-3-4", "count": 4}
    ]}'''.encode('utf-8')
    service.api_accessor.api_post = CoroMock(return_value=(None, content))

    queue = []
    service.record_event('1-2-3', 1, queue)
    service.record_event('2-3-4', 4, queue)

    assert queue == [
        dict(event_id='1-2-3', count=1),
        dict(event_id='2-3-4', count=4),
    ]

    result = await service.execute_batch_update(42, queue)
    assert result == json.loads(content.decode('utf-8'))['updated_events']

    service.api_accessor.api_post.assert_called_once_with("/events/recordMultiple", 42, data=dict(updates=queue))
Пример #4
0
def service(api_accessor: ApiAccessor):
    return EventService(api_accessor)
Пример #5
0
def event_service(api_accessor):
    from server.stats.event_service import EventService
    return EventService(api_accessor)