feat: обновления парсеров, тестов и миграций
Some checks failed
CI/CD Pipeline / Run Tests (push) Failing after 37s
CI/CD Pipeline / Code Quality Checks (push) Failing after 43s
CI/CD Pipeline / Build & Push Images (push) Has been skipped
CI/CD Pipeline / Deploy (dev) (push) Has been skipped
CI/CD Pipeline / Deploy (prod) (push) Has been skipped
CI/CD Pipeline / Code Quality Checks (pull_request) Failing after 0s
CI/CD Pipeline / Run Tests (pull_request) Failing after 0s
CI/CD Pipeline / Build & Push Images (pull_request) Has been skipped
CI/CD Pipeline / Deploy (dev) (pull_request) Has been skipped
CI/CD Pipeline / Deploy (prod) (pull_request) Has been skipped
Some checks failed
CI/CD Pipeline / Run Tests (push) Failing after 37s
CI/CD Pipeline / Code Quality Checks (push) Failing after 43s
CI/CD Pipeline / Build & Push Images (push) Has been skipped
CI/CD Pipeline / Deploy (dev) (push) Has been skipped
CI/CD Pipeline / Deploy (prod) (push) Has been skipped
CI/CD Pipeline / Code Quality Checks (pull_request) Failing after 0s
CI/CD Pipeline / Run Tests (pull_request) Failing after 0s
CI/CD Pipeline / Build & Push Images (pull_request) Has been skipped
CI/CD Pipeline / Deploy (dev) (pull_request) Has been skipped
CI/CD Pipeline / Deploy (prod) (pull_request) Has been skipped
- Обновлены клиенты парсеров (checko, fns, minpromtorg, proverki, zakupki) - Добавлены новые миграции для моделей - Расширено покрытие тестами - Обновлены конфигурации и настройки проекта - Добавлены утилиты для тестирования Co-Authored-By: Warp <agent@warp.dev>
This commit is contained in:
343
tests/apps/parsers/test_checko_parsers.py
Normal file
343
tests/apps/parsers/test_checko_parsers.py
Normal file
@@ -0,0 +1,343 @@
|
||||
"""Extra parsing tests for Checko client (no mocks)."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from django.test import SimpleTestCase
|
||||
|
||||
from apps.parsers.clients.checko.client import CheckoClient, _map_ru_keys
|
||||
from tests.utils.fixtures import fake
|
||||
|
||||
|
||||
def _digits(count: int) -> str:
|
||||
return "".join(str(fake.random_int(0, 9)) for _ in range(count))
|
||||
|
||||
|
||||
class CheckoClientParsingTest(SimpleTestCase):
|
||||
def setUp(self):
|
||||
self.client = CheckoClient(api_key="test_key")
|
||||
|
||||
def test_map_ru_keys_handles_nested(self):
|
||||
data = {
|
||||
"\u0418\u041d\u041d": _digits(10),
|
||||
"\u042e\u0440\u0410\u0434\u0440\u0435\u0441": {
|
||||
"\u0410\u0434\u0440\u0435\u0441\u0420\u0424": fake.address(),
|
||||
},
|
||||
"\u0417\u0430\u043f\u0438\u0441\u0438": [
|
||||
{"\u041e\u0413\u0420\u041d": _digits(13)},
|
||||
"raw",
|
||||
],
|
||||
}
|
||||
mapped = _map_ru_keys(data)
|
||||
|
||||
self.assertEqual(mapped["inn"], data["\u0418\u041d\u041d"])
|
||||
self.assertIn("legal_address", mapped)
|
||||
self.assertIn("records", mapped)
|
||||
self.assertEqual(mapped["records"][0]["ogrn"], data["\u0417\u0430\u043f\u0438\u0441\u0438"][0]["\u041e\u0413\u0420\u041d"])
|
||||
|
||||
def test_parse_okved_info_with_additional(self):
|
||||
info = self.client._parse_okved_info(
|
||||
{"code": "62.01", "name": "Development", "version": "2001"},
|
||||
[{"code": "62.02", "name": "Consulting"}, None],
|
||||
)
|
||||
self.assertEqual(info.main.code, "62.01")
|
||||
self.assertEqual(len(info.additional), 1)
|
||||
|
||||
def test_parse_leader_and_founders_variants(self):
|
||||
leader = self.client._parse_leader(
|
||||
[
|
||||
{
|
||||
"full_name": fake.name(),
|
||||
"inn": _digits(12),
|
||||
"position_name": fake.job(),
|
||||
}
|
||||
]
|
||||
)
|
||||
self.assertIsNotNone(leader)
|
||||
|
||||
founders_list = self.client._parse_founders(
|
||||
[
|
||||
{"full_name": fake.name(), "inn": _digits(12)},
|
||||
{"name": fake.company(), "ogrn": _digits(13)},
|
||||
]
|
||||
)
|
||||
self.assertEqual(len(founders_list), 2)
|
||||
|
||||
founders_dict = self.client._parse_founders(
|
||||
{
|
||||
"\u0444\u043b": [{"full_name": fake.name(), "inn": _digits(12)}],
|
||||
"\u0440\u043e\u0441\u043e\u0440\u0433": [{"name": fake.company()}],
|
||||
}
|
||||
)
|
||||
self.assertEqual(len(founders_dict), 2)
|
||||
|
||||
def test_parse_branches_variants(self):
|
||||
branches_list = self.client._parse_branches(
|
||||
[
|
||||
{"full_name": fake.company(), "address": fake.address()},
|
||||
{"name": fake.company(), "country": "RU"},
|
||||
]
|
||||
)
|
||||
self.assertEqual(len(branches_list), 2)
|
||||
|
||||
branches_dict = self.client._parse_branches(
|
||||
{
|
||||
"branch": [{"full_name": fake.company(), "address": fake.address()}],
|
||||
"representative_office": [{"name": fake.company()}],
|
||||
}
|
||||
)
|
||||
self.assertEqual(len(branches_dict), 2)
|
||||
|
||||
def test_parse_company_data_full(self):
|
||||
data = {
|
||||
"ogrn": _digits(13),
|
||||
"inn": _digits(10),
|
||||
"kpp": _digits(9),
|
||||
"okpo": _digits(8),
|
||||
"reg_date": str(fake.date()),
|
||||
"short_name": fake.company(),
|
||||
"full_name": fake.company(),
|
||||
"status": {"code": "100", "name": "Active", "record_date": str(fake.date())},
|
||||
"legal_address": {
|
||||
"full_address": fake.address(),
|
||||
"region": {"code": "77", "name": "Moscow"},
|
||||
"city": fake.city(),
|
||||
"street": fake.street_name(),
|
||||
"building": fake.building_number(),
|
||||
"apartment": fake.street_address(),
|
||||
"postal_code": fake.postcode(),
|
||||
"is_unreliable": True,
|
||||
"is_mass_address": False,
|
||||
},
|
||||
"leader": [
|
||||
{
|
||||
"full_name": fake.name(),
|
||||
"inn": _digits(12),
|
||||
"position_name": fake.job(),
|
||||
}
|
||||
],
|
||||
"founders": {"\u0444\u043b": [{"full_name": fake.name()}]},
|
||||
"capital": {"value": 1000, "type_name": "RUB", "date": str(fake.date())},
|
||||
"okved": {"code": "62.01", "name": "Development", "version": "2001"},
|
||||
"okved_additional": [{"code": "62.02", "name": "Consulting"}],
|
||||
"opf": {"code": "123", "name": "LLC"},
|
||||
"okfs": {"code": "16", "name": "Private"},
|
||||
"okogu": {"code": "4210014", "name": "Federal"},
|
||||
"region": {"code": "77", "name": "Moscow"},
|
||||
"tax_authority": {
|
||||
"code": "7700",
|
||||
"name": "IFNS",
|
||||
"address": fake.address(),
|
||||
"date": str(fake.date()),
|
||||
},
|
||||
"tax_authority_local": {
|
||||
"code": "7701",
|
||||
"name": "IFNS Local",
|
||||
"address": fake.address(),
|
||||
"date": str(fake.date()),
|
||||
},
|
||||
"pfr": {
|
||||
"reg_date": str(fake.date()),
|
||||
"reg_number": _digits(10),
|
||||
"code": "087",
|
||||
"name": "PFR",
|
||||
},
|
||||
"fss": {
|
||||
"reg_date": str(fake.date()),
|
||||
"reg_number": _digits(10),
|
||||
"code": "773",
|
||||
"name": "FSS",
|
||||
},
|
||||
"registrar": {
|
||||
"ogrn": _digits(13),
|
||||
"inn": _digits(10),
|
||||
"full_name": fake.company(),
|
||||
},
|
||||
"predecessors": [
|
||||
{
|
||||
"ogrn": _digits(13),
|
||||
"inn": _digits(10),
|
||||
"kpp": _digits(9),
|
||||
"full_name": fake.company(),
|
||||
}
|
||||
],
|
||||
"successors": [
|
||||
{
|
||||
"ogrn": _digits(13),
|
||||
"inn": _digits(10),
|
||||
"kpp": _digits(9),
|
||||
"full_name": fake.company(),
|
||||
}
|
||||
],
|
||||
"branches": {"branch": [{"full_name": fake.company(), "address": fake.address()}]},
|
||||
"licenses": [{"number": "L-1", "activities": [fake.word()]}],
|
||||
"trademarks": [{"id": 1, "url": fake.url()}],
|
||||
"tax_debt": {"total": 123, "date": str(fake.date())},
|
||||
"tax_penalty": {"penalties": 10, "fines": 5, "date": str(fake.date())},
|
||||
"msp": {"category": "micro", "include_date": str(fake.date()), "type": "A"},
|
||||
"msp_support": [
|
||||
{
|
||||
"date": str(fake.date()),
|
||||
"type": "grant",
|
||||
"form": "cash",
|
||||
"org_name": fake.company(),
|
||||
"org_inn": _digits(10),
|
||||
"amount": 42,
|
||||
"violation": True,
|
||||
}
|
||||
],
|
||||
"bankruptcy": [{"type": "msg", "date": str(fake.date())}],
|
||||
"unfair_supplier": [{"registry_number": "123", "purchase_number": "1"}],
|
||||
"related_companies": [{"ogrn": _digits(13), "inn": _digits(10)}],
|
||||
"statistics": {
|
||||
"contracts_44_customer_count": 1,
|
||||
"contracts_44_supplier_count": 2,
|
||||
"contracts_223_customer_count": 3,
|
||||
"contracts_223_supplier_count": 4,
|
||||
"legal_cases_plaintiff_count": 5,
|
||||
"legal_cases_defendant_count": 6,
|
||||
"inspections_count": 7,
|
||||
"enforcements_count": 8,
|
||||
},
|
||||
"employees_count": 10,
|
||||
"employees_count_date": str(fake.date()),
|
||||
"liquidation_date": str(fake.date()),
|
||||
}
|
||||
|
||||
parsed = self.client._parse_company_data(data)
|
||||
self.assertEqual(parsed.ogrn, data["ogrn"])
|
||||
self.assertEqual(parsed.status.code, "100")
|
||||
self.assertEqual(len(parsed.founders), 1)
|
||||
self.assertEqual(len(parsed.branches), 1)
|
||||
self.assertEqual(parsed.tax_authority.code, "7700")
|
||||
|
||||
def test_parse_other_data_blocks(self):
|
||||
entrepreneur = self.client._parse_entrepreneur_data(
|
||||
{
|
||||
"ogrnip": _digits(15),
|
||||
"inn": _digits(12),
|
||||
"full_name": fake.name(),
|
||||
"status": {"code": "100", "name": "Active"},
|
||||
"region": {"code": "78", "name": "SPB"},
|
||||
"tax_authority": {"code": "7800", "name": "IFNS"},
|
||||
"okved": {"code": "47.19", "name": "Retail"},
|
||||
"licenses": [{"number": "L-2"}],
|
||||
}
|
||||
)
|
||||
self.assertIsNotNone(entrepreneur)
|
||||
self.assertEqual(entrepreneur.status.code, "100")
|
||||
|
||||
person = self.client._parse_person_data(
|
||||
{
|
||||
"inn": _digits(12),
|
||||
"full_name": fake.name(),
|
||||
"disqualifications": [
|
||||
{"date_from": str(fake.date()), "reason": fake.sentence(nb_words=4)}
|
||||
],
|
||||
"companies_as_leader": [
|
||||
{"ogrn": _digits(13), "short_name": fake.company()}
|
||||
],
|
||||
"companies_as_founder": [
|
||||
{"ogrn": _digits(13), "short_name": fake.company()}
|
||||
],
|
||||
"entrepreneurs": [
|
||||
{"ogrnip": _digits(15), "full_name": fake.name()}
|
||||
],
|
||||
}
|
||||
)
|
||||
self.assertEqual(len(person.disqualifications), 1)
|
||||
self.assertEqual(len(person.companies_as_leader), 1)
|
||||
|
||||
finances = self.client._parse_finances_data(
|
||||
{
|
||||
"ogrn": _digits(13),
|
||||
"inn": _digits(10),
|
||||
"reports": [
|
||||
{
|
||||
"year": 2023,
|
||||
"balance": [{"code": "1100", "current": 10}],
|
||||
"profit_loss": [{"code": "2100", "current": 20}],
|
||||
}
|
||||
],
|
||||
"summary": {"revenue": 100, "profit": 10},
|
||||
}
|
||||
)
|
||||
self.assertEqual(len(finances.reports), 1)
|
||||
self.assertIsNotNone(finances.summary)
|
||||
|
||||
contracts = self.client._parse_contracts_data(
|
||||
{
|
||||
"contracts": [
|
||||
{
|
||||
"registry_number": "c-1",
|
||||
"customer": {"inn": _digits(10)},
|
||||
"suppliers": [{"inn": _digits(10)}, None],
|
||||
}
|
||||
],
|
||||
"pagination": {"total_records": 1, "total_pages": 1, "current_page": 1},
|
||||
"total_sum": 123,
|
||||
}
|
||||
)
|
||||
self.assertEqual(len(contracts.contracts), 1)
|
||||
self.assertEqual(len(contracts.contracts[0].suppliers), 1)
|
||||
|
||||
inspections = self.client._parse_inspections_data(
|
||||
{
|
||||
"inspections": [
|
||||
{
|
||||
"id": 1,
|
||||
"type": "planned",
|
||||
"status": "done",
|
||||
"violations_found": True,
|
||||
}
|
||||
],
|
||||
"pagination": {"total_records": 1, "total_pages": 1, "current_page": 1},
|
||||
}
|
||||
)
|
||||
self.assertEqual(len(inspections.inspections), 1)
|
||||
|
||||
enforcements = self.client._parse_enforcements_data(
|
||||
{
|
||||
"enforcements": [{"number": "e-1", "status": "open"}],
|
||||
"pagination": {"total_records": 1, "total_pages": 1, "current_page": 1},
|
||||
"total_debt": 555,
|
||||
}
|
||||
)
|
||||
self.assertEqual(len(enforcements.enforcements), 1)
|
||||
|
||||
legal_cases = self.client._parse_legal_cases_data(
|
||||
{
|
||||
"cases": [
|
||||
{
|
||||
"case_number": "A40-1/2024",
|
||||
"plaintiffs": [{"name": fake.company()}],
|
||||
"defendants": [{"name": fake.company()}],
|
||||
"instances": [{"number": "1", "court_name": "Court"}],
|
||||
}
|
||||
],
|
||||
"pagination": {"total_records": 1, "total_pages": 1, "current_page": 1},
|
||||
"total_claim_amount": 1000,
|
||||
}
|
||||
)
|
||||
self.assertEqual(len(legal_cases.cases), 1)
|
||||
|
||||
bank = self.client._parse_bank_data(
|
||||
{
|
||||
"bic": "044525225",
|
||||
"name": "Bank",
|
||||
"short_name": "BK",
|
||||
"corr_account": _digits(20),
|
||||
"status": "active",
|
||||
}
|
||||
)
|
||||
self.assertEqual(bank.bic, "044525225")
|
||||
|
||||
def test_parse_search_data_with_pagination(self):
|
||||
search = self.client._parse_search_data(
|
||||
{
|
||||
"records": [
|
||||
{"ogrn": _digits(13), "inn": _digits(10), "short_name": "A"}
|
||||
],
|
||||
"pagination": {"total_records": 1, "total_pages": 1, "current_page": 1},
|
||||
}
|
||||
)
|
||||
self.assertEqual(len(search.organizations), 1)
|
||||
Reference in New Issue
Block a user