コード例 #1
0
def test_add_extra_params_to_message():
    currentTime = fetch_current_time_in_milliseconds()
    msgToBePublished = sampleDecodedMessageFromPubSub.copy()
    expectedResult = [{
        "user_id":
        msgToBePublished["user_id"],
        "event_type":
        msgToBePublished["event_type"],
        "time_transaction_occurred":
        msgToBePublished["time_transaction_occurred"],
        "context":
        msgToBePublished["context"],
        "created_at":
        currentTime,
        "updated_at":
        currentTime,
        "source_of_event":
        SOURCE_OF_EVENT
    }]

    assert add_extra_params_to_message([msgToBePublished],
                                       currentTime) == expectedResult
コード例 #2
0
def test_fetch_current_time_in_milliseconds():
    assert fetch_current_time_in_milliseconds() == int(
        round(time.time() * SECOND_TO_MILLISECOND_FACTOR))
コード例 #3
0
    decode_message_from_pubsub, \
    fetch_current_time_in_milliseconds, \
    add_extra_params_to_message, \
    format_message_and_insert_into_all_user_events

import main

dataset_id = main.dataset_id
table_id = main.table_id
client = main.client
table_ref = main.table_ref
table = main.table
SOURCE_OF_EVENT = constant.SOURCE_OF_EVENT
SECOND_TO_MILLISECOND_FACTOR = constant.SECOND_TO_MILLISECOND_FACTOR

time_in_milliseconds_now = fetch_current_time_in_milliseconds()

sampleDecodedMessageFromPubSub = {
    "user_id": "1a",
    "event_type": "3k",
    "time_transaction_occurred": time_in_milliseconds_now,
    "context": "{}"
}
sampleDecodedMessageAsList = [sampleDecodedMessageFromPubSub]

sampleFormattedMessageForAllEventsTable = [
    {
        "user_id": "1a",
        "event_type": "3k",
        "time_transaction_occurred": time_in_milliseconds_now,
        "context": "{}",