mirror of
https://github.com/catspace-dev/unicheckbot.git
synced 2024-11-21 13:36:37 +03:00
Тесты? Тесты. Мержи уже
This commit is contained in:
parent
766198ad81
commit
ff8143ccf4
|
@ -21,3 +21,6 @@ aiomysql = "^0.0.21"
|
|||
[build-system]
|
||||
requires = ["poetry-core>=1.0.0"]
|
||||
build-backend = "poetry.core.masonry.api"
|
||||
|
||||
[tool.poetry.scripts]
|
||||
test = 'tgbot.test:run_all'
|
||||
|
|
|
@ -6,7 +6,7 @@ from httpx import Response
|
|||
from aiogram.bot import Bot
|
||||
from datetime import datetime
|
||||
from core.coretypes import APINodeInfo
|
||||
from .helpers import send_api_requests, check_int
|
||||
from .helpers import send_api_requests
|
||||
from .errors import NotEnoughArgs, InvalidPort, LocalhostForbidden
|
||||
from .validators import BaseValidator, LocalhostValidator
|
||||
from tgbot.middlewares.throttling import rate_limit
|
||||
|
|
2
apps/tgbot/tgbot/test/__init__.py
Normal file
2
apps/tgbot/tgbot/test/__init__.py
Normal file
|
@ -0,0 +1,2 @@
|
|||
def run_all():
|
||||
from . import port_parsers
|
57
apps/tgbot/tgbot/test/port_parsers.py
Normal file
57
apps/tgbot/tgbot/test/port_parsers.py
Normal file
|
@ -0,0 +1,57 @@
|
|||
import asyncio
|
||||
|
||||
from ..handlers.default.tcp import TCPCheckerHandler
|
||||
from ..handlers.base import process_args_for_host_port,\
|
||||
NotEnoughArgs, InvalidPort
|
||||
|
||||
|
||||
try:
|
||||
args = "/cmd"
|
||||
process_args_for_host_port(args, 443)
|
||||
except NotEnoughArgs:
|
||||
pass
|
||||
args = "/cmd example.com"
|
||||
host, port = process_args_for_host_port(args, 443)
|
||||
assert port == 443
|
||||
|
||||
args = "/cmd example.com 42"
|
||||
host, port = process_args_for_host_port(args, 443)
|
||||
assert port == "42" # TODO: FIX THIS SHIT
|
||||
|
||||
args = "/cmd example.com:42"
|
||||
host, port = process_args_for_host_port(args, 443)
|
||||
assert port == "42"
|
||||
|
||||
try:
|
||||
args = "/cmd example.com fucktests"
|
||||
except InvalidPort:
|
||||
pass
|
||||
|
||||
method = TCPCheckerHandler().process_args
|
||||
|
||||
|
||||
async def test():
|
||||
try:
|
||||
args = "/cmd"
|
||||
await method(args)
|
||||
args = "/cmd example.com"
|
||||
await method(args)
|
||||
except NotEnoughArgs:
|
||||
pass
|
||||
|
||||
args = "/cmd example.com 42"
|
||||
host, port = await method(args)
|
||||
assert port == "42"
|
||||
|
||||
args = "/cmd example.com:42"
|
||||
host, port = await method(args)
|
||||
assert port == "42"
|
||||
|
||||
try:
|
||||
args = "/cmd example.com jdbnjsbndjsd"
|
||||
await method(args)
|
||||
except InvalidPort:
|
||||
pass
|
||||
|
||||
|
||||
asyncio.run(test())
|
Loading…
Reference in New Issue
Block a user