refactor(parsers): remove proxy api endpoints
This commit is contained in:
@@ -15,7 +15,6 @@ from apps.parsers.models import (
|
|||||||
ParserLoadLog,
|
ParserLoadLog,
|
||||||
ParsingSettings,
|
ParsingSettings,
|
||||||
ProcurementRecord,
|
ProcurementRecord,
|
||||||
Proxy,
|
|
||||||
)
|
)
|
||||||
from rest_framework import serializers
|
from rest_framework import serializers
|
||||||
|
|
||||||
@@ -429,31 +428,6 @@ class ParserLoadLogListSerializer(serializers.Serializer):
|
|||||||
created_at = serializers.DateTimeField(read_only=True)
|
created_at = serializers.DateTimeField(read_only=True)
|
||||||
updated_at = serializers.DateTimeField(read_only=True)
|
updated_at = serializers.DateTimeField(read_only=True)
|
||||||
|
|
||||||
|
|
||||||
class ProxySerializer(serializers.ModelSerializer):
|
|
||||||
"""
|
|
||||||
Прокси-сервер для парсеров.
|
|
||||||
|
|
||||||
Используется для обхода блокировок при парсинге.
|
|
||||||
"""
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
model = Proxy
|
|
||||||
fields = [
|
|
||||||
"id",
|
|
||||||
"address",
|
|
||||||
"is_active",
|
|
||||||
"country_code",
|
|
||||||
"source",
|
|
||||||
"last_used_at",
|
|
||||||
"fail_count",
|
|
||||||
"description",
|
|
||||||
"created_at",
|
|
||||||
"updated_at",
|
|
||||||
]
|
|
||||||
read_only_fields = fields
|
|
||||||
|
|
||||||
|
|
||||||
class SourceCardRefreshParamSerializer(serializers.Serializer):
|
class SourceCardRefreshParamSerializer(serializers.Serializer):
|
||||||
"""Описание параметра ручного обновления карточки источника."""
|
"""Описание параметра ручного обновления карточки источника."""
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ from apps.parsers.views import (
|
|||||||
ParserLoadLogViewSet,
|
ParserLoadLogViewSet,
|
||||||
ParsingSettingsView,
|
ParsingSettingsView,
|
||||||
ProcurementViewSet,
|
ProcurementViewSet,
|
||||||
ProxyViewSet,
|
|
||||||
SourceCardDetailView,
|
SourceCardDetailView,
|
||||||
SourceCardListView,
|
SourceCardListView,
|
||||||
SourceCardRefreshView,
|
SourceCardRefreshView,
|
||||||
@@ -108,7 +107,6 @@ sources_urlpatterns = [
|
|||||||
|
|
||||||
system_router = DefaultRouter()
|
system_router = DefaultRouter()
|
||||||
system_router.register(r"logs", ParserLoadLogViewSet, basename="parser-logs")
|
system_router.register(r"logs", ParserLoadLogViewSet, basename="parser-logs")
|
||||||
system_router.register(r"proxies", ProxyViewSet, basename="proxies")
|
|
||||||
|
|
||||||
system_urlpatterns = [
|
system_urlpatterns = [
|
||||||
path("logs/export/", ParserLoadLogExportView.as_view(), name="parser-logs-export"),
|
path("logs/export/", ParserLoadLogExportView.as_view(), name="parser-logs-export"),
|
||||||
|
|||||||
@@ -19,7 +19,6 @@ from apps.parsers.models import (
|
|||||||
ParserLoadLog,
|
ParserLoadLog,
|
||||||
ParsingSettings,
|
ParsingSettings,
|
||||||
ProcurementRecord,
|
ProcurementRecord,
|
||||||
Proxy,
|
|
||||||
)
|
)
|
||||||
from apps.parsers.serializers import (
|
from apps.parsers.serializers import (
|
||||||
FinancialReportDetailSerializer,
|
FinancialReportDetailSerializer,
|
||||||
@@ -33,7 +32,6 @@ from apps.parsers.serializers import (
|
|||||||
ParserLoadLogSerializer,
|
ParserLoadLogSerializer,
|
||||||
ParsingSettingsSerializer,
|
ParsingSettingsSerializer,
|
||||||
ProcurementSerializer,
|
ProcurementSerializer,
|
||||||
ProxySerializer,
|
|
||||||
SourceCardDetailSerializer,
|
SourceCardDetailSerializer,
|
||||||
SourceCardRefreshRequestSerializer,
|
SourceCardRefreshRequestSerializer,
|
||||||
SourceCardRefreshResponseSerializer,
|
SourceCardRefreshResponseSerializer,
|
||||||
@@ -1091,45 +1089,3 @@ class ParserLoadLogExportView(APIView):
|
|||||||
)
|
)
|
||||||
|
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
|
||||||
class ProxyViewSet(ReadOnlyModelViewSet):
|
|
||||||
"""
|
|
||||||
API для просмотра списка прокси-серверов.
|
|
||||||
|
|
||||||
Используется для отладки и мониторинга парсеров.
|
|
||||||
Только для администраторов.
|
|
||||||
"""
|
|
||||||
|
|
||||||
queryset = Proxy.objects.all().order_by("-last_used_at")
|
|
||||||
serializer_class = ProxySerializer
|
|
||||||
permission_classes = [IsAdminUser]
|
|
||||||
filterset_fields = ["is_active"]
|
|
||||||
|
|
||||||
@swagger_auto_schema(
|
|
||||||
tags=[SYSTEM_TAG],
|
|
||||||
operation_summary="Список прокси",
|
|
||||||
operation_description=(
|
|
||||||
"Возвращает список прокси-серверов для парсеров.\n"
|
|
||||||
"Доступно только администраторам.\n"
|
|
||||||
"Поддерживает фильтрацию по: is_active."
|
|
||||||
),
|
|
||||||
responses={
|
|
||||||
200: ProxySerializer(many=True),
|
|
||||||
**ErrorResponses.ADMIN,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
def list(self, request, *args, **kwargs):
|
|
||||||
return super().list(request, *args, **kwargs)
|
|
||||||
|
|
||||||
@swagger_auto_schema(
|
|
||||||
tags=[SYSTEM_TAG],
|
|
||||||
operation_summary="Детали прокси",
|
|
||||||
operation_description="Возвращает информацию о конкретном прокси.",
|
|
||||||
responses={
|
|
||||||
200: ProxySerializer,
|
|
||||||
**ErrorResponses.ADMIN_NOT_FOUND,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
def retrieve(self, request, *args, **kwargs):
|
|
||||||
return super().retrieve(request, *args, **kwargs)
|
|
||||||
|
|||||||
@@ -19,7 +19,6 @@ from tests.apps.parsers.factories import (
|
|||||||
InspectionRecordFactory,
|
InspectionRecordFactory,
|
||||||
ManufacturerRecordFactory,
|
ManufacturerRecordFactory,
|
||||||
ParserLoadLogFactory,
|
ParserLoadLogFactory,
|
||||||
ProxyFactory,
|
|
||||||
)
|
)
|
||||||
from tests.apps.user.factories import UserFactory
|
from tests.apps.user.factories import UserFactory
|
||||||
from tests.utils.fixtures import fake
|
from tests.utils.fixtures import fake
|
||||||
@@ -151,11 +150,9 @@ class ParsersViewSetTest(APITestCase):
|
|||||||
self.assertEqual(detail.status_code, status.HTTP_200_OK)
|
self.assertEqual(detail.status_code, status.HTTP_200_OK)
|
||||||
self.assertIn("lines", detail.data)
|
self.assertIn("lines", detail.data)
|
||||||
|
|
||||||
def test_system_logs_and_proxies_admin_only(self):
|
def test_system_logs_admin_only(self):
|
||||||
log = ParserLoadLogFactory()
|
log = ParserLoadLogFactory()
|
||||||
proxy = ProxyFactory()
|
|
||||||
url_logs = reverse("api_v1:system:parser-logs-list")
|
url_logs = reverse("api_v1:system:parser-logs-list")
|
||||||
url_proxy = reverse("api_v1:system:proxies-list")
|
|
||||||
|
|
||||||
response = self.client.get(url_logs)
|
response = self.client.get(url_logs)
|
||||||
self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)
|
self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)
|
||||||
@@ -172,13 +169,6 @@ class ParsersViewSetTest(APITestCase):
|
|||||||
)
|
)
|
||||||
self.assertEqual(detail.status_code, status.HTTP_200_OK)
|
self.assertEqual(detail.status_code, status.HTTP_200_OK)
|
||||||
|
|
||||||
proxy_response = self.client.get(url_proxy)
|
|
||||||
self.assertEqual(proxy_response.status_code, status.HTTP_200_OK)
|
|
||||||
proxy_detail = self.client.get(
|
|
||||||
reverse("api_v1:system:proxies-detail", args=[proxy.id])
|
|
||||||
)
|
|
||||||
self.assertEqual(proxy_detail.status_code, status.HTTP_200_OK)
|
|
||||||
|
|
||||||
def test_system_logs_support_search_and_organizations_count(self):
|
def test_system_logs_support_search_and_organizations_count(self):
|
||||||
first_log = ParserLoadLogFactory(
|
first_log = ParserLoadLogFactory(
|
||||||
source="manufactures",
|
source="manufactures",
|
||||||
|
|||||||
Reference in New Issue
Block a user