feat: parser, refactoring
This commit is contained in:
@@ -317,6 +317,28 @@ class MockDatabase:
|
||||
return subscription
|
||||
return None
|
||||
|
||||
async def get_active_subscriptions_by_subscriber_and_channel(
|
||||
self, subscriber_id: uuid.UUID, channel_telegram_id: int
|
||||
) -> list[domain.Subscription]:
|
||||
result = []
|
||||
for subscription in self.subscriptions.values():
|
||||
if subscription.subscriber_id == subscriber_id and subscription.unsubscribed_at is None:
|
||||
placement = self.placements.get(subscription.placement_id)
|
||||
if placement:
|
||||
target_channel = self.target_channels.get(placement.target_channel_id)
|
||||
if target_channel and target_channel.telegram_id == channel_telegram_id:
|
||||
subscription.placement = placement
|
||||
result.append(subscription)
|
||||
return result
|
||||
|
||||
async def get_active_subscription_by_subscriber_and_channel(
|
||||
self, subscriber_id: uuid.UUID, channel_telegram_id: int
|
||||
) -> domain.Subscription | None:
|
||||
subscriptions = await self.get_active_subscriptions_by_subscriber_and_channel(
|
||||
subscriber_id, channel_telegram_id
|
||||
)
|
||||
return subscriptions[0] if subscriptions else None
|
||||
|
||||
async def create_placement_views_history(
|
||||
self, history: domain.PlacementViewsHistory
|
||||
) -> domain.PlacementViewsHistory:
|
||||
@@ -360,6 +382,12 @@ class MockTelegramWriter:
|
||||
{'text': text, 'chat_id': chat_id, 'button': {'text': button_text, 'url': button_url}}
|
||||
)
|
||||
|
||||
async def send_message_with_inline_keyboard(self, text: str, chat_id: int, buttons: list[list[Any]]) -> None:
|
||||
self.sent_messages.append({'text': text, 'chat_id': chat_id, 'inline_keyboard': buttons})
|
||||
|
||||
async def edit_message_reply_markup(self, chat_id: int, message_id: int) -> None:
|
||||
pass
|
||||
|
||||
async def get_chat_member(self, chat_id: int, user_id: int) -> dict[str, Any]:
|
||||
return {}
|
||||
|
||||
@@ -368,10 +396,6 @@ class MockTelegramWriter:
|
||||
link_type = 'approval' if requires_approval else 'public'
|
||||
return f'https://t.me/+{link_type}_link_{self.invite_link_counter}_{chat_id}'
|
||||
|
||||
async def get_post_views(self, post_url: str) -> int | None:
|
||||
"""Mock implementation returns None (TDLib not integrated)."""
|
||||
return None
|
||||
|
||||
|
||||
class MockJWTEncoder:
|
||||
def encode_access_token(self, user_id: uuid.UUID, telegram_id: int, username: str | None = None) -> str:
|
||||
@@ -395,6 +419,12 @@ def mock_jwt() -> MockJWTEncoder:
|
||||
|
||||
@pytest.fixture
|
||||
def usecases(
|
||||
mock_database: MockDatabase, mock_telegram: MockTelegramWriter, mock_jwt: MockJWTEncoder
|
||||
mock_database: MockDatabase,
|
||||
mock_telegram: MockTelegramWriter,
|
||||
mock_jwt: MockJWTEncoder,
|
||||
) -> usecase.Usecase:
|
||||
return usecase.Usecase(database=mock_database, telegram_bot=mock_telegram, jwt_encoder=mock_jwt)
|
||||
return usecase.Usecase(
|
||||
database=mock_database, # type: ignore[arg-type]
|
||||
telegram_bot=mock_telegram,
|
||||
jwt_encoder=mock_jwt,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user