Exemple #1
0
def test_create_and_get_event_with_process_after():
    connection = data_access.connect(DSN)
    event = Event(topic="foo", process_after=timestamps.now() + timedelta(seconds=10))
    with data_access.cursor(connection) as cursor:
        created = data_access.create_event(cursor, event)

    with data_access.cursor(connection) as cursor:
        retrieved = data_access.get_event_by_id(cursor, created.id)

    assert retrieved.process_after == event.process_after
Exemple #2
0
def test_now():
    assert timestamps.now().tzinfo == timezone.utc
Exemple #3
0
def test_process_events(app):
    app.event_stream = Mock()
    app.process_events()

    app.event_stream.process.assert_called_once()
    assert app.last_processed == timestamps.now()
Exemple #4
0
        retrieved = data_access.get_event_by_id(cursor, created.id)

    assert retrieved.process_after == event.process_after


@pytest.mark.parametrize(
    [
        "first_process_after",
        "second_process_after",
        "expected_first_status",
        "expected_second_status",
    ],
    [
        [None, None, constants.PROCESSED, constants.PROCESSED,],
        [
            timestamps.now() + timedelta(seconds=10),
            None,
            constants.PENDING,
            constants.PROCESSED,
        ],
    ],
)
def test_get_next_event(
    first_process_after,
    second_process_after,
    expected_first_status,
    expected_second_status,
):
    connection = data_access.connect(DSN)
    topic = "foo"
    with data_access.cursor(connection) as cursor:
Exemple #5
0
 def process_events(self):
     LOGGER.debug("Processing events")
     self.last_processed = timestamps.now()
     self.event_stream.process()
Exemple #6
0
 def calculate_seconds_since_last_processed(self):
     return (timestamps.now() - self.last_processed).total_seconds()