-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ci(github action): update branch of checking (#1384)
- Loading branch information
Showing
11 changed files
with
731 additions
and
546 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
name: bklogin_ci_check | ||
on: | ||
push: | ||
branches: [ main, pre_*, ft_*, release/* ] | ||
paths: | ||
- "src/bk-login/**" | ||
- "src/idp-plugins/**" | ||
pull_request: | ||
branches: [ main, pre_*, ft_*, release/* ] | ||
paths: | ||
- "src/bk-login/**" | ||
- "src/idp-plugins/**" | ||
jobs: | ||
check: | ||
runs-on: ubuntu-latest | ||
continue-on-error: true | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Set up Python | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: "3.10" | ||
- name: create idp plugin symbolic link | ||
run: | | ||
ln -s $(pwd)/src/idp-plugins/idp_plugins $(pwd)/src/bk-login/bklogin | ||
- name: Format & Lint with ruff | ||
run: | | ||
pip install ruff==0.1.4 | ||
ruff format src/bk-login --config=src/bk-login/pyproject.toml | ||
ruff src/bk-login --config=src/bk-login/pyproject.toml | ||
- name: Lint with mypy | ||
run: | | ||
pip install mypy==1.6.1 types-requests==2.31.0.2 types-setuptools==57.4.18 types-dataclasses==0.1.7 types-redis==3.5.18 types-PyMySQL==1.1.0.1 types-six==0.1.9 types-toml==0.1.5 types-pytz==2023.3.0.0 types-urllib3==1.26.25.14 | ||
mypy src/bk-login --config-file=src/bk-login/pyproject.toml | ||
test: | ||
strategy: | ||
fail-fast: false | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Start MySQL Container | ||
uses: samin/[email protected] | ||
with: | ||
mysql version: "8.0" | ||
mysql database: bk-login | ||
mysql user: root | ||
mysql password: root_pwd | ||
mysql root password: root_pwd | ||
- name: Start Redis Container | ||
uses: supercharge/[email protected] | ||
with: | ||
redis-version: "3.2.0" | ||
- uses: actions/checkout@v3 | ||
- name: Set up Python | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: "3.10" | ||
- name: create idp plugin symbolic link | ||
run: | | ||
ln -s $(pwd)/src/idp-plugins/idp_plugins $(pwd)/src/bk-login/bklogin | ||
- name: Set up Poetry | ||
uses: abatilo/[email protected] | ||
with: | ||
poetry-version: "1.6.1" | ||
- name: Install dependencies | ||
working-directory: src/bk-login | ||
run: poetry install | ||
- name: Run unittest | ||
working-directory: src/bk-login | ||
run: | | ||
# random secret | ||
export BK_APP_SECRET="fod6MKVTVi_3M5HgGoj-qI7b3l0dgCzTBwGypnDz4vg=" | ||
export BK_USER_APP_SECRET="Vi_3M5HgGogCzTBwGypnDz4vgfod6MKVTj-qI7b3l0d=" | ||
# random secret key | ||
export BKKRILL_ENCRYPT_SECRET_KEY="tttHSBLiVdQPItrfy7n9dV7AxAUMZpYVkD6IHMbL0VE=" | ||
export BK_DOMAIN="example.com" | ||
export BK_COMPONENT_API_URL="" | ||
export MYSQL_PASSWORD=root_pwd | ||
export MYSQL_HOST="127.0.0.1" | ||
export DJANGO_SETTINGS_MODULE=bklogin.settings | ||
poetry run pytest ./tests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,15 @@ | ||
name: bkuser_ci_check | ||
on: | ||
push: | ||
branches: [master, ft_tenant] | ||
branches: [ main, pre_*, ft_*, release/* ] | ||
paths: | ||
- "src/bk-user/**" | ||
- "src/idp-plugins/**" | ||
pull_request: | ||
branches: [master, ft_tenant] | ||
branches: [ main, pre_*, ft_*, release/* ] | ||
paths: | ||
- "src/bk-user/**" | ||
- "src/idp-plugins/**" | ||
jobs: | ||
check: | ||
runs-on: ubuntu-latest | ||
|
@@ -20,23 +22,16 @@ jobs: | |
python-version: "3.10" | ||
- name: create idp plugin symbolic link | ||
run: | | ||
ln -s $(pwd)/src/idp-plugins/idp_plugins $(pwd)/src/bk-login/bklogin | ||
ln -s $(pwd)/src/idp-plugins/idp_plugins $(pwd)/src/bk-user/bkuser | ||
- name: Format & Lint with ruff | ||
run: | | ||
pip install ruff==0.1.4 | ||
ruff format src/bk-user --config=src/bk-user/pyproject.toml | ||
ruff src/bk-user --config=src/bk-user/pyproject.toml | ||
ruff format src/bk-login --config=src/bk-login/pyproject.toml | ||
ruff src/bk-login --config=src/bk-login/pyproject.toml | ||
ruff format src/idp-plugins --config=src/idp-plugins/pyproject.toml | ||
ruff src/idp-plugins --config=src/idp-plugins/pyproject.toml | ||
- name: Lint with mypy | ||
run: | | ||
pip install mypy==1.6.1 types-requests==2.31.0.2 types-setuptools==57.4.18 types-dataclasses==0.1.7 types-redis==3.5.18 types-PyMySQL==1.1.0.1 types-six==0.1.9 types-toml==0.1.5 types-pytz==2023.3.0.0 types-urllib3==1.26.25.14 | ||
mypy src/bk-user --config-file=src/bk-user/pyproject.toml | ||
mypy src/bk-login --config-file=src/bk-login/pyproject.toml | ||
mypy src/idp-plugins --config-file=src/idp-plugins/pyproject.toml | ||
test: | ||
strategy: | ||
fail-fast: false | ||
|
@@ -61,7 +56,6 @@ jobs: | |
python-version: "3.10" | ||
- name: create idp plugin symbolic link | ||
run: | | ||
ln -s $(pwd)/src/idp-plugins/idp_plugins $(pwd)/src/bk-login/bklogin | ||
ln -s $(pwd)/src/idp-plugins/idp_plugins $(pwd)/src/bk-user/bkuser | ||
- name: Set up Poetry | ||
uses: abatilo/[email protected] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
name: idp_plugin_ci_check | ||
on: | ||
push: | ||
branches: [ main, pre_*, ft_*, release/* ] | ||
paths: | ||
- "src/idp-plugins/**" | ||
pull_request: | ||
branches: [ main, pre_*, ft_*, release/* ] | ||
paths: | ||
- "src/idp-plugins/**" | ||
jobs: | ||
check: | ||
runs-on: ubuntu-latest | ||
continue-on-error: true | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Set up Python | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: "3.10" | ||
- name: Format & Lint with ruff | ||
run: | | ||
pip install ruff==0.1.4 | ||
ruff format src/idp-plugins --config=src/idp-plugins/pyproject.toml | ||
ruff src/idp-plugins --config=src/idp-plugins/pyproject.toml | ||
- name: Lint with mypy | ||
run: | | ||
pip install mypy==1.6.1 types-requests==2.31.0.2 types-setuptools==57.4.18 types-dataclasses==0.1.7 types-redis==3.5.18 types-PyMySQL==1.1.0.1 types-six==0.1.9 types-toml==0.1.5 types-pytz==2023.3.0.0 types-urllib3==1.26.25.14 | ||
mypy src/idp-plugins --config-file=src/idp-plugins/pyproject.toml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
TencentBlueKing is pleased to support the open source community by making 蓝鲸智云-用户管理(Bk-User) available. | ||
Copyright (C) 2017-2021 THL A29 Limited, a Tencent company. All rights reserved. | ||
Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at http://opensource.org/licenses/MIT | ||
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
specific language governing permissions and limitations under the License. | ||
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
TencentBlueKing is pleased to support the open source community by making 蓝鲸智云-用户管理(Bk-User) available. | ||
Copyright (C) 2017-2021 THL A29 Limited, a Tencent company. All rights reserved. | ||
Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at http://opensource.org/licenses/MIT | ||
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
specific language governing permissions and limitations under the License. | ||
""" | ||
import pytest | ||
from bklogin.utils.std_error import APIError, ErrorCode | ||
from django.utils.translation import gettext_lazy | ||
|
||
|
||
def _format_message(message, exc): | ||
return f"{exc.code}-{message}" | ||
|
||
|
||
class TestingErrorCodes: | ||
foo_bar = ErrorCode("foo message", status_code=500) | ||
foo_formatted = ErrorCode("foo message", extra_formatter=_format_message) | ||
|
||
|
||
class TestErrorCode: | ||
def test_integrated(self): | ||
error_codes = TestingErrorCodes() | ||
exc = error_codes.foo_bar | ||
|
||
assert isinstance(exc, APIError) | ||
assert exc.code == "foo_bar" | ||
assert exc.status_code == 500 # noqa: PLR2004 | ||
assert exc.message == "foo message" | ||
|
||
def test_formatted(self): | ||
exc = TestingErrorCodes().foo_formatted | ||
assert exc.message == "foo_formatted-foo message" | ||
|
||
def test_exception_clone(self): | ||
error_codes = TestingErrorCodes() | ||
assert error_codes.foo_bar is not error_codes.foo_bar | ||
|
||
|
||
class TestAPIError: | ||
def test_simple_message(self): | ||
exc = APIError("foo", "foo error", "INVALID_ARGUMENT") | ||
assert exc.message == "foo error" | ||
assert exc.code == "foo" | ||
|
||
@pytest.mark.parametrize( | ||
("message", "replace", "kwargs", "result"), | ||
[ | ||
("", False, {}, "name={name}"), | ||
("value", False, {}, "name={name}: value"), | ||
("value", False, {"name": "foo"}, "name=foo: value"), | ||
("value", True, {"name": "foo"}, "value"), | ||
], | ||
) | ||
def test_message_format(self, message, replace, result, kwargs): | ||
exc = APIError("foo", "name={name}") | ||
exc = exc.format(message=message, replace=replace, **kwargs) | ||
assert exc.message == result | ||
|
||
def test_format_clone(self): | ||
exc = APIError("foo", "message") | ||
formatted_exc = exc.format() | ||
assert formatted_exc is not exc | ||
|
||
def test_data_property_in_chain(self): | ||
exc = APIError("foo", "name={name}") | ||
assert exc.set_data({"value": -1}).f(name="bar").data == {"value": -1} | ||
|
||
def test_lazy_str(self): | ||
exc = APIError("foo", gettext_lazy("message")) | ||
formatted_exc = exc.format(gettext_lazy("new message")) | ||
assert formatted_exc.message == "message: new message" |
Oops, something went wrong.