"""Mock FediverseService for testing purposes""" from typing import List, Optional, Union, BinaryIO from fediverse_service import FediverseService from fediverse_types import FediverseNotification, FediversePost, FediverseFile, Visibility class MockFediverseService(FediverseService): """Mock implementation of FediverseService for testing""" def __init__(self): self.notifications = [] self.created_posts = [] self.uploaded_files = [] def get_notifications(self, since_id: Optional[str] = None) -> List[FediverseNotification]: """Return mock notifications, optionally filtered by since_id""" if since_id is None: return self.notifications # Filter notifications newer than since_id filtered = [] for notif in self.notifications: if notif.id > since_id: filtered.append(notif) return filtered def create_post( self, text: str, reply_to_id: Optional[str] = None, visibility: Visibility = Visibility.HOME, file_ids: Optional[List[str]] = None, visible_user_ids: Optional[List[str]] = None ) -> str: """Mock post creation, returns fake post ID""" post_id = f"mock_post_{len(self.created_posts)}" # Store the post for assertions self.created_posts.append({ 'id': post_id, 'text': text, 'reply_to_id': reply_to_id, 'visibility': visibility, 'file_ids': file_ids, 'visible_user_ids': visible_user_ids }) return post_id def upload_file(self, file_data: Union[BinaryIO, bytes]) -> FediverseFile: """Mock file upload, returns fake file""" file_id = f"mock_file_{len(self.uploaded_files)}" mock_file = FediverseFile( id=file_id, url=f"https://example.com/files/{file_id}", type="image/png", name="test_file.png" ) self.uploaded_files.append(mock_file) return mock_file # Helper methods for testing def add_mock_notification(self, notification: FediverseNotification): """Add a mock notification for testing""" self.notifications.append(notification) def clear_all(self): """Clear all mock data""" self.notifications.clear() self.created_posts.clear() self.uploaded_files.clear()