Exemple #1
0
def test_stream_slices_without_state_large_batch():
    conversation_export = ConversationExport(
        start_date=datetime(year=2021, month=7, day=1, hour=12, tzinfo=timezone.utc), batch_size=31, logger=None
    )
    conversation_export.end_timestamp = 1625270400001  # 2021-07-03 00:00:00 + 1 ms
    expected_slices = [{"updated_after": 1625140800000, "updated_before": 1625270400001}]  # 2021-07-01 12:00:00
    actual_slices = conversation_export.stream_slices()
    assert actual_slices == expected_slices
Exemple #2
0
def test_stream_slices_with_start_timestamp_larger_than_state():
    """
    Test that if start_timestamp is larger than state, then start at start_timestamp.
    """
    conversation_export = ConversationExport(
        start_date=datetime(year=2021, month=12, day=1, tzinfo=timezone.utc), batch_size=31, logger=None
    )
    conversation_export.end_timestamp = 1638360000001  # 2021-12-01 12:00:00 + 1 ms
    expected_slices = [{"updated_after": 1638316800000, "updated_before": 1638360000001}]  # 2021-07-01 12:00:00
    actual_slices = conversation_export.stream_slices(stream_state={"updated_at": 1625220000000})  # # 2021-07-02 12:00:00
    assert actual_slices == expected_slices
Exemple #3
0
def test_stream_slices_without_state_large_batch():

    updated_config = config
    updated_config["batch_size"] = 31

    conversation_export = ConversationExport(updated_config)
    conversation_export.end_timestamp = 1625259600000  # 2021-07-03 00:00:00 + 1 ms
    expected_slices = [{
        "updated_after": 1625097600000,
        "updated_before": 1625259600000
    }]  # 2021-07-01 12:00:00 """
    actual_slices = conversation_export.stream_slices()
    assert actual_slices == expected_slices
Exemple #4
0
def test_datetime_to_ms_timestamp():
    assert (
        ConversationExport.datetime_to_ms_timestamp(
            datetime(year=2021, month=7, day=3, hour=11, minute=49, second=40, microsecond=123000, tzinfo=timezone.utc)
        )
        == 1625312980123
    )
Exemple #5
0
def test_stream_slices_with_start_timestamp_larger_than_state():
    #
    # Test that if start_timestamp is larger than state, then start at start_timestamp.
    #
    updated_config = config
    updated_config["start_date"] = "2021-12-01"
    updated_config["batch_size"] = 31

    conversation_export = ConversationExport(updated_config)
    conversation_export.end_timestamp = 1638352800001  # 2021-12-01 12:00:00 + 1 ms
    expected_slices = [{
        "updated_after": 1638316800000,
        "updated_before": 1638352800001
    }]  # 2021-07-01 12:00:00 """
    actual_slices = conversation_export.stream_slices(
        stream_state={"updated_at": 1625216400000})  # # 2021-07-02 12:00:00
    assert actual_slices == expected_slices
Exemple #6
0
def conversation_export():
    return ConversationExport(config)
Exemple #7
0
def test_add_days_to_ms_timestamp():
    assert ConversationExport.add_days_to_ms_timestamp(days=1, milliseconds=1625312980123) == 1625399380123
Exemple #8
0
def test_validate_ms_timestamp_with_invalid_input_length():
    with pytest.raises(ValueError):
        assert ConversationExport._validate_ms_timestamp(1)
Exemple #9
0
def test_validate_ms_timestamp_with_valid_input():
    assert ConversationExport._validate_ms_timestamp(1234567890123) == 1234567890123
Exemple #10
0
def conversation_export():
    return ConversationExport(start_date=datetime(year=2021, month=7, day=1, hour=12, tzinfo=timezone.utc), batch_size=1, logger=None)