Skip to content

Commit

Permalink
chore: cleanup comments and remove warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
jackstar12 committed Feb 10, 2025
1 parent 3e08dec commit 1cf7ee5
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 39 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,15 @@ jobs:
- name: Run ruff checks
run: uv run ruff check .

- name: Setup postgres
- name: Setup PostgreSQL
run: make postgres

- name: Run tests
run: uv run pytest .
env:
DATABASE_URL: "postgresql+asyncpg://boltz:boltz@localhost:5433/fees"
TELEGRAM_BOT_TOKEN: ${{ secrets.TELEGRAM_BOT_TOKEN }}
TEST_BOT_NAME: ${{ secrets.TEST_BOT_NAME }}
TEST_API_ID: ${{ secrets.TEST_API_ID }}
TEST_API_HASH: ${{ secrets.TEST_API_HASH }}
TEST_API_SESSION: ${{ secrets.TEST_API_SESSION }}
2 changes: 1 addition & 1 deletion db.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from sqlalchemy import select
from sqlalchemy.exc import IntegrityError
from sqlalchemy.ext.asyncio import AsyncSession
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import declarative_base
from telegram.ext import ContextTypes

from consts import Fees
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,4 @@ dev = [
pythonpath = [
"."
]
asyncio_default_fixture_loop_scope = "session"
20 changes: 7 additions & 13 deletions settings.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,19 @@
from pydantic import Field
from pydantic import Field, ConfigDict
from pydantic_settings import BaseSettings


class Settings(BaseSettings):
telegram_bot_token: str = Field(
..., env="TELEGRAM_BOT_TOKEN", description="Telegram bot token"
)
check_interval: int = Field(
60, env="CHECK_INTERVAL", description="Interval to check API (seconds)"
)
telegram_bot_token: str = Field(..., description="Telegram bot token")
check_interval: int = Field(60, description="Interval to check API (seconds)")
api_url: str = Field(
"https://api.boltz.exchange",
env="API_URL",
description="Boltz API URL for submarine swaps",
)
database_url: str = Field(
env="DATABASE_URL",
description="Database URL for PostgreSQL",
)

class Config:
env_file = ".env"
env_file_encoding = "utf-8"
extra = "allow"
model_config = ConfigDict(
env_file=".env",
extra="allow",
)
22 changes: 12 additions & 10 deletions tests/e2e/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import subprocess
from typing import Optional

import pytest
import pytest_asyncio
from telethon.tl.custom import Conversation

Expand Down Expand Up @@ -30,21 +31,22 @@ class TestSettings(Settings):
test_api_id: int
test_api_hash: str
test_api_session: Optional[str]
test_bot_name: str

class Config:
env_file = ".env"
extra = "allow"

@pytest.fixture(scope="session")
def test_settings():
return TestSettings()


@pytest_asyncio.fixture(scope="session")
async def telegram_client():
async def telegram_client(test_settings):
"""Connect to Telegram user for testing."""
settings = TestSettings()

client = TelegramClient(
StringSession(settings.test_api_session),
settings.test_api_id,
settings.test_api_hash,
StringSession(test_settings.test_api_session),
test_settings.test_api_id,
test_settings.test_api_hash,
sequential_updates=True,
)
await client.connect()
Expand All @@ -57,9 +59,9 @@ async def telegram_client():


@pytest_asyncio.fixture(scope="session")
async def conv(telegram_client: TelegramClient) -> Conversation:
async def conv(telegram_client: TelegramClient, test_settings) -> Conversation:
"""Open conversation with the bot."""
async with telegram_client.conversation(
"@boltz_fees_bot", timeout=3, max_messages=10000
f"@{test_settings.test_bot_name}", timeout=3, max_messages=10000
) as conv:
yield conv
2 changes: 0 additions & 2 deletions tests/e2e/get_session_string.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# tests/e2e/get_session_string.py

from telethon import TelegramClient
from telethon.sessions import StringSession

Expand Down
8 changes: 8 additions & 0 deletions tests/e2e/test_commands.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
import pytest
from pydantic import ValidationError
from telethon.tl.custom import Conversation

from tests.e2e.conftest import TestSettings
from tests.helpers import get_button_with_text, wait


try:
TestSettings()
except ValidationError as e:
pytest.skip(reason=f"Test settings not set {e}", allow_module_level=True)


async def remove_subscriptions(conv: Conversation):
await conv.send_message("/unsubscribe")
await conv.get_response()
Expand Down
12 changes: 0 additions & 12 deletions tests/helpers.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,9 @@
# tests/helpers.py
import asyncio
import random
import string
from typing import Optional

from telethon.tl.custom.message import Message, MessageButton


# Used to generate random unique names for lists and items.
# This way you do not need to think about clashing names
# when you do not clear DB after each test.
def random_string(length=16):
"""Return random string of ASCII letters in both registers."""
return "".join(random.choice(string.ascii_letters) for _ in range(length))


async def wait():
await asyncio.sleep(0.75)

Expand All @@ -24,7 +13,6 @@ async def wait():
def get_button_with_text(
message: Message, text: str, strict: bool = False
) -> Optional[MessageButton]:
"""Return MessageButton from Message with text or None."""
if message.buttons is None:
return None

Expand Down

0 comments on commit 1cf7ee5

Please sign in to comment.