Best Python code snippet using localstack_python
test_control_node_repository.py
Source:test_control_node_repository.py
1import unittest2from mock import MagicMock, call, patch3from bounded_contexts.central_console.domain_services import control_node_repository4from bounded_contexts.central_console.domain_services.abstract_contact_person_repository import \5 AbstractContactPersonRepository6from bounded_contexts.central_console.domain_services.abstract_platform_repository import AbstractPlatformRepository7from bounded_contexts.central_console.domain_services.abstract_server_repository import AbstractServerRepository8from bounded_contexts.central_console.domain_services.abstract_system_repository import AbstractSystemRepository9from bounded_contexts.central_console.domain_services.control_node_repository import CONFIG_SERVER_ID, CONFIG_VERSION10from bounded_contexts.central_console.models.contact_person import ContactPerson11from bounded_contexts.central_console.models.control_node import ControlNode12from bounded_contexts.central_console.models.platform import Platform13from bounded_contexts.central_console.models.server import Server14from bounded_contexts.central_console.models.system import System15from shared_kernel.config.domain_services.abstract_config_repository import AbstractConfigRepository16from shared_kernel.config.models.config import Config17from unit_tests.base_test_case import BaseTestCase18class TestControlNodeRepository(BaseTestCase):19 def setUp(self):20 self.conf_repo = MagicMock(spec=AbstractConfigRepository)21 self.system_repo = MagicMock(spec=AbstractSystemRepository)22 self.server_repo = MagicMock(spec=AbstractServerRepository)23 self.contact_repo = MagicMock(spec=AbstractContactPersonRepository)24 self.platform_repo = MagicMock(spec=AbstractPlatformRepository)25 self.repo = control_node_repository.ControlNodeRepository(26 ControlNode,27 self.conf_repo,28 self.system_repo,29 self.server_repo,30 self.contact_repo,31 self.platform_repo32 )33 @patch.object(control_node_repository, 'get_bytes_from_uuid', autospec=True)34 def test_get_control_node_with_public_ip(self, convert_id_mock):35 server_id_config = MagicMock(spec=Config)36 softversion_config = MagicMock(spec=Config)37 self.system_repo.get_system.return_value = MagicMock(spec=System)38 self.server_repo.get_server.return_value = MagicMock(spec=Server)39 self.conf_repo.get_config.side_effect = [server_id_config, softversion_config]40 self.contact_repo.get_contact_person.return_value = MagicMock(spec=ContactPerson)41 self.set_named_tuple_mock_bool_context_value(self.contact_repo.get_contact_person.return_value, True)42 self.platform_repo.get_platform.return_value = MagicMock(spec=Platform)43 self.set_named_tuple_mock_bool_context_value(self.platform_repo.get_platform.return_value, True)44 self.platform_repo.get_platform.return_value.public_ip = '10.0.0.0'45 actual_node = self.repo.get_control_node()46 self.conf_repo.get_config.assert_has_calls([47 call(CONFIG_SERVER_ID),48 call(CONFIG_VERSION)49 ])50 self.system_repo.get_system.assert_called_once_with()51 self.server_repo.get_server.assert_called_once_with(convert_id_mock.return_value)52 self.contact_repo.get_contact_person.assert_called_once_with()53 self.platform_repo.get_platform.assert_called_once_with(self.system_repo.get_system.return_value.admin_ip)54 self.assertEqual(actual_node.node_id, self.system_repo.get_system.return_value.id)55 self.assertEqual(actual_node.name, self.system_repo.get_system.return_value.name)56 self.assertEqual(actual_node.description, self.server_repo.get_server.return_value.descr)57 self.assertEqual(actual_node.platform, self.platform_repo.get_platform.return_value.name)58 self.assertEqual(actual_node.appliance_type, self.platform_repo.get_platform.return_value.appliance_type)59 self.assertEqual(actual_node.software_version, softversion_config.value)60 self.assertEqual(61 actual_node.intelligence_version,62 self.platform_repo.get_platform.return_value.threat_intelligence_version63 )64 self.assertEqual(actual_node.contact_email, self.contact_repo.get_contact_person.return_value.email)65 self.assertEqual(actual_node.contact_name, self.contact_repo.get_contact_person.return_value.name)66 self.assertEqual(actual_node.admin_ip_address, self.platform_repo.get_platform.return_value.public_ip)67 self.assertEqual(actual_node.vpn_ip_address, self.system_repo.get_system.return_value.vpn_ip)68 @patch.object(control_node_repository, 'get_bytes_from_uuid', autospec=True)69 def test_get_control_node_with_admin_ip(self, convert_id_mock):70 server_id_config = MagicMock(spec=Config)71 softversion_config = MagicMock(spec=Config)72 self.system_repo.get_system.return_value = MagicMock(spec=System)73 self.system_repo.get_system.return_value.admin_ip = '192.168.0.1'74 self.system_repo.get_system.return_value.ha_ip = ''75 self.server_repo.get_server.return_value = MagicMock(spec=Server)76 self.conf_repo.get_config.side_effect = [server_id_config, softversion_config]77 self.contact_repo.get_contact_person.return_value = MagicMock(spec=ContactPerson)78 self.contact_repo.get_contact_person.return_value.__len__ = MagicMock(return_value=1)79 self.platform_repo.get_platform.return_value = MagicMock(spec=Platform)80 self.set_named_tuple_mock_bool_context_value(self.platform_repo.get_platform.return_value, True)81 self.platform_repo.get_platform.return_value.public_ip = None82 actual_node = self.repo.get_control_node()83 self.conf_repo.get_config.assert_has_calls([84 call(CONFIG_SERVER_ID),85 call(CONFIG_VERSION)86 ])87 self.system_repo.get_system.assert_called_once_with()88 self.server_repo.get_server.assert_called_once_with(convert_id_mock.return_value)89 self.contact_repo.get_contact_person.assert_called_once_with()90 self.platform_repo.get_platform.assert_called_once_with(self.system_repo.get_system.return_value.admin_ip)91 self.assertEqual(actual_node.node_id, self.system_repo.get_system.return_value.id)92 self.assertEqual(actual_node.name, self.system_repo.get_system.return_value.name)93 self.assertEqual(actual_node.description, self.server_repo.get_server.return_value.descr)94 self.assertEqual(actual_node.platform, self.platform_repo.get_platform.return_value.name)95 self.assertEqual(actual_node.appliance_type, self.platform_repo.get_platform.return_value.appliance_type)96 self.assertEqual(actual_node.software_version, softversion_config.value)97 self.assertEqual(98 actual_node.intelligence_version,99 self.platform_repo.get_platform.return_value.threat_intelligence_version100 )101 self.assertEqual(actual_node.contact_email, self.contact_repo.get_contact_person.return_value.email)102 self.assertEqual(actual_node.contact_name, self.contact_repo.get_contact_person.return_value.name)103 self.assertEqual(actual_node.admin_ip_address, self.system_repo.get_system.return_value.admin_ip)104 self.assertEqual(actual_node.vpn_ip_address, self.system_repo.get_system.return_value.vpn_ip)105 @patch.object(control_node_repository, 'get_bytes_from_uuid', autospec=True)106 def test_get_control_node_with_ha_ip(self, convert_id_mock):107 server_id_config = MagicMock(spec=Config)108 softversion_config = MagicMock(spec=Config)109 self.system_repo.get_system.return_value = MagicMock(spec=System)110 self.system_repo.get_system.return_value.admin_ip = '192.168.0.1'111 self.system_repo.get_system.return_value.ha_ip = '192.168.0.10'112 self.server_repo.get_server.return_value = MagicMock(spec=Server)113 self.conf_repo.get_config.side_effect = [server_id_config, softversion_config]114 self.contact_repo.get_contact_person.return_value = MagicMock(spec=ContactPerson)115 self.set_named_tuple_mock_bool_context_value(self.contact_repo.get_contact_person.return_value, True)116 self.platform_repo.get_platform.return_value = MagicMock(spec=Platform)117 self.set_named_tuple_mock_bool_context_value(self.platform_repo.get_platform.return_value, True)118 self.platform_repo.get_platform.return_value.public_ip = None119 actual_node = self.repo.get_control_node()120 self.conf_repo.get_config.assert_has_calls([121 call(CONFIG_SERVER_ID),122 call(CONFIG_VERSION)123 ])124 self.system_repo.get_system.assert_called_once_with()125 self.server_repo.get_server.assert_called_once_with(convert_id_mock.return_value)126 self.contact_repo.get_contact_person.assert_called_once_with()127 self.platform_repo.get_platform.assert_called_once_with(self.system_repo.get_system.return_value.admin_ip)128 self.assertEqual(actual_node.node_id, self.system_repo.get_system.return_value.id)129 self.assertEqual(actual_node.name, self.system_repo.get_system.return_value.name)130 self.assertEqual(actual_node.description, self.server_repo.get_server.return_value.descr)131 self.assertEqual(actual_node.platform, self.platform_repo.get_platform.return_value.name)132 self.assertEqual(actual_node.appliance_type, self.platform_repo.get_platform.return_value.appliance_type)133 self.assertEqual(actual_node.software_version, softversion_config.value)134 self.assertEqual(135 actual_node.intelligence_version,136 self.platform_repo.get_platform.return_value.threat_intelligence_version137 )138 self.assertEqual(actual_node.contact_email, self.contact_repo.get_contact_person.return_value.email)139 self.assertEqual(actual_node.contact_name, self.contact_repo.get_contact_person.return_value.name)140 self.assertEqual(actual_node.admin_ip_address, self.system_repo.get_system.return_value.ha_ip)141 self.assertEqual(actual_node.vpn_ip_address, self.system_repo.get_system.return_value.vpn_ip)142 @patch.object(control_node_repository, 'get_bytes_from_uuid', autospec=True)143 def test_get_control_node_no_contact_person(self, convert_id_mock):144 server_id_config = MagicMock(spec=Config)145 softversion_config = MagicMock(spec=Config)146 self.system_repo.get_system.return_value = MagicMock(spec=System)147 self.server_repo.get_server.return_value = MagicMock(spec=Server)148 self.conf_repo.get_config.side_effect = [server_id_config, softversion_config]149 self.contact_repo.get_contact_person.return_value = None150 self.platform_repo.get_platform.return_value = MagicMock(spec=Platform)151 self.set_named_tuple_mock_bool_context_value(self.platform_repo.get_platform.return_value, True)152 self.platform_repo.get_platform.return_value.public_ip = '10.0.0.1'153 actual_node = self.repo.get_control_node()154 self.assertEqual(actual_node.node_id, self.system_repo.get_system.return_value.id)155 self.assertEqual(actual_node.name, self.system_repo.get_system.return_value.name)156 self.assertEqual(actual_node.description, self.server_repo.get_server.return_value.descr)157 self.assertEqual(actual_node.platform, self.platform_repo.get_platform.return_value.name)158 self.assertEqual(actual_node.appliance_type, self.platform_repo.get_platform.return_value.appliance_type)159 self.assertEqual(actual_node.software_version, softversion_config.value)160 self.assertEqual(161 actual_node.intelligence_version,162 self.platform_repo.get_platform.return_value.threat_intelligence_version163 )164 self.assertEqual(actual_node.contact_email, None)165 self.assertEqual(actual_node.contact_name, None)166 self.assertEqual(actual_node.admin_ip_address, self.platform_repo.get_platform.return_value.public_ip)167 self.assertEqual(actual_node.vpn_ip_address, self.system_repo.get_system.return_value.vpn_ip)168 @patch.object(control_node_repository, 'get_bytes_from_uuid', autospec=True)169 def test_get_control_node_no_platform_data(self, convert_id_mock):170 server_id_config = MagicMock(spec=Config)171 softversion_config = MagicMock(spec=Config)172 self.system_repo.get_system.return_value = MagicMock(spec=System)173 self.system_repo.get_system.return_value.ha_ip = ''174 self.server_repo.get_server.return_value = MagicMock(spec=Server)175 self.conf_repo.get_config.side_effect = [server_id_config, softversion_config]176 self.contact_repo.get_contact_person.return_value = MagicMock(spec=ContactPerson)177 self.set_named_tuple_mock_bool_context_value(self.contact_repo.get_contact_person.return_value, True)178 self.platform_repo.get_platform.return_value = None179 actual_node = self.repo.get_control_node()180 self.assertEqual(actual_node.node_id, self.system_repo.get_system.return_value.id)181 self.assertEqual(actual_node.name, self.system_repo.get_system.return_value.name)182 self.assertEqual(actual_node.description, self.server_repo.get_server.return_value.descr)183 self.assertEqual(actual_node.platform, None)184 self.assertEqual(actual_node.appliance_type, None)185 self.assertEqual(actual_node.software_version, softversion_config.value)186 self.assertEqual(actual_node.intelligence_version, None)187 self.assertEqual(actual_node.contact_email, self.contact_repo.get_contact_person.return_value.email)188 self.assertEqual(actual_node.contact_name, self.contact_repo.get_contact_person.return_value.name)189 self.assertEqual(actual_node.admin_ip_address, self.system_repo.get_system.return_value.admin_ip)190 self.assertEqual(actual_node.vpn_ip_address, self.system_repo.get_system.return_value.vpn_ip)191if __name__ == '__main__':...
client_system_api.py
Source:client_system_api.py
...8 è·åèæ¬è¿è¡çå¹³å°9 1.18 æ°å¢ è·åèæ¬è¿è¡çå¹³å°10 :return: int 0ï¼Windowï¼1ï¼IOSï¼2ï¼Androidï¼-1ï¼å
¶ä»11 """12 return extra_client_api.get_system(ModName, ModClientSystemName).GetPlatform()13def broadcast_event(event_name, event_data):14 # type: (str, dict) -> None15 """16 æ¬å°å¹¿æäºä»¶ï¼å®¢æ·ç«¯system广æçäºä»¶ä»
客æ·ç«¯systemè½çå¬ã17 :param event_name: str äºä»¶å18 :param event_data: dict äºä»¶åæ°19 :return:20 """21 warnings.warn("1.20 BroadcastEventç®åææ¶æ æ³ä½¿ç¨ï¼éè¦éè¿æå¡ç«¯BroadcastToAllClient广æ", DeprecationWarning)22 extra_client_api.get_system(ModName, ModClientSystemName).BroadcastEvent(event_name, event_data)23def create_event_data():24 # type: () -> dict25 """26 å建èªå®ä¹äºä»¶çæ°æ®ï¼eventDataç¨äºåéäºä»¶ãå建çeventDataå¯ä»¥ç解为ä¸ä¸ªdictï¼å¯ä»¥åµå¥èµå¼dict,listååºæ¬æ°æ®ç±»åï¼ä½ä¸æ¯ætuple27 :return: dict äºä»¶æ°æ®28 """29 warnings.warn("1.20 ç®åCreateEventDataææ¶æ²¡æç¹æ®åè½ï¼å¯ä»¥ä½¿ç¨{}代æ¿", DeprecationWarning)30 return extra_client_api.get_system(ModName, ModClientSystemName).CreateEventData()31def define_event(event_name):32 # type: (str) -> None33 """34 å®ä¹èªå®ä¹äºä»¶35 :param event_name: str äºä»¶å36 :return:37 """38 extra_client_api.get_system(ModName, ModClientSystemName).DefineEvent(event_name)39def listen_for_event(namespace, system_name, event_name, instance, func, priority=0):40 """41 注åçå¬æ个系ç»æåºçäºä»¶ãè¥çå¬å¼æäºä»¶æ¶ï¼namespaceåsystemNameåå«ä¸ºGetEngineNamespace()åGetEngineSystemName()42 :param namespace: str æçå¬äºä»¶çæ¥æºç³»ç»çnamespace43 :param system_name: str æçå¬äºä»¶çæ¥æºç³»ç»çsystemName44 :param event_name: str äºä»¶å45 :param instance: instance åè°å½æ°æå±çç±»çå®ä¾46 :param func: function åè°å½æ°47 :param priority: int è¿ä¸ªåè°å½æ°çä¼å
级ãé»è®¤å¼ä¸º0ï¼è¿ä¸ªæ°å¼è¶å¤§è¡¨ç¤ºè¢«æ§è¡çä¼å
级è¶é«ï¼æé«ä¸º1048 :return:49 """50 extra_client_api.get_system(ModName, ModClientSystemName51 ).ListenForEvent(namespace, system_name, event_name, instance, func, priority)52def notify_to_server(event_name, event_data):53 # type: (str, dict) -> None54 """55 客æ·ç«¯åéäºä»¶å°æå¡å¨56 :param event_name: str äºä»¶å57 :param event_data: dict äºä»¶åæ°ï¼ä¸è¬ç¨CreateEventDataçè¿åå¼58 :return:59 """60 extra_client_api.get_system(ModName, ModClientSystemName).NotifyToServer(event_name, event_data)61def un_define_event(event_name):62 # type: (str) -> None63 """64 åæ¶èªå®ä¹äºä»¶65 :param event_name: str äºä»¶å66 :return:67 """68 extra_client_api.get_system(ModName, ModClientSystemName).UnDefineEvent(event_name)69def un_listen_all_events():70 """71 å注åçå¬æ个系ç»æåºçææäºä»¶ï¼å³ä¸åçå¬ã72 :return:73 """74 extra_client_api.get_system(ModName, ModClientSystemName).UnListenAllEvents()75def un_listen_for_event(namespace, system_name, event_name, instance, func, priority=0):76 """77 å注åçå¬æ个系ç»æåºçäºä»¶ï¼å³ä¸åçå¬ãè¥æ¯å¼æäºä»¶ï¼ånamespaceåsystemNameåå«ä¸ºGetEngineNamespace()åGetEngineSystemName()ãä¸ListenForEvent对åºã78 :param namespace: str æçå¬äºä»¶çæ¥æºç³»ç»çnamespace79 :param system_name: str æçå¬äºä»¶çæ¥æºç³»ç»çsystemName80 :param event_name: str äºä»¶å81 :param instance: instance åè°å½æ°æå±çç±»çå®ä¾82 :param func: function åè°å½æ°83 :param priority: int è¿ä¸ªåè°å½æ°çä¼å
级ãé»è®¤å¼ä¸º0ï¼è¿ä¸ªæ°å¼è¶å¤§è¡¨ç¤ºè¢«æ§è¡çä¼å
级è¶é«84 :return:85 """86 extra_client_api.get_system(ModName, ModClientSystemName87 ).UnListenForEvent(namespace, system_name, event_name, instance, func, priority)88def destroy_entity(entity_id):89 # type: (str) -> bool90 """91 å®ä½éæ¯æ¥å£92 :param entity_id: str éæ¯çå®ä½ID93 :return: bool æ¯å¦éæ¯æå94 """95 return extra_client_api.get_system(ModName, ModClientSystemName).DestroyEntity(entity_id)96def create_engine_effect(path, bind_entity, ani_name):97 # type: (str, str, str) -> int98 """99 ç¨äºå建模åææ¥ç¹æï¼å
·ä½åè§å建ç¹æé¨åå
容ã100 :param path: str ç¹æèµæºè·¯å¾ï¼éè¦å ä¸åç¼åï¼ä¸è¬æ¯jsonï¼101 :param bind_entity: str ç»å®å®ä½çId102 :param ani_name: str éæ©ä½¿ç¨åªä¸ªæ¨¡åå¨ä½çç¹æ103 :return: intæNone effectEntityIdæè
None104 """105 return extra_client_api.get_system(ModName, ModClientSystemName).CreateEngineEffect(path, bind_entity, ani_name)106def create_engine_particle(path, pos=(0, 0, 0)):107 # type: (str, tuple) -> int108 """109 ç¨äºå建ç²åç¹æï¼å
·ä½åè§å建ç¹æé¨åå
容110 :param path: str ç¹æèµæºè·¯å¾ï¼éè¦å ä¸åç¼åï¼ä¸è¬æ¯jsonï¼111 :param pos: tuple (float,float,float)å建ä½ç½®åæ 112 :return: intæNone particleEntityIdæè
None113 """114 return extra_client_api.get_system(ModName, ModClientSystemName).CreateEngineParticle(path, pos)115def create_engine_sfx(path, pos=None, rot=None, scale=None):116 # type: (str, tuple, tuple, float) -> int117 """118 ç¨äºå建åºå帧ç¹æï¼å
·ä½åè§å建ç¹æé¨åå
容119 :param path: str ç¹æèµæºè·¯å¾ï¼ä¸ç¨åç¼å120 :param pos: tuple (float,float,float)å建ä½ç½®ï¼å¯é121 :param rot: tuple (float,float)è§åº¦ï¼å¯é122 :param scale: float 缩æ¾ç³»æ°ï¼å¯é123 :return: intæNone frameEntityIdæè
None124 """125 return extra_client_api.get_system(ModName, ModClientSystemName).CreateEngineSfx(path, pos, rot, scale)126def create_engine_sfx_from_editor(path, pos=None, rot=None, scale=None):127 # type: (str, tuple, tuple, float) -> int128 """129 æ使ç¨èµæºå
ä¸effects/xxx.jsonï¼æç
§ç¼è¾å¨ä¸ç¼è¾å¥½çåæ°å建åºå帧ãæ¯æç¯ç¶åºå帧130 :param path: str ç¹æèµæºè·¯å¾ï¼ä¸ç¨åç¼å131 :param pos: tuple (float,float,float)å建ä½ç½®ï¼å¯é132 :param rot: tuple (float,float)è§åº¦ï¼å¯é133 :param scale: float 缩æ¾ç³»æ°ï¼å¯é134 :return: intæNone frameEntityIdæè
None135 """136 return extra_client_api.get_system(ModName, ModClientSystemName).CreateEngineSfxFromEditor(path, pos, rot, scale)137def create_component(entity_id, namespace, name):138 """139 ç»å®ä½å建ç»ä»¶ï¼ä¸GetComponent类似ï¼å¦æå·²ç»å建ä¼èªå¨ç´æ¥Get140 :param entity_id: str 该ç»ä»¶å±ä¸»çå®ä½id141 :param namespace: str ç»ä»¶çå½å空é´ï¼registerComponentçnamespace142 :param name: str ç»ä»¶çåå143 :return: instance ç»ä»¶å®ä¾144 """145 return clientApi.CreateComponent(entity_id, namespace, name)146def get_component(entity_id, namespace, name):147 """148 è·åå®ä½çç»ä»¶ãä¸è¬ç¨æ¥å¤ææ个ç»ä»¶æ¯å¦å建è¿ï¼å
¶ä»æ
åµè¯·ä½¿ç¨CreateComponent149 :param entity_id: str 该ç»ä»¶å±ä¸»çå®ä½id150 :param namespace: str ç»ä»¶çå½å空é´ï¼registerComponentçnamespace...
configInfo.py
Source:configInfo.py
2å®ä¹é
置类ï¼è¯»åé
ç½®æ件ä¸çé
置信æ¯å
æ¬[HTTP][USER][EMAIL][LOG]3"""4from read_config import get_system, get_email, get_log5class SystemConfig:6 super_name = get_system('super_name')7 super_pwd = get_system('super_pwd')8 username = get_system('username')9 password = get_system('password')10 pass_rate = float(get_system('pass_rate'))11 system_name = get_system('system_name')12class EmailConfig:13 on_off = get_email('on_off')14 title = get_email('title')15 message = get_email('message')16 password = get_email('password')17 receiver = get_email('receiver')18 server = get_email('server')19 sender = get_email('sender')20class LogConfig:21 file_name = get_log('file_name')22 backup = int(get_log('backup'))23 console_level = get_log('console_level')...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!