Skip to content

Commit

Permalink
test: fix unittest
Browse files Browse the repository at this point in the history
  • Loading branch information
narasux committed Sep 6, 2023
1 parent b43df6e commit 21e0373
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/bk-user/tests/apis/web/data_source/test_data_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
@pytest.fixture()
def local_ds_plugin_config() -> Dict[str, Any]:
return {
"enable_login_by_password": True,
"enable_account_password_login": True,
"password_rule": {
"min_length": 12,
"contain_lowercase": True,
Expand Down Expand Up @@ -172,7 +172,7 @@ def test_create_with_minimal_plugin_config(self, api_client):
data={
"name": generate_random_string(),
"plugin_id": DataSourcePluginEnum.LOCAL,
"plugin_config": {"enable_login_by_password": False},
"plugin_config": {"enable_account_password_login": False},
},
)
assert resp.status_code == status.HTTP_201_CREATED
Expand Down Expand Up @@ -224,7 +224,7 @@ def test_create_with_invalid_notification_template(self, api_client, local_ds_pl
assert "邮件通知模板需要提供标题" in resp.data["message"]

def test_create_with_invalid_plugin_config(self, api_client, local_ds_plugin_config):
local_ds_plugin_config.pop("enable_login_by_password")
local_ds_plugin_config.pop("enable_account_password_login")
resp = api_client.post(
reverse("data_source.list_create"),
data={
Expand All @@ -234,7 +234,7 @@ def test_create_with_invalid_plugin_config(self, api_client, local_ds_plugin_con
},
)
assert resp.status_code == status.HTTP_400_BAD_REQUEST
assert "插件配置不合法:enable_login_by_password: Field required" in resp.data["message"]
assert "插件配置不合法:enable_account_password_login: Field required" in resp.data["message"]

def test_create_without_required_field_mapping(self, api_client):
"""非本地数据源,需要字段映射配置"""
Expand Down Expand Up @@ -266,24 +266,24 @@ def test_list_other_tenant_data_source(self, api_client, random_tenant, data_sou

class TestDataSourceUpdateApi:
def test_update_local_data_source(self, api_client, data_source, local_ds_plugin_config):
local_ds_plugin_config["enable_login_by_password"] = False
local_ds_plugin_config["enable_account_password_login"] = False
resp = api_client.put(
reverse("data_source.retrieve_update", kwargs={"id": data_source.id}),
data={"plugin_config": local_ds_plugin_config},
)
assert resp.status_code == status.HTTP_204_NO_CONTENT

resp = api_client.get(reverse("data_source.retrieve_update", kwargs={"id": data_source.id}))
assert resp.data["plugin_config"]["enable_login_by_password"] is False
assert resp.data["plugin_config"]["enable_account_password_login"] is False

def test_update_with_invalid_plugin_config(self, api_client, data_source, local_ds_plugin_config):
local_ds_plugin_config.pop("enable_login_by_password")
local_ds_plugin_config.pop("enable_account_password_login")
resp = api_client.put(
reverse("data_source.retrieve_update", kwargs={"id": data_source.id}),
data={"plugin_config": local_ds_plugin_config},
)
assert resp.status_code == status.HTTP_400_BAD_REQUEST
assert "插件配置不合法:enable_login_by_password: Field required" in resp.data["message"]
assert "插件配置不合法:enable_account_password_login: Field required" in resp.data["message"]

def test_update_without_required_field_mapping(self, api_client):
"""非本地数据源,需要字段映射配置"""
Expand Down

0 comments on commit 21e0373

Please sign in to comment.