Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from bundle
Telegram MTProto MCP server with userbot watcher, chat/DM parser and context builders
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
test_validation.py
1import pytest2import os34os.environ["TELEGRAM_API_ID"] = "12345"5os.environ["TELEGRAM_API_HASH"] = "dummy_hash"6from main import validate_id, ValidationError, log_and_format_error7from functools import wraps8import asyncio9from typing import Union, List, Optional101112# A simple async function to be decorated for testing13@validate_id("user_id", "chat_id", "user_ids")14async def dummy_function(**kwargs):15return "success", kwargs161718@pytest.mark.asyncio19async def test_valid_integer_id():20result, kwargs = await dummy_function(user_id=12345)21assert result == "success"22assert kwargs["user_id"] == 12345232425@pytest.mark.asyncio26async def test_valid_negative_integer_id():27result, kwargs = await dummy_function(chat_id=-100123456)28assert result == "success"29assert kwargs["chat_id"] == -100123456303132@pytest.mark.asyncio33async def test_valid_string_integer_id():34result, kwargs = await dummy_function(user_id="12345")35assert result == "success"36assert kwargs["user_id"] == 12345373839@pytest.mark.asyncio40async def test_valid_username():41result, kwargs = await dummy_function(user_id="@test_user")42assert result == "success"43assert kwargs["user_id"] == "@test_user"444546@pytest.mark.asyncio47async def test_valid_username_without_at():48result, kwargs = await dummy_function(user_id="test_user_long_enough")49assert result == "success"50assert kwargs["user_id"] == "test_user_long_enough"515253@pytest.mark.asyncio54async def test_valid_list_of_ids():55result, kwargs = await dummy_function(user_ids=[123, "456", "@test_user"])56assert result == "success"57assert kwargs["user_ids"] == [123, 456, "@test_user"]585960@pytest.mark.asyncio61async def test_invalid_float_id():62result = await dummy_function(user_id=123.45)63assert "Invalid user_id" in result64assert "Type must be an integer or a string" in result656667@pytest.mark.asyncio68async def test_invalid_string_id():69result = await dummy_function(user_id="inv") # too short70assert "Invalid user_id" in result71assert "Must be a valid integer ID, or a username string" in result727374@pytest.mark.asyncio75async def test_integer_out_of_range():76result = await dummy_function(user_id=2**64)77assert "Invalid user_id" in result78assert "out of the valid integer range" in result798081@pytest.mark.asyncio82async def test_invalid_item_in_list():83result = await dummy_function(user_ids=[123, "456", 123.45])84assert "Invalid user_ids" in result85assert "Type must be an integer or a string" in result868788@pytest.mark.asyncio89async def test_no_id_provided():90result, kwargs = await dummy_function()91assert result == "success"929394@pytest.mark.asyncio95async def test_none_id_provided():96result, kwargs = await dummy_function(user_id=None)97assert result == "success"98