~homeworkprod/byceps

c53ea60f8200b818efbe7ed895a68ad38fbca9f1 — Jochen Kupperschmidt 8 months ago e185caf
Include optional site ID in user creation event, include in announcement
M byceps/announce/text_assembly/user.py => byceps/announce/text_assembly/user.py +16 -4
@@ 17,6 17,7 @@ from ...events.user import (
    UserEmailAddressInvalidated,
    UserScreenNameChanged,
)
from ...services.site import service as site_service

from ._helpers import get_screen_name_or_fallback



@@ 27,10 28,21 @@ def assemble_text_for_user_account_created(event: UserAccountCreated) -> str:
    )
    user_screen_name = get_screen_name_or_fallback(event.user_screen_name)

    return (
        f'{initiator_screen_name} '
        f'hat das Benutzerkonto "{user_screen_name}" angelegt.'
    )
    site = None
    if event.site_id:
        site = site_service.find_site(event.site_id)

    if site:
        return (
            f'{initiator_screen_name} '
            f'hat das Benutzerkonto "{user_screen_name}" '
            f'auf Site "{site.title}" angelegt.'
        )
    else:
        return (
            f'{initiator_screen_name} '
            f'hat das Benutzerkonto "{user_screen_name}" angelegt.'
        )


def assemble_text_for_user_screen_name_changed(

M byceps/events/user.py => byceps/events/user.py +2 -0
@@ 9,6 9,7 @@ byceps.events.user
from dataclasses import dataclass
from typing import Optional

from ..services.site.transfer.models import SiteID
from ..typing import UserID

from .base import _BaseEvent


@@ 22,6 23,7 @@ class _UserEvent(_BaseEvent):
@dataclass(frozen=True)
class UserAccountCreated(_UserEvent):
    user_screen_name: str
    site_id: Optional[SiteID]


@dataclass(frozen=True)

M byceps/services/user/creation_service.py => byceps/services/user/creation_service.py +1 -0
@@ 145,6 145,7 @@ def _create_user(
        initiator_screen_name=creator.screen_name if creator else None,
        user_id=user.id,
        user_screen_name=user.screen_name,
        site_id=site_id,
    )

    return user_dto, event

M tests/integration/announce/irc/test_user.py => tests/integration/announce/irc/test_user.py +25 -0
@@ 38,6 38,30 @@ def test_account_created_announced(app, make_user):
        initiator_screen_name=None,
        user_id=user.id,
        user_screen_name=user.screen_name,
        site_id=None,
    )

    with mocked_irc_bot() as mock:
        user_signals.account_created.send(None, event=event)

    assert_submitted_data(mock, EXPECTED_CHANNEL, expected_text)


def test_account_created_announced_on_site(app, make_user, site):
    expected_text = (
        'Jemand hat das Benutzerkonto "JaneDoeOnSite" '
        'auf Site "ACMECon 2014 website" angelegt.'
    )

    user = make_user('JaneDoeOnSite')

    event = UserAccountCreated(
        occurred_at=now(),
        initiator_id=None,
        initiator_screen_name=None,
        user_id=user.id,
        user_screen_name=user.screen_name,
        site_id=site.id,
    )

    with mocked_irc_bot() as mock:


@@ 58,6 82,7 @@ def test_account_created_by_admin_announced(app, make_user):
        initiator_screen_name=admin.screen_name,
        user_id=user.id,
        user_screen_name=user.screen_name,
        site_id=None,
    )

    with mocked_irc_bot() as mock: