fix(parsers): unblock source status and heavy product import
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from unittest.mock import patch
|
||||
from urllib.parse import urlparse
|
||||
|
||||
import requests
|
||||
@@ -22,6 +23,7 @@ from apps.parsers.clients.minpromtorg.schemas import (
|
||||
from apps.parsers.clients.proverki import ProverkiClient
|
||||
from apps.parsers.clients.proverki.schemas import Inspection
|
||||
from django.test import TestCase, tag
|
||||
from openpyxl import load_workbook as openpyxl_load_workbook
|
||||
from requests.adapters import BaseAdapter
|
||||
|
||||
from tests.utils import Response, TestHTTPServer
|
||||
@@ -513,6 +515,40 @@ class IndustrialProductsClientTest(TestCase):
|
||||
|
||||
self.assertEqual(products, [])
|
||||
|
||||
def test_fetch_products_uses_read_only_workbook(self):
|
||||
excel_bytes, rows = build_minpromtorg_products_excel(count=2)
|
||||
file_name = "industrial_products_20260428.xlsx"
|
||||
|
||||
with TestHTTPServer() as server:
|
||||
server.add_json(
|
||||
"/api/kss-document-preview",
|
||||
{
|
||||
"data": [
|
||||
{
|
||||
"name": IndustrialProductsClient().query,
|
||||
"files": [
|
||||
{"name": file_name, "url": f"/files/{file_name}"}
|
||||
],
|
||||
}
|
||||
]
|
||||
},
|
||||
)
|
||||
server.add_bytes(f"/files/{file_name}", excel_bytes)
|
||||
|
||||
client = IndustrialProductsClient(
|
||||
host=_host_from_base_url(server.base_url),
|
||||
scheme="http",
|
||||
http_adapter=server.adapter,
|
||||
)
|
||||
with patch(
|
||||
"apps.parsers.clients.minpromtorg.products.load_workbook",
|
||||
wraps=openpyxl_load_workbook,
|
||||
) as load_workbook_mock:
|
||||
products = client.fetch_products()
|
||||
|
||||
self.assertEqual(len(products), len(rows))
|
||||
self.assertTrue(load_workbook_mock.call_args.kwargs["read_only"])
|
||||
|
||||
def test_get_latest_file_url_falls_back_to_excel_file(self):
|
||||
client = IndustrialProductsClient()
|
||||
files = [
|
||||
|
||||
Reference in New Issue
Block a user