From 50c7a61c6db51629ab2c986e9141b1cf0433bf20 Mon Sep 17 00:00:00 2001 From: alex-smile <443677891@qq.com> Date: Wed, 5 Jul 2023 15:09:51 +0800 Subject: [PATCH] fix project root __init__.py; fix lint, tests --- src/dashboard/apigateway/{ => apigateway}/__init__.py | 0 .../apigateway/apigateway/apps/access_log/helpers.py | 4 ++-- .../apigateway/apps/support/resource_doc/import_doc/docs.py | 1 + .../apigateway/controller/crds/v1beta1/convertor.py | 2 ++ .../apigateway/apigateway/controller/registry/dict.py | 2 +- .../apigateway/editions/ee/apps/esb/status/es_client.py | 5 ++--- .../apigateway/tests/apps/docs/esb/component/test_views.py | 2 +- .../apigateway/tests/apps/docs/esb/doc/test_views.py | 2 +- .../apigateway/tests/apps/docs/esb/system/test_views.py | 2 +- .../apigateway/tests/apps/docs/gateway/gateway/test_views.py | 2 +- .../tests/apps/docs/gateway/resource/test_views.py | 2 +- .../tests/apps/docs/gateway/resource_doc/test_constants.py | 2 +- .../tests/apps/docs/gateway/resource_doc/test_views.py | 2 +- .../apigateway/tests/apps/docs/gateway/sdk/test_views.py | 2 +- .../apigateway/tests/apps/docs/gateway/stage/test_views.py | 2 +- 15 files changed, 17 insertions(+), 15 deletions(-) rename src/dashboard/apigateway/{ => apigateway}/__init__.py (100%) diff --git a/src/dashboard/apigateway/__init__.py b/src/dashboard/apigateway/apigateway/__init__.py similarity index 100% rename from src/dashboard/apigateway/__init__.py rename to src/dashboard/apigateway/apigateway/__init__.py diff --git a/src/dashboard/apigateway/apigateway/apps/access_log/helpers.py b/src/dashboard/apigateway/apigateway/apps/access_log/helpers.py index 13fde6b35..347b649e7 100644 --- a/src/dashboard/apigateway/apigateway/apps/access_log/helpers.py +++ b/src/dashboard/apigateway/apigateway/apps/access_log/helpers.py @@ -20,7 +20,7 @@ import logging import urllib from abc import ABC, abstractmethod -from typing import ClassVar +from typing import ClassVar, Type from django.conf import settings from django.utils.translation import gettext as _ @@ -64,7 +64,7 @@ def get_client_class(self, es_client_type): class BaseLogSearch(ABC): _es_index: str = settings.ACCESS_LOG_CONFIG["es_index"] _es_time_field_name: str = settings.ACCESS_LOG_CONFIG["es_time_field_name"] - _es_client_class: ClassVar[BaseESClient] + _es_client_class: ClassVar[Type[BaseESClient]] # FIXME: change api_id to gateway_id def __init__( diff --git a/src/dashboard/apigateway/apigateway/apps/support/resource_doc/import_doc/docs.py b/src/dashboard/apigateway/apigateway/apps/support/resource_doc/import_doc/docs.py index 01fe8a55a..01974366f 100644 --- a/src/dashboard/apigateway/apigateway/apps/support/resource_doc/import_doc/docs.py +++ b/src/dashboard/apigateway/apigateway/apps/support/resource_doc/import_doc/docs.py @@ -41,6 +41,7 @@ class BaseDoc: resource_id: Optional[int] = None resource_doc_id: Optional[int] = None resource_doc_swagger_id: Optional[int] = None + has_changed: bool = True @property def doc_key(self) -> Optional[str]: diff --git a/src/dashboard/apigateway/apigateway/controller/crds/v1beta1/convertor.py b/src/dashboard/apigateway/apigateway/controller/crds/v1beta1/convertor.py index 9ea067bf1..ef7fd658d 100644 --- a/src/dashboard/apigateway/apigateway/controller/crds/v1beta1/convertor.py +++ b/src/dashboard/apigateway/apigateway/controller/crds/v1beta1/convertor.py @@ -95,9 +95,11 @@ def _iter_convert(self): def get_kubernetes_resources(self) -> Iterable[KubernetesResource]: if self.include_config: + assert self._gateway_config yield self._gateway_config if self.include_stage: + assert self._stage yield self._stage if self.include_service: diff --git a/src/dashboard/apigateway/apigateway/controller/registry/dict.py b/src/dashboard/apigateway/apigateway/controller/registry/dict.py index b82221c47..3e27ee554 100644 --- a/src/dashboard/apigateway/apigateway/controller/registry/dict.py +++ b/src/dashboard/apigateway/apigateway/controller/registry/dict.py @@ -38,7 +38,7 @@ def apply_resource(self, resource: KubernetesResource) -> bool: self._registry_dict[self._get_key(resource.kind, resource.metadata.name)] = deepcopy(resource) return True - def sync_resources_by_key_prefix(self, resources: List[KubernetesResource]) -> List[KubernetesResource]: + def sync_resources_by_key_prefix(self, resources: Iterable[KubernetesResource]) -> List[KubernetesResource]: self.delete_resources_by_key_prefix() for resource in resources: diff --git a/src/dashboard/apigateway/apigateway/editions/ee/apps/esb/status/es_client.py b/src/dashboard/apigateway/apigateway/editions/ee/apps/esb/status/es_client.py index c6c7886ae..501176cd0 100644 --- a/src/dashboard/apigateway/apigateway/editions/ee/apps/esb/status/es_client.py +++ b/src/dashboard/apigateway/apigateway/editions/ee/apps/esb/status/es_client.py @@ -19,7 +19,7 @@ """ 请求Elasticsearch辅助Client """ -from typing import ClassVar +from typing import ClassVar, Type from django.conf import settings @@ -28,10 +28,9 @@ class BaseSearchClient: - _es_index = settings.BK_ESB_ACCESS_LOG_CONFIG["es_index"] _es_time_field_name = settings.BK_ESB_ACCESS_LOG_CONFIG["es_time_field_name"] - _es_client_class: ClassVar[BaseESClient] + _es_client_class: ClassVar[Type[BaseESClient]] def __init__(self): self._es_client = self._es_client_class(self._es_index) diff --git a/src/dashboard/apigateway/apigateway/tests/apps/docs/esb/component/test_views.py b/src/dashboard/apigateway/apigateway/tests/apps/docs/esb/component/test_views.py index aad21b1d1..4908ce73e 100644 --- a/src/dashboard/apigateway/apigateway/tests/apps/docs/esb/component/test_views.py +++ b/src/dashboard/apigateway/apigateway/tests/apps/docs/esb/component/test_views.py @@ -19,9 +19,9 @@ from unittest.mock import MagicMock import pytest -from tests.utils.testing import get_response_json from apigateway.apps.docs.esb.component import views +from apigateway.tests.utils.testing import get_response_json class TestAPIViewSet: diff --git a/src/dashboard/apigateway/apigateway/tests/apps/docs/esb/doc/test_views.py b/src/dashboard/apigateway/apigateway/tests/apps/docs/esb/doc/test_views.py index a2303b6a4..4ea65b650 100644 --- a/src/dashboard/apigateway/apigateway/tests/apps/docs/esb/doc/test_views.py +++ b/src/dashboard/apigateway/apigateway/tests/apps/docs/esb/doc/test_views.py @@ -17,9 +17,9 @@ # to the current version of the project delivered to anyone in the future. # import pytest -from tests.utils.testing import get_response_json from apigateway.apps.docs.esb.doc import views +from apigateway.tests.utils.testing import get_response_json pytestmark = pytest.mark.django_db diff --git a/src/dashboard/apigateway/apigateway/tests/apps/docs/esb/system/test_views.py b/src/dashboard/apigateway/apigateway/tests/apps/docs/esb/system/test_views.py index b3646887e..2ed148cb6 100644 --- a/src/dashboard/apigateway/apigateway/tests/apps/docs/esb/system/test_views.py +++ b/src/dashboard/apigateway/apigateway/tests/apps/docs/esb/system/test_views.py @@ -18,9 +18,9 @@ # import pytest from django.conf import settings -from tests.utils.testing import get_response_json from apigateway.apps.docs.esb.system import views +from apigateway.tests.utils.testing import get_response_json pytestmark = pytest.mark.django_db diff --git a/src/dashboard/apigateway/apigateway/tests/apps/docs/gateway/gateway/test_views.py b/src/dashboard/apigateway/apigateway/tests/apps/docs/gateway/gateway/test_views.py index 77515cbae..01c5cbfac 100644 --- a/src/dashboard/apigateway/apigateway/tests/apps/docs/gateway/gateway/test_views.py +++ b/src/dashboard/apigateway/apigateway/tests/apps/docs/gateway/gateway/test_views.py @@ -17,9 +17,9 @@ # to the current version of the project delivered to anyone in the future. # import pytest -from tests.utils.testing import get_response_json from apigateway.apps.docs.gateway.gateway import views +from apigateway.tests.utils.testing import get_response_json class TestGatewayViewSet: diff --git a/src/dashboard/apigateway/apigateway/tests/apps/docs/gateway/resource/test_views.py b/src/dashboard/apigateway/apigateway/tests/apps/docs/gateway/resource/test_views.py index 1cba639ff..80759b45d 100644 --- a/src/dashboard/apigateway/apigateway/tests/apps/docs/gateway/resource/test_views.py +++ b/src/dashboard/apigateway/apigateway/tests/apps/docs/gateway/resource/test_views.py @@ -17,9 +17,9 @@ # to the current version of the project delivered to anyone in the future. # import pytest -from tests.utils.testing import get_response_json from apigateway.apps.docs.gateway.resource import views +from apigateway.tests.utils.testing import get_response_json class TestResourceViewSet: diff --git a/src/dashboard/apigateway/apigateway/tests/apps/docs/gateway/resource_doc/test_constants.py b/src/dashboard/apigateway/apigateway/tests/apps/docs/gateway/resource_doc/test_constants.py index 89e392ba7..38a0b5bfd 100644 --- a/src/dashboard/apigateway/apigateway/tests/apps/docs/gateway/resource_doc/test_constants.py +++ b/src/dashboard/apigateway/apigateway/tests/apps/docs/gateway/resource_doc/test_constants.py @@ -15,9 +15,9 @@ # We undertake not to change the open source license (MIT license) applicable # to the current version of the project delivered to anyone in the future. # -from utils.jinja2 import render_to_string from apigateway.apps.docs.gateway.resource_doc.constants import BKAPI_AUTHORIZATION_DESCRIPTION_ZH +from apigateway.utils.jinja2 import render_to_string def test_bkapi_authorization_description(): diff --git a/src/dashboard/apigateway/apigateway/tests/apps/docs/gateway/resource_doc/test_views.py b/src/dashboard/apigateway/apigateway/tests/apps/docs/gateway/resource_doc/test_views.py index b0ce0578a..1794d8675 100644 --- a/src/dashboard/apigateway/apigateway/tests/apps/docs/gateway/resource_doc/test_views.py +++ b/src/dashboard/apigateway/apigateway/tests/apps/docs/gateway/resource_doc/test_views.py @@ -17,9 +17,9 @@ # to the current version of the project delivered to anyone in the future. # import pytest -from tests.utils.testing import get_response_json from apigateway.apps.docs.gateway.resource_doc import views +from apigateway.tests.utils.testing import get_response_json class TestResourceDocViewSet: diff --git a/src/dashboard/apigateway/apigateway/tests/apps/docs/gateway/sdk/test_views.py b/src/dashboard/apigateway/apigateway/tests/apps/docs/gateway/sdk/test_views.py index 46fd2a146..e1932f75f 100644 --- a/src/dashboard/apigateway/apigateway/tests/apps/docs/gateway/sdk/test_views.py +++ b/src/dashboard/apigateway/apigateway/tests/apps/docs/gateway/sdk/test_views.py @@ -17,10 +17,10 @@ # to the current version of the project delivered to anyone in the future. # import pytest -from tests.utils.testing import get_response_json from apigateway.apps.docs.gateway.sdk import views from apigateway.apps.docs.gateway.sdk.helpers import DummyResourceForSDK +from apigateway.tests.utils.testing import get_response_json class TestSDKViewSet: diff --git a/src/dashboard/apigateway/apigateway/tests/apps/docs/gateway/stage/test_views.py b/src/dashboard/apigateway/apigateway/tests/apps/docs/gateway/stage/test_views.py index 911f61eec..f1a3c2469 100644 --- a/src/dashboard/apigateway/apigateway/tests/apps/docs/gateway/stage/test_views.py +++ b/src/dashboard/apigateway/apigateway/tests/apps/docs/gateway/stage/test_views.py @@ -17,9 +17,9 @@ # to the current version of the project delivered to anyone in the future. # import pytest -from tests.utils.testing import get_response_json from apigateway.apps.docs.gateway.stage import views +from apigateway.tests.utils.testing import get_response_json class TestStageViewSet: