Skip to content

Commit

Permalink
Start covering Telegram agent frontend with tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Saluev committed Dec 20, 2023
1 parent 3d6ee57 commit 276b574
Show file tree
Hide file tree
Showing 7 changed files with 376 additions and 52 deletions.
1 change: 1 addition & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ jobs:
run: |
docker pull postgres:latest
- name: Run tests
# TODO properly wait until postgres is ready https://stackoverflow.com/a/55835081/999858
run: |
docker run -p 5432:5432 -e POSTGRES_USER=suppgram -e POSTGRES_PASSWORD=test -e POSTGRES_DB=suppgram_test -d postgres:latest
docker run -p 27017:27017 -d mongo:latest
Expand Down
9 changes: 6 additions & 3 deletions suppgram/frontends/telegram/agent_frontend.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@ async def _handle_start_command(self, update: Update, context: ContextTypes.DEFA
)
if not should_create:
await context.bot.send_message(
update.effective_chat.id,
self._texts.telegram_manager_permission_denied_message,
chat_id=update.effective_chat.id,
text=self._texts.telegram_manager_permission_denied_message,
)
return
agent_identification = workplace_identification.to_agent_identification()
Expand All @@ -166,7 +166,9 @@ async def _send_start_message_and_conversation_messages(
workplace_identification: WorkplaceIdentification,
context: ContextTypes.DEFAULT_TYPE,
):
await context.bot.send_message(effective_chat.id, self._texts.telegram_agent_start_message)
await context.bot.send_message(
chat_id=effective_chat.id, text=self._texts.telegram_agent_start_message
)

try:
conversation = await self._backend.identify_agent_conversation(workplace_identification)
Expand Down Expand Up @@ -408,6 +410,7 @@ async def _nudge_to_start_bot_in_chat(self, workplace: Workplace, chat: Telegram
chat,
message.message_id,
TelegramMessageKind.NUDGE_TO_START_BOT_NOTIFICATION,
agent_id=workplace.agent.id,
telegram_bot_username=bot_username,
)

Expand Down
2 changes: 1 addition & 1 deletion suppgram/frontends/telegram/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ async def create_or_update_chat(self, telegram_chat_id: int) -> TelegramChat:
"""Create or update Telegram chat by Telegram chat ID."""

@abc.abstractmethod
async def add_chat_roles(self, telegram_chat_id: int, *roles: TelegramChatRole):
async def add_chat_roles(self, telegram_chat_id: int, *roles: TelegramChatRole) -> object:
"""Assign roles to a Telegram chat."""

@abc.abstractmethod
Expand Down
4 changes: 2 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def sqlite_sqlalchemy_storage(sqlite_engine: AsyncEngine) -> Generator[Storage,

async def _clean_postgresql_storage():
engine = create_async_engine(
f"postgresql+asyncpg://suppgram:test@localhost:5432/suppgram_test", echo=True
"postgresql+asyncpg://suppgram:test@localhost:5432/suppgram_test", echo=True
)
for truncate_query in [
text(
Expand Down Expand Up @@ -86,7 +86,7 @@ def clean_postgresql_storage():
@pytest.fixture
def postgresql_engine() -> AsyncEngine:
return create_async_engine(
f"postgresql+asyncpg://suppgram:test@localhost:5432/suppgram_test", echo=True
"postgresql+asyncpg://suppgram:test@localhost:5432/suppgram_test", echo=True
)


Expand Down
Loading

0 comments on commit 276b574

Please sign in to comment.