mirror of
https://github.com/Tech-Workers-Coalition-Italia/mobilizon-reshare.git
synced 2025-02-16 11:40:54 +01:00
query: Add get_event_publications.
This commit is contained in:
parent
04f29e37e4
commit
cf9ffd2149
@ -150,6 +150,13 @@ async def get_event(event_mobilizon_id: UUID) -> Event:
|
||||
return events[0]
|
||||
|
||||
|
||||
async def get_event_publications(
|
||||
mobilizon_event: MobilizonEvent,
|
||||
) -> list[EventPublication]:
|
||||
event = await get_event(mobilizon_event.mobilizon_id)
|
||||
return [publication_from_orm(p, mobilizon_event) for p in event.publications]
|
||||
|
||||
|
||||
async def get_mobilizon_event(event_mobilizon_id: UUID) -> MobilizonEvent:
|
||||
return event_from_model(await get_event(event_mobilizon_id))
|
||||
|
||||
|
@ -1,16 +1,19 @@
|
||||
from datetime import timedelta
|
||||
from uuid import UUID
|
||||
|
||||
import arrow
|
||||
import pytest
|
||||
|
||||
from mobilizon_reshare.event.event import EventPublicationStatus
|
||||
from mobilizon_reshare.models.publication import PublicationStatus
|
||||
from mobilizon_reshare.publishers.abstract import EventPublication
|
||||
from mobilizon_reshare.storage.query.read import (
|
||||
get_published_events,
|
||||
events_with_status,
|
||||
publications_with_status,
|
||||
events_without_publications,
|
||||
build_publications,
|
||||
get_event_publications,
|
||||
)
|
||||
from tests import today
|
||||
from tests.storage import complete_specification
|
||||
@ -54,7 +57,7 @@ async def test_get_published_events(generate_models):
|
||||
],
|
||||
)
|
||||
async def test_publications_with_status(
|
||||
status, mobilizon_id, from_date, to_date, expected_result, generate_models,
|
||||
status, mobilizon_id, from_date, to_date, expected_result, generate_models,
|
||||
):
|
||||
await generate_models(complete_specification)
|
||||
publications = await publications_with_status(
|
||||
@ -81,33 +84,33 @@ async def test_event_with_status(generate_models, status, expected_events_count)
|
||||
"status, expected_events_count, begin_window, end_window",
|
||||
[
|
||||
(
|
||||
EventPublicationStatus.COMPLETED,
|
||||
2,
|
||||
arrow.get(today + timedelta(hours=-1)),
|
||||
None,
|
||||
EventPublicationStatus.COMPLETED,
|
||||
2,
|
||||
arrow.get(today + timedelta(hours=-1)),
|
||||
None,
|
||||
),
|
||||
(
|
||||
EventPublicationStatus.COMPLETED,
|
||||
1,
|
||||
arrow.get(today + timedelta(hours=1)),
|
||||
None,
|
||||
EventPublicationStatus.COMPLETED,
|
||||
1,
|
||||
arrow.get(today + timedelta(hours=1)),
|
||||
None,
|
||||
),
|
||||
(
|
||||
EventPublicationStatus.COMPLETED,
|
||||
1,
|
||||
arrow.get(today + timedelta(hours=-2)),
|
||||
arrow.get(today + timedelta(hours=1)),
|
||||
EventPublicationStatus.COMPLETED,
|
||||
1,
|
||||
arrow.get(today + timedelta(hours=-2)),
|
||||
arrow.get(today + timedelta(hours=1)),
|
||||
),
|
||||
(
|
||||
EventPublicationStatus.COMPLETED,
|
||||
0,
|
||||
arrow.get(today + timedelta(hours=-2)),
|
||||
arrow.get(today + timedelta(hours=0)),
|
||||
EventPublicationStatus.COMPLETED,
|
||||
0,
|
||||
arrow.get(today + timedelta(hours=-2)),
|
||||
arrow.get(today + timedelta(hours=0)),
|
||||
),
|
||||
],
|
||||
)
|
||||
async def test_event_with_status_window(
|
||||
generate_models, status, expected_events_count, begin_window, end_window
|
||||
generate_models, status, expected_events_count, begin_window, end_window
|
||||
):
|
||||
await generate_models(complete_specification)
|
||||
result = list(
|
||||
@ -123,23 +126,23 @@ async def test_event_with_status_window(
|
||||
[
|
||||
({"event": 2, "publications": [], "publisher": ["zulip"]}, [event_0, event_1],),
|
||||
(
|
||||
{
|
||||
"event": 3,
|
||||
"publications": [
|
||||
{
|
||||
"event_idx": 1,
|
||||
"publisher_idx": 0,
|
||||
"status": PublicationStatus.FAILED,
|
||||
},
|
||||
{
|
||||
"event_idx": 2,
|
||||
"publisher_idx": 0,
|
||||
"status": PublicationStatus.COMPLETED,
|
||||
},
|
||||
],
|
||||
"publisher": ["zulip"],
|
||||
},
|
||||
[event_0],
|
||||
{
|
||||
"event": 3,
|
||||
"publications": [
|
||||
{
|
||||
"event_idx": 1,
|
||||
"publisher_idx": 0,
|
||||
"status": PublicationStatus.FAILED,
|
||||
},
|
||||
{
|
||||
"event_idx": 2,
|
||||
"publisher_idx": 0,
|
||||
"status": PublicationStatus.COMPLETED,
|
||||
},
|
||||
],
|
||||
"publisher": ["zulip"],
|
||||
},
|
||||
[event_0],
|
||||
),
|
||||
(complete_specification, [event_3],),
|
||||
],
|
||||
@ -157,26 +160,26 @@ async def test_events_without_publications(spec, expected_events, generate_model
|
||||
[
|
||||
([], {"event": 2, "publications": [], "publisher": ["zulip"]}, event_0, 0,),
|
||||
(
|
||||
["zulip"],
|
||||
{"event": 2, "publications": [], "publisher": ["zulip"]},
|
||||
event_0,
|
||||
1,
|
||||
["zulip"],
|
||||
{"event": 2, "publications": [], "publisher": ["zulip"]},
|
||||
event_0,
|
||||
1,
|
||||
),
|
||||
(
|
||||
["telegram", "zulip", "mastodon", "facebook"],
|
||||
{
|
||||
"event": 2,
|
||||
"publications": [],
|
||||
"publisher": ["telegram", "zulip", "mastodon", "facebook"],
|
||||
},
|
||||
event_0,
|
||||
4,
|
||||
["telegram", "zulip", "mastodon", "facebook"],
|
||||
{
|
||||
"event": 2,
|
||||
"publications": [],
|
||||
"publisher": ["telegram", "zulip", "mastodon", "facebook"],
|
||||
},
|
||||
event_0,
|
||||
4,
|
||||
),
|
||||
],
|
||||
indirect=["mock_active_publishers"],
|
||||
)
|
||||
async def test_build_publications(
|
||||
mock_active_publishers, spec, event, n_publications, generate_models
|
||||
mock_active_publishers, spec, event, n_publications, generate_models
|
||||
):
|
||||
await generate_models(spec)
|
||||
|
||||
@ -187,3 +190,52 @@ async def test_build_publications(
|
||||
for p in publications:
|
||||
assert p.event == event
|
||||
assert p.publisher.name in mock_active_publishers
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.parametrize(
|
||||
"mock_active_publishers, spec, event, publications_ids",
|
||||
[
|
||||
(
|
||||
["telegram", "zulip", "mastodon", "facebook"],
|
||||
{"event": 2, "publications": [], "publisher": ["zulip"]},
|
||||
event_0,
|
||||
[],
|
||||
),
|
||||
(
|
||||
["telegram", "zulip", "mastodon", "facebook"],
|
||||
{
|
||||
"event": 2,
|
||||
"publications": [
|
||||
{
|
||||
"event_idx": 1,
|
||||
"publisher_idx": 0,
|
||||
"status": PublicationStatus.COMPLETED,
|
||||
},
|
||||
{
|
||||
"event_idx": 0,
|
||||
"publisher_idx": 0,
|
||||
"status": PublicationStatus.FAILED,
|
||||
},
|
||||
],
|
||||
"publisher": ["zulip"],
|
||||
},
|
||||
event_1,
|
||||
# This tuples are made like so: (event_mobilizon_id, publication_id)
|
||||
[(UUID(int=1), UUID(int=0))],
|
||||
),
|
||||
],
|
||||
indirect=["mock_active_publishers"],
|
||||
)
|
||||
async def test_get_event_publications(
|
||||
mock_active_publishers, spec, event, publications_ids, generate_models
|
||||
):
|
||||
await generate_models(spec)
|
||||
|
||||
publications = list(await get_event_publications(event))
|
||||
|
||||
assert len(publications) == len(publications_ids)
|
||||
|
||||
for i, p in enumerate(publications):
|
||||
assert p.event.mobilizon_id == publications_ids[i][0]
|
||||
assert p.id == publications_ids[i][1]
|
||||
|
Loading…
x
Reference in New Issue
Block a user