Ejemplo n.º 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
Ejemplo n.º 2
0
def test_now():
    assert timestamps.now().tzinfo == timezone.utc
Ejemplo n.º 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()
Ejemplo n.º 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:
Ejemplo n.º 5
0
 def process_events(self):
     LOGGER.debug("Processing events")
     self.last_processed = timestamps.now()
     self.event_stream.process()
Ejemplo n.º 6
0
 def calculate_seconds_since_last_processed(self):
     return (timestamps.now() - self.last_processed).total_seconds()