2021-11-11 16:20:50 +01:00
|
|
|
from logging import DEBUG
|
|
|
|
|
|
|
|
import pytest
|
|
|
|
|
2022-03-02 08:59:57 +01:00
|
|
|
from mobilizon_reshare.cli.commands.recap.main import recap
|
2021-11-11 16:20:50 +01:00
|
|
|
from mobilizon_reshare.models.publication import PublicationStatus
|
2022-07-12 07:39:56 +02:00
|
|
|
from mobilizon_reshare.main.publish import CommandConfig
|
2021-11-24 23:58:06 +01:00
|
|
|
|
|
|
|
spec = {
|
|
|
|
# We need three events since recap will print only
|
|
|
|
# future events, but the 0th event happens at today + 0.
|
|
|
|
"event": 3,
|
|
|
|
"publications": [
|
|
|
|
{"event_idx": 1, "publisher_idx": 0, "status": PublicationStatus.COMPLETED},
|
|
|
|
{"event_idx": 2, "publisher_idx": 0, "status": PublicationStatus.COMPLETED},
|
|
|
|
],
|
|
|
|
"publisher": ["zulip"],
|
|
|
|
}
|
2021-11-11 16:20:50 +01:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize(
|
2022-07-12 07:39:56 +02:00
|
|
|
"publisher_class", [pytest.lazy_fixture("mock_publisher_class")]
|
2021-11-11 16:20:50 +01:00
|
|
|
)
|
|
|
|
@pytest.mark.asyncio
|
2022-07-12 07:39:56 +02:00
|
|
|
async def test_recap_event_from_db(
|
|
|
|
caplog,
|
|
|
|
mock_publisher_config,
|
|
|
|
mock_now,
|
|
|
|
message_collector,
|
|
|
|
generate_models,
|
|
|
|
command_config,
|
2021-11-11 16:20:50 +01:00
|
|
|
):
|
2021-11-24 23:58:06 +01:00
|
|
|
await generate_models(spec)
|
2021-11-11 16:20:50 +01:00
|
|
|
|
|
|
|
with caplog.at_level(DEBUG):
|
|
|
|
# calling the recap command
|
2022-07-12 07:39:56 +02:00
|
|
|
report = await recap(command_config)
|
2021-11-11 16:20:50 +01:00
|
|
|
assert report.successful
|
|
|
|
|
|
|
|
assert "Found 2 events to recap" in caplog.text
|
|
|
|
|
|
|
|
recap_message = """Upcoming
|
|
|
|
|
2021-11-24 23:58:06 +01:00
|
|
|
event_1
|
2021-11-11 16:20:50 +01:00
|
|
|
|
2021-11-24 23:58:06 +01:00
|
|
|
event_2"""
|
|
|
|
assert message_collector == [recap_message]
|
2022-07-12 07:39:56 +02:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
|
|
@pytest.mark.parametrize(
|
|
|
|
"dry_run", [True, False]
|
|
|
|
) # the behavior should be identical with and without dry-run
|
|
|
|
async def test_recap_no_event(caplog, mock_now, message_collector, dry_run):
|
|
|
|
|
|
|
|
with caplog.at_level(DEBUG):
|
|
|
|
# calling the recap command
|
|
|
|
report = await recap(CommandConfig(dry_run=dry_run))
|
|
|
|
assert report is None
|
|
|
|
|
|
|
|
assert "Found no events" in caplog.text
|
|
|
|
|
|
|
|
assert message_collector == []
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
|
|
"publisher_class", [pytest.lazy_fixture("mock_publisher_invalid_class")]
|
|
|
|
)
|
|
|
|
@pytest.mark.asyncio
|
|
|
|
async def test_recap_event_dry_run(
|
|
|
|
caplog, mock_publisher_config, mock_now, message_collector, generate_models
|
|
|
|
):
|
|
|
|
await generate_models(spec)
|
|
|
|
|
|
|
|
with caplog.at_level(DEBUG):
|
|
|
|
# calling the recap command
|
|
|
|
reports = await recap(CommandConfig(dry_run=True))
|
|
|
|
assert reports.successful
|
|
|
|
|
|
|
|
assert "Found 2 events to recap" in caplog.text
|
|
|
|
|
|
|
|
assert message_collector == []
|
|
|
|
|
|
|
|
recap_message = """Upcoming
|
|
|
|
|
|
|
|
event_1
|
|
|
|
|
|
|
|
event_2"""
|
|
|
|
|
|
|
|
for report in reports.reports:
|
|
|
|
assert report.published_content == recap_message
|