Skip to content

Commit

Permalink
fix: fix apigw version validate
Browse files Browse the repository at this point in the history
  • Loading branch information
Han-Ya-Jun committed Jun 6, 2024
1 parent e5e088f commit 33306f8
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 25 deletions.
61 changes: 42 additions & 19 deletions sdks/apigw-manager/tests/apigw_manager/apigw/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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",
),
],
)
Expand All @@ -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",
),
],
)
Expand Down Expand Up @@ -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")

6 changes: 0 additions & 6 deletions sdks/apigw-manager/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 33306f8

Please sign in to comment.