Changeset View
Changeset View
Standalone View
Standalone View
swh/search/tests/test_cli.py
# Copyright (C) 2019-2020 The Software Heritage developers | # Copyright (C) 2019-2020 The Software Heritage developers | ||||||||
# See the AUTHORS file at the top-level directory of this distribution | # See the AUTHORS file at the top-level directory of this distribution | ||||||||
# License: GNU General Public License version 3, or any later version | # License: GNU General Public License version 3, or any later version | ||||||||
# See top-level LICENSE file for more information | # See top-level LICENSE file for more information | ||||||||
import copy | import copy | ||||||||
from datetime import datetime, timezone | |||||||||
import tempfile | import tempfile | ||||||||
from click.testing import CliRunner | from click.testing import CliRunner | ||||||||
from confluent_kafka import Producer | from confluent_kafka import Producer | ||||||||
import pytest | import pytest | ||||||||
import yaml | import yaml | ||||||||
from swh.journal.serializers import value_to_kafka | from swh.journal.serializers import value_to_kafka | ||||||||
▲ Show 20 Lines • Show All 158 Lines • ▼ Show 20 Lines | producer = Producer( | ||||||||
"client.id": "test search origin visit status producer", | "client.id": "test search origin visit status producer", | ||||||||
"acks": "all", | "acks": "all", | ||||||||
} | } | ||||||||
) | ) | ||||||||
topic = f"{kafka_prefix}.origin_visit_status" | topic = f"{kafka_prefix}.origin_visit_status" | ||||||||
value = value_to_kafka( | value = value_to_kafka( | ||||||||
{ | { | ||||||||
"origin": origin_foobar["url"], | "origin": origin_foobar["url"], | ||||||||
"visit": 1, | "visit": 1, | ||||||||
KShivendu: Note that here I've assumed that `to_dict` function of `OriginVisitStatus` translates `datetime. | |||||||||
Not Done Inline Actions
from datetime import datetime, timezone assuming this top-level import ;) ardumont: ```
from datetime import datetime, timezone
```
assuming this top-level import ;) | |||||||||
"date": datetime.now(tz=timezone.utc), | |||||||||
"snapshot": None, | "snapshot": None, | ||||||||
"status": "full", | "status": "full", | ||||||||
} | } | ||||||||
) | ) | ||||||||
producer.produce(topic=topic, key=b"bogus-origin-visit-status", value=value) | producer.produce(topic=topic, key=b"bogus-origin-visit-status", value=value) | ||||||||
journal_objects_config = JOURNAL_OBJECTS_CONFIG_TEMPLATE.format( | journal_objects_config = JOURNAL_OBJECTS_CONFIG_TEMPLATE.format( | ||||||||
broker=kafka_server, prefix=kafka_prefix, group_id="test-consumer" | broker=kafka_server, prefix=kafka_prefix, group_id="test-consumer" | ||||||||
▲ Show 20 Lines • Show All 251 Lines • Show Last 20 Lines |
Note that here I've assumed that to_dict function of OriginVisitStatus translates datetime.datetime object to string before passing to Kafka. That's why I've converted datetime.now() to string and hopefully it emulates the same behaviour.