Skip to content

Commit

Permalink
Fix tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
fishinthecalculator committed Dec 7, 2022
1 parent 39b63f8 commit a7e7b05
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 15 deletions.
11 changes: 8 additions & 3 deletions mobilizon_reshare/storage/query/read.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,22 @@ def _filter_event_with_status(event: Event) -> bool:


async def get_all_publications(
from_date: Optional[Arrow] = None, to_date: Optional[Arrow] = None,
from_date: Optional[Arrow] = None,
to_date: Optional[Arrow] = None,
) -> Iterable[Publication]:
return await prefetch_publication_relations(
_add_date_window(Publication.all(), "timestamp", from_date, to_date)
)


async def get_all_mobilizon_events(
from_date: Optional[Arrow] = None, to_date: Optional[Arrow] = None,
from_date: Optional[Arrow] = None,
to_date: Optional[Arrow] = None,
) -> list[MobilizonEvent]:
return [MobilizonEvent.from_model(event) for event in await get_all_events()]
return [
MobilizonEvent.from_model(event)
for event in await get_all_events(from_date, to_date)
]


async def get_all_events(
Expand Down
6 changes: 4 additions & 2 deletions tests/commands/test_publish.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

from mobilizon_reshare.main.publish import select_and_publish, publish_event
from mobilizon_reshare.models.notification import NotificationStatus, Notification
from mobilizon_reshare.storage.query.converter import event_from_model
from mobilizon_reshare.event.event import EventPublicationStatus, MobilizonEvent
from mobilizon_reshare.models.event import Event
from mobilizon_reshare.models.publication import PublicationStatus
Expand Down Expand Up @@ -157,4 +156,7 @@ async def test_notify_publisher_failure(
)

# the derived status for the event should be FAILED
assert event_from_model(event_model).status == EventPublicationStatus.FAILED
assert (
MobilizonEvent.from_model(event_model).status
== EventPublicationStatus.FAILED
)
12 changes: 9 additions & 3 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def generate_event_status(published):


def generate_notification_status(published):
return NotificationStatus.COMPLETED if published else NotificationStatus.WAITING
return NotificationStatus.COMPLETED if published else NotificationStatus.FAILED


@pytest.fixture(scope="session", autouse=True)
Expand Down Expand Up @@ -438,7 +438,10 @@ def mock_mobilizon_success_answer(mobilizon_answer, mobilizon_url):
with responses.RequestsMock() as rsps:

rsps.add(
responses.POST, mobilizon_url, json=mobilizon_answer, status=200,
responses.POST,
mobilizon_url,
json=mobilizon_answer,
status=200,
)
yield

Expand All @@ -450,7 +453,10 @@ def mock_multiple_success_answer(multiple_answers, mobilizon_url):

for answer in multiple_answers:
rsps.add(
responses.POST, mobilizon_url, json=answer, status=200,
responses.POST,
mobilizon_url,
json=answer,
status=200,
)

yield
Expand Down
12 changes: 5 additions & 7 deletions tests/storage/test_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

from mobilizon_reshare.event.event import EventPublicationStatus
from mobilizon_reshare.models.publication import PublicationStatus
from mobilizon_reshare.storage.query.converter import event_to_model
from mobilizon_reshare.storage.query.read import (
get_published_events,
events_with_status,
Expand All @@ -15,8 +14,10 @@
build_publications,
get_event_publications,
get_all_events,
get_event,
)
from tests import today
from tests.commands.test_publish import one_unpublished_event_specification
from tests.storage import complete_specification
from tests.conftest import event_0, event_1, event_3
from tests.storage import result_publication
Expand Down Expand Up @@ -169,13 +170,10 @@ async def test_events_without_publications(spec, expected_events, generate_model


@pytest.mark.asyncio
async def test_get_all_events(event_generator):
all_events = [
event_generator(mobilizon_id=UUID(int=i), published=False) for i in range(4)
]
for e in all_events:
await event_to_model(e).save()
async def test_get_all_events(generate_models):
await generate_models(one_unpublished_event_specification)

all_events = [await get_event(event_0.mobilizon_id)]
assert list(await get_all_events()) == all_events


Expand Down

0 comments on commit a7e7b05

Please sign in to comment.