refactor(parsers): перенести тесты в ROOT_DIR/tests и синхронизировать контракты задач
- перенесены тесты parsers из src/apps/parsers/tests в tests/apps/parsers - обновлены тесты задач под текущее поведение Celery (ошибки пробрасываются исключениями) - убрана зависимость тестов от внешнего брокера через локальные eager-вызовы - добавлены/уточнены фабрики и импорты для единой структуры тестов - обновлены README и CHANGELOG с новым правилом размещения тестов и запуском
This commit is contained in:
119
tests/apps/parsers/run_checko_e2e.py
Normal file
119
tests/apps/parsers/run_checko_e2e.py
Normal file
@@ -0,0 +1,119 @@
|
||||
#!/usr/bin/env python
|
||||
"""
|
||||
Standalone E2E test for Checko API client.
|
||||
|
||||
Usage:
|
||||
PYTHONPATH=src python tests/apps/parsers/run_checko_e2e.py
|
||||
"""
|
||||
|
||||
import os
|
||||
import sys
|
||||
|
||||
import django
|
||||
from apps.parsers.clients.checko import (
|
||||
CheckoClient,
|
||||
CompanyRequest,
|
||||
ContractLaw,
|
||||
ContractsRequest,
|
||||
FinancesRequest,
|
||||
LegalCasesRequest,
|
||||
ObjectType,
|
||||
SearchRequest,
|
||||
SearchType,
|
||||
)
|
||||
from django.conf import settings
|
||||
|
||||
sys.path.insert(0, ".")
|
||||
|
||||
# Setup Django settings
|
||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings.dev")
|
||||
|
||||
django.setup()
|
||||
|
||||
|
||||
API_KEY = os.environ.get("CHECKO_API_KEY") or settings.CHECKO_API_KEY
|
||||
if not API_KEY:
|
||||
print("ERROR: CHECKO_API_KEY not configured")
|
||||
print("Set it in .env or as environment variable")
|
||||
sys.exit(1)
|
||||
|
||||
TEST_INN = "7727060950" # АО "ЭКОС"
|
||||
|
||||
|
||||
def main():
|
||||
client = CheckoClient(api_key=API_KEY)
|
||||
|
||||
print("=" * 60)
|
||||
print("E2E TEST: Get Company by INN")
|
||||
print("=" * 60)
|
||||
response = client.get_company(CompanyRequest(inn=TEST_INN))
|
||||
print(f"Status: {response.meta.status}")
|
||||
print(f"Balance: {response.meta.balance}")
|
||||
print(f"Requests today: {response.meta.today_request_count}")
|
||||
print(f"Company: {response.data.short_name}")
|
||||
print(f"Full name: {response.data.full_name}")
|
||||
print(f"INN: {response.data.inn}")
|
||||
print(f"OGRN: {response.data.ogrn}")
|
||||
print(f"Status: {response.data.status.name if response.data.status else None}")
|
||||
print(
|
||||
f"Address: {response.data.legal_address.full_address if response.data.legal_address else None}"
|
||||
)
|
||||
|
||||
print()
|
||||
print("=" * 60)
|
||||
print("E2E TEST: Search by name")
|
||||
print("=" * 60)
|
||||
response = client.search(
|
||||
SearchRequest(
|
||||
by=SearchType.NAME, obj=ObjectType.ORGANIZATION, query="Ростелеком", limit=5
|
||||
)
|
||||
)
|
||||
print(f"Found: {len(response.data.organizations)} organizations")
|
||||
for org in response.data.organizations[:3]:
|
||||
print(f" - {org.inn}: {org.short_name}")
|
||||
|
||||
print()
|
||||
print("=" * 60)
|
||||
print("E2E TEST: Get Finances")
|
||||
print("=" * 60)
|
||||
response = client.get_finances(FinancesRequest(inn=TEST_INN))
|
||||
print(f"Reports count: {len(response.data.reports)}")
|
||||
if response.data.reports:
|
||||
for r in response.data.reports[:2]:
|
||||
print(f" - Year {r.year}: {len(r.balance)} balance lines")
|
||||
|
||||
print()
|
||||
print("=" * 60)
|
||||
print("E2E TEST: Get Contracts (44-ФЗ)")
|
||||
print("=" * 60)
|
||||
response = client.get_contracts(
|
||||
ContractsRequest(inn=TEST_INN, law=ContractLaw.FZ44, limit=5)
|
||||
)
|
||||
print(f"Contracts: {len(response.data.contracts)}")
|
||||
if response.data.pagination:
|
||||
print(f"Total: {response.data.pagination.total_records}")
|
||||
if response.data.contracts:
|
||||
c = response.data.contracts[0]
|
||||
print(f"First: {c.registry_number}, price={c.price}")
|
||||
|
||||
print()
|
||||
print("=" * 60)
|
||||
print("E2E TEST: Get Legal Cases")
|
||||
print("=" * 60)
|
||||
response = client.get_legal_cases(LegalCasesRequest(inn=TEST_INN, limit=5))
|
||||
print(f"Cases: {len(response.data.cases)}")
|
||||
if response.data.pagination:
|
||||
print(f"Total: {response.data.pagination.total_records}")
|
||||
if response.data.cases:
|
||||
c = response.data.cases[0]
|
||||
print(f"First: {c.case_number}, claim={c.claim_amount}")
|
||||
|
||||
client.close()
|
||||
print()
|
||||
print("=" * 60)
|
||||
print("ALL E2E TESTS PASSED!")
|
||||
print("=" * 60)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user