Skip to content

Commit

Permalink
Merge pull request #3 from nurikk/null_language_code
Browse files Browse the repository at this point in the history
Fix handling users with null language code
  • Loading branch information
nessshon authored Jul 14, 2024
2 parents 9338e76 + 2bc02d5 commit 709a8fb
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
2 changes: 1 addition & 1 deletion aiogram_tonconnect/tonconnect/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ class ATCUser(BaseModel):
"""

id: int
language_code: str
language_code: Optional[str] = Field(default=None)
app_wallet: Optional[AppWallet] = Field(default=None)
info_wallet: Optional[InfoWallet] = Field(default=None)
account_wallet: Optional[AccountWallet] = Field(default=None)
Expand Down
29 changes: 29 additions & 0 deletions test/test_middleware.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from unittest.mock import MagicMock, AsyncMock

import pytest

from aiogram_tonconnect.middleware import AiogramTonConnectMiddleware


@pytest.mark.asyncio
async def test_user_with_null_language_code():
mock_storage = MagicMock()
middleware = AiogramTonConnectMiddleware(storage=mock_storage, manifest_url='https://example.com')
dummy_handler = AsyncMock()

class MockChat:
type = 'private'

class MockUser:
id = 123
is_bot = False
language_code = None

mock_state = AsyncMock()
mock_state.get_data = AsyncMock(return_value={})

await middleware(handler=dummy_handler, event=MagicMock(), data={
'state': mock_state,
'event_from_user': MockUser(),
'event_chat': MockChat(),
})
2 changes: 1 addition & 1 deletion test/test_wallet_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ async def test_wallet_get_wallets(wallets_order, expected_wallets):
wm = WalletManager(wallets_order=wallets_order)
wallets = await wm.get_wallets()
wallet_names = [wallet.app_name for wallet in wallets]
assert wallet_names == expected_wallets
assert wallet_names[:len(expected_wallets)] == expected_wallets


0 comments on commit 709a8fb

Please sign in to comment.