def _make_test_publication(publication_id, status, event_id, publisher_id):
    return Publication(
        id=UUID(int=publication_id),
        status=status,
        timestamp=today + timedelta(hours=publication_id),
        event_id=UUID(int=event_id),
        publisher_id=UUID(int=publisher_id),
    )
async def publications_with_status(
    status: PublicationStatus,
    from_date: Optional[Arrow] = None,
    to_date: Optional[Arrow] = None,
) -> Iterable[Publication]:
    query = Publication.filter(status=status)

    return await prefetch_publication_relations(
        _add_date_window(query, "timestamp", from_date, to_date))
示例#3
0
async def failed_publication(stored_event) -> Publication:

    p = Publication(
        event=stored_event,
        status=PublicationStatus.FAILED,
        timestamp=arrow.now().datetime,
        publisher=await get_publisher_by_name("mock"),
    )
    await p.save()
    return p
async def get_publication(publication_id):
    try:
        publication = await prefetch_publication_relations(
            Publication.get(id=publication_id).first())
        # TODO: this is redundant but there's some prefetch problem otherwise
        publication.event = await get_event(publication.event.mobilizon_id)
        return publication_from_orm(event=event_from_model(publication.event),
                                    model=publication)
    except DoesNotExist:
        return None
示例#5
0
 async def build_publication_by_publisher_name(
         self,
         publisher_name: str,
         status: PublicationStatus = PublicationStatus.FAILED
 ) -> Publication:
     publisher = await Publisher.filter(name=publisher_name).first()
     return Publication(
         status=status,
         event_id=self.id,
         publisher_id=publisher.id,
         publisher=publisher,
     )
示例#6
0
 def _publication_model_generator(
     status=PublicationStatus.COMPLETED,
     publication_time=datetime(year=2021, month=1, day=1, hour=11, minute=30),
     event_id=None,
     publisher_id=None,
 ):
     return Publication(
         status=status,
         timestamp=publication_time,
         event_id=event_id,
         publisher_id=publisher_id,
     )
async def mock_publications(
    num_publications: int,
    test_event: MobilizonEvent,
    mock_publisher_valid,
    mock_formatter_valid,
):
    result = []
    for i in range(num_publications):
        event = event_to_model(test_event)
        await event.save()
        publisher = Publisher(name="telegram")
        await publisher.save()
        publication = PublicationModel(
            id=UUID(int=i + 1),
            event=event,
            publisher=publisher,
            timestamp=today + timedelta(hours=i),
            reason=None,
        )
        publication = publication_from_orm(publication, test_event)
        publication.publisher = mock_publisher_valid
        publication.formatter = mock_formatter_valid
        result.append(publication)
    return result
示例#8
0
                        status=PublicationStatus.COMPLETED,
                        reason="",
                        publication=EventPublication(
                            id=UUID(int=6),
                            formatter=TelegramFormatter(),
                            event=event_1,
                            publisher=TelegramPublisher(),
                        ),
                    ),
                ],
            ),
            event_1,
            {
                UUID(int=6):
                Publication(id=UUID(int=6),
                            status=PublicationStatus.COMPLETED,
                            reason=""),
            },
        ],
    ],
)
async def test_save_publication_report(
    specification,
    report,
    event,
    expected_result,
    generate_models,
):
    await generate_models(specification)
    known_publication_ids = set(p.id for p in await Publication.all())
async def get_all_publications(
    from_date: Optional[Arrow] = None,
    to_date: Optional[Arrow] = None,
) -> Iterable[EventPublication]:
    return await prefetch_publication_relations(
        _add_date_window(Publication.all(), "timestamp", from_date, to_date))