~homeworkprod/byceps-whereabouts

df543977b4dd819ef0b9bcb6e6a12f8f494290df — Jochen Kupperschmidt 5 months ago be2030f
Adjust to introduction of `byceps.events.base.{EventParty,EventUser}`
M byceps/announce/handlers/whereabouts.py => byceps/announce/handlers/whereabouts.py +1 -1
@@ 27,7 27,7 @@ def announce_whereabouts_status_updated(
    webhook: OutgoingWebhook,
) -> Announcement | None:
    """Announce that a user's whereabouts has been updated."""
    user_screen_name = get_screen_name_or_fallback(event.user_screen_name)
    user_screen_name = get_screen_name_or_fallback(event.user)

    text = gettext(
        '%(user_screen_name)s\'s whereabouts changed to "%(whereabouts_description)s".',

M byceps/events/whereabouts.py => byceps/events/whereabouts.py +3 -8
@@ 10,16 10,11 @@ from __future__ import annotations

from dataclasses import dataclass

from byceps.services.party.models import PartyID
from byceps.services.user.models.user import UserID

from .base import _BaseEvent
from .base import _BaseEvent, EventParty, EventUser


@dataclass(frozen=True)
class WhereaboutsStatusUpdatedEvent(_BaseEvent):
    party_id: PartyID
    party_title: str
    user_id: UserID
    user_screen_name: str | None
    party: EventParty
    user: EventUser
    whereabouts_description: str

M byceps/services/whereabouts/whereabouts_domain_service.py => byceps/services/whereabouts/whereabouts_domain_service.py +4 -6
@@ 10,6 10,7 @@ from __future__ import annotations

from datetime import datetime

from byceps.events.base import EventParty, EventUser
from byceps.events.whereabouts import WhereaboutsStatusUpdatedEvent
from byceps.services.party.models import Party
from byceps.services.user.models.user import User


@@ 73,12 74,9 @@ def set_status(

    event = WhereaboutsStatusUpdatedEvent(
        occurred_at=set_at,
        initiator_id=user.id,
        initiator_screen_name=user.screen_name,
        party_id=whereabouts.party.id,
        party_title=whereabouts.party.title,
        user_id=user.id,
        user_screen_name=user.screen_name,
        initiator=EventUser.from_user(user),
        party=EventParty.from_party(whereabouts.party),
        user=EventUser.from_user(user),
        whereabouts_description=whereabouts.description,
    )


M tests/unit/announce/irc/test_whereabouts.py => tests/unit/announce/irc/test_whereabouts.py +17 -17
@@ 3,33 3,33 @@
:License: Revised BSD (see `LICENSE` file for details)
"""

from datetime import datetime

from flask import Flask

from byceps.announce.announce import build_announcement_request
from byceps.events.base import EventParty
from byceps.events.whereabouts import WhereaboutsStatusUpdatedEvent
from byceps.services.party.models import PartyID
from byceps.services.user.models.user import UserID

from tests.helpers import generate_uuid

from .helpers import assert_text, now

from .helpers import assert_text

OCCURRED_AT = now()
USER_ID = UserID(generate_uuid())


def test_whereabouts_status_updated(app: Flask, webhook_for_irc):
def test_whereabouts_status_updated(
    app: Flask,
    now: datetime,
    party: EventParty,
    make_event_user,
    webhook_for_irc,
):
    expected_text = 'Dingo\'s whereabouts changed to "backstage area".'

    user = make_event_user(screen_name='Dingo')

    event = WhereaboutsStatusUpdatedEvent(
        occurred_at=OCCURRED_AT,
        initiator_id=USER_ID,
        initiator_screen_name='Dingo',
        party_id=PartyID('acmecon-2014'),
        party_title='ACMECon 2014',
        user_id=USER_ID,
        user_screen_name='Dingo',
        occurred_at=now,
        initiator=user,
        party=party,
        user=user,
        whereabouts_description='backstage area',
    )