Exemplo n.º 1
0
def test_build_messages_missing_event(setup):
    context.event_handler_manager = EventHandlerManager()
    event_proto = EventMessage_pb2.Event()
    event_proto.user_id = 1
    event_proto.event_id = 5
    event_proto.event_type = 2
    event_proto.timestamp = 1442502890000
    request = EventRequestBatch([event_proto])
    assert len(request.build_messages()) == 0
Exemplo n.º 2
0
def test_build_messages_multiple_event_msg(setup):
    context.event_handler_manager = EventHandlerManager()
    event_proto = EventMessage_pb2.Event()
    event_proto.user_id = 1
    event_proto.event_id = 1
    event_proto.event_type = 2
    event_proto.timestamp = 1442502890000
    request = EventRequestBatch([event_proto])
    messages = request.build_messages()
    print messages
    assert len(messages) == 2
    assert set([message['message_id'] for message in messages]) == {1, 2}
Exemplo n.º 3
0
def test_build_messages_single_event_msg(setup):
    context.event_handler_manager = EventHandlerManager()
    event_proto = EventMessage_pb2.Event()
    event_proto.user_id = 1
    event_proto.event_id = 2
    event_proto.event_type = 2
    event_proto.timestamp = 1442502890000
    request = EventRequestBatch([event_proto])
    messages = request.build_messages()
    print messages
    assert len(messages) == 1
    assert messages[0]['message_id'] == 3
Exemplo n.º 4
0
def test_login_proto_without_platform_id(mock_log):
    '''Test that a login proto without platform id fails validation.'''
    event_proto = EventMessage_pb2.Event()
    pair = event_proto.pairs.add()
    pair.key = 'deviceToken'
    pair.value = '1234'
    pair = event_proto.pairs.add()
    pair.key = 'applicationVersion'
    pair.value = '1'
    params = dict((pair.key, pair.value) for pair in event_proto.pairs)
    event = EventRequestSingle(123, config.login_event_id, params, 12345)
    assert not LoginEventHandler().validate(event, params)
Exemplo n.º 5
0
def test_valid_login_proto(mock_log):
    '''Test that a valid login proto is validated correctly.'''
    event_proto = EventMessage_pb2.Event()
    pair = event_proto.pairs.add()
    pair.key = 'platformId'
    pair.value = '1'
    pair = event_proto.pairs.add()
    pair.key = 'deviceToken'
    pair.value = '1234'
    pair = event_proto.pairs.add()
    pair.key = 'applicationVersion'
    pair.value = '1'
    params = dict((pair.key, pair.value) for pair in event_proto.pairs)
    event = EventRequestSingle(123, config.login_event_id, params, 12345)
    assert LoginEventHandler().validate(event, params)
Exemplo n.º 6
0
def create_batch_with_login_event(user_id, platform_id, device_token):
    event_proto = EventMessage_pb2.Event()
    # add required parameters
    pair = event_proto.pairs.add()
    pair.key = 'platformId'
    pair.value = str(platform_id)
    pair = event_proto.pairs.add()
    pair.key = 'deviceToken'
    pair.value = device_token
    pair = event_proto.pairs.add()
    pair.key = 'applicationVersion'
    pair.value = '1'
    params = dict((pair.key, pair.value) for pair in event_proto.pairs)
    event = EventRequestSingle(user_id, config.login_event_id, params,
                               1442502890000)
    return event
Exemplo n.º 7
0
def event_batch_proto():
    '''Return a valid event request'''
    event_request_proto = EventMessage_pb2.BatchEventRequest()
    event_proto = event_request_proto.events.add()
    event_proto.user_id = 123
    event_proto.event_id = 1
    event_proto.event_type = 2
    event_proto.timestamp = 12345
    # add some parameters
    pair = event_proto.pairs.add()
    pair.key = 'some_constant'
    pair.value = '6'
    pair = event_proto.pairs.add()
    pair.key = 'world_id'
    pair.value = '1'
    return event_request_proto.SerializeToString()
Exemplo n.º 8
0
 def init_input_format(self, body):
     proto_request = EventMessage_pb2.BatchEventRequest()
     proto_request.ParseFromString(body)
     return proto_request