From 5b785ab7c6df17695d566de9f75a14e97379ee90 Mon Sep 17 00:00:00 2001 From: bidaya0 Date: Wed, 21 Dec 2022 11:35:09 +0800 Subject: [PATCH 1/5] fix: typing in config_settings. --- dongtai_web/threshold/config_setting.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/dongtai_web/threshold/config_setting.py b/dongtai_web/threshold/config_setting.py index 70d56d2e8..3d90e8eb6 100644 --- a/dongtai_web/threshold/config_setting.py +++ b/dongtai_web/threshold/config_setting.py @@ -37,6 +37,8 @@ from dongtai_web.utils import extend_schema_with_envcheck, get_response_serializer from dongtai_web.serializers.agent_config import AgentConfigSettingSerializer from rest_framework.serializers import ValidationError +from rest_framework.utils.serializer_helpers import ReturnDict +from typing import Dict _ResponseSerializer = get_response_serializer(status_msg_keypair=( ((201, _('The setting is complete')), ''), @@ -219,7 +221,8 @@ def get_targets(targets): return res -def get_data_from_dict_by_key(dic: dict, fields: Iterable) -> dict: +def get_data_from_dict_by_key(dic: ReturnDict | Dict, + fields: Iterable) -> Dict: return {i: dic[i] for i in fields} From 6a3f8ce8ec5b7713602d922e79729c1f5096b6ce Mon Sep 17 00:00:00 2001 From: bidaya0 Date: Wed, 21 Dec 2022 12:28:21 +0800 Subject: [PATCH 2/5] fix: add test case. --- dongtai_web/threshold/tests.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 dongtai_web/threshold/tests.py diff --git a/dongtai_web/threshold/tests.py b/dongtai_web/threshold/tests.py new file mode 100644 index 000000000..dc0a5d92f --- /dev/null +++ b/dongtai_web/threshold/tests.py @@ -0,0 +1,14 @@ +from django.test import TestCase +from dongtai_web.threshold.config_setting import get_data_from_dict_by_key +from rest_framework.utils.serializer_helpers import ReturnDict + +class TypingTestCase(TestCase): + + def test_typing_in_get_data_from_dict_by_key(): + get_data_from_dict_by_key({"213123132": "123123132"}, ("213123132", )) + get_data_from_dict_by_key( + AgentConfigSettingV2TargetSerializer(data={ + "target_type": 1, + "opt": 1, + "value": "21313" + }).data, ("target_type", "opt", "value")) From 38eaed78c617f454cd87c554049421e666e7c50f Mon Sep 17 00:00:00 2001 From: bidaya0 Date: Wed, 21 Dec 2022 13:27:09 +0800 Subject: [PATCH 3/5] fix: add test case. --- dongtai_web/threshold/tests.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dongtai_web/threshold/tests.py b/dongtai_web/threshold/tests.py index dc0a5d92f..83039902d 100644 --- a/dongtai_web/threshold/tests.py +++ b/dongtai_web/threshold/tests.py @@ -4,7 +4,7 @@ class TypingTestCase(TestCase): - def test_typing_in_get_data_from_dict_by_key(): + def test_typing_in_get_data_from_dict_by_key(self, ): get_data_from_dict_by_key({"213123132": "123123132"}, ("213123132", )) get_data_from_dict_by_key( AgentConfigSettingV2TargetSerializer(data={ From fb26e06c8c0708157c6d19b43e0bcbcc9227a17e Mon Sep 17 00:00:00 2001 From: bidaya0 Date: Wed, 21 Dec 2022 13:34:53 +0800 Subject: [PATCH 4/5] fix: add test case. --- dongtai_web/threshold/tests.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/dongtai_web/threshold/tests.py b/dongtai_web/threshold/tests.py index 83039902d..9281e9564 100644 --- a/dongtai_web/threshold/tests.py +++ b/dongtai_web/threshold/tests.py @@ -1,5 +1,8 @@ from django.test import TestCase -from dongtai_web.threshold.config_setting import get_data_from_dict_by_key +from dongtai_web.threshold.config_setting import ( + get_data_from_dict_by_key, + AgentConfigSettingV2TargetSerializer, +) from rest_framework.utils.serializer_helpers import ReturnDict class TypingTestCase(TestCase): From be3de82f6bc081191df6645364679423f58b7cf4 Mon Sep 17 00:00:00 2001 From: bidaya0 Date: Wed, 21 Dec 2022 14:47:25 +0800 Subject: [PATCH 5/5] fix: add test case. --- dongtai_web/threshold/tests.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/dongtai_web/threshold/tests.py b/dongtai_web/threshold/tests.py index 9281e9564..cda931244 100644 --- a/dongtai_web/threshold/tests.py +++ b/dongtai_web/threshold/tests.py @@ -9,9 +9,10 @@ class TypingTestCase(TestCase): def test_typing_in_get_data_from_dict_by_key(self, ): get_data_from_dict_by_key({"213123132": "123123132"}, ("213123132", )) - get_data_from_dict_by_key( - AgentConfigSettingV2TargetSerializer(data={ - "target_type": 1, - "opt": 1, - "value": "21313" - }).data, ("target_type", "opt", "value")) + ser = AgentConfigSettingV2TargetSerializer(data={ + "target_type": 1, + "opt": 1, + "value": "21313" + }) + ser.is_valid() + get_data_from_dict_by_key(ser.data, ("target_type", "opt", "value"))