diff --git a/sdks/apigw-manager/tests/apigw_manager/apigw/test_utils.py b/sdks/apigw-manager/tests/apigw_manager/apigw/test_utils.py index ed1c1f3..efb90fa 100644 --- a/sdks/apigw-manager/tests/apigw_manager/apigw/test_utils.py +++ b/sdks/apigw-manager/tests/apigw_manager/apigw/test_utils.py @@ -14,8 +14,9 @@ import pytest from django.conf import settings +from packaging.version import InvalidVersion -from apigw_manager.apigw.utils import ZipArchiveFile, get_configuration, parse_value_list +from apigw_manager.apigw.utils import ZipArchiveFile, get_configuration, parse_value_list, parse_version class TestGetConfiguration: @@ -51,16 +52,16 @@ def test_jwt_provider_cls(self, settings, faker): ("kwargs", "expected"), [ ( - {}, - "", + {}, + "", ), ( - {"host": "http://apigw.svc/api/test/prod/"}, - "http://apigw.svc/api/test/prod", + {"host": "http://apigw.svc/api/test/prod/"}, + "http://apigw.svc/api/test/prod", ), ( - {"host": "http://apigw.svc/api/test/prod"}, - "http://apigw.svc/api/test/prod", + {"host": "http://apigw.svc/api/test/prod"}, + "http://apigw.svc/api/test/prod", ), ], ) @@ -76,24 +77,24 @@ def test_host_by_kwargs(self, settings, kwargs, expected): ("fake_settings", "expected"), [ ( - {}, - "", + {}, + "", ), ( - { - "BK_APIGATEWAY_API_STAGE_URL": "http://apigw.svc/api/bk-apigateway/prod", - }, - "http://apigw.svc/api/bk-apigateway/prod", + { + "BK_APIGATEWAY_API_STAGE_URL": "http://apigw.svc/api/bk-apigateway/prod", + }, + "http://apigw.svc/api/bk-apigateway/prod", ), ( - {"BK_API_URL_TMPL": "http://apigw.svc/api/{api_name}/"}, - "http://apigw.svc/api/bk-apigateway/prod", + {"BK_API_URL_TMPL": "http://apigw.svc/api/{api_name}/"}, + "http://apigw.svc/api/bk-apigateway/prod", ), ( - { - "BK_API_URL_TMPL": "http://apigw.svc/api/{api_name}", - }, - "http://apigw.svc/api/bk-apigateway/prod", + { + "BK_API_URL_TMPL": "http://apigw.svc/api/{api_name}", + }, + "http://apigw.svc/api/bk-apigateway/prod", ), ], ) @@ -140,3 +141,25 @@ def test_get_archived_files(self): file_path = os.path.join(settings.BASE_DIR, "tests", "files", "docs") result = ZipArchiveFile._get_archived_files(file_path) assert result == {os.path.join(file_path, "zh", "get.md"): os.path.join("zh", "get.md")} + + +class TestVersion: + + def test_valid_versions(self): + valid_versions = [ + "1.0.0", + "2.1.0-alpha", + "3.0.0-beta.1", + "4.0.0-rc.1", + "5.0.0+build.1", + "6.0.0-alpha+build.1", + "7.0.0-feature-layered-alpha2", + "8.0.0-feature-layered-alpha.2", + "3.14.1-feature-layered-alpha2" + ] + for version in valid_versions: + try: + parse_version(version) + except InvalidVersion: + pytest.fail(f"Valid version '{version}' raised InvalidVersion") + diff --git a/sdks/apigw-manager/tests/conftest.py b/sdks/apigw-manager/tests/conftest.py index 8fee742..ab2fb82 100644 --- a/sdks/apigw-manager/tests/conftest.py +++ b/sdks/apigw-manager/tests/conftest.py @@ -17,12 +17,6 @@ def _reset_bkapi_settings(): bkapi_settings.reset() - -@pytest.fixture(autouse=True) -def _mark_django_db(db): - pass - - @pytest.fixture() def fake_gateway_name(settings, faker): gateway_name = faker.pystr()