def test_diff_paths_multiple_wildcard_path_req(): endpoint_id = "ENDPOINT-ID" mock_db = mock.create_autospec(agent_db.Database) req_handler = request_handler.UspRequestHandler(endpoint_id, mock_db) req_path = "Device.LocalAgent.Controller.*.MTP.*." param_path = "Device.LocalAgent.Controller.1.MTP.2.Protocol" diff_path = req_handler._diff_paths(req_path, param_path) assert diff_path == "1.MTP.2.Protocol"
def test_diff_paths_partial_path_req(): endpoint_id = "ENDPOINT-ID" mock_db = mock.create_autospec(agent_db.Database) req_handler = request_handler.UspRequestHandler(endpoint_id, mock_db) req_path = "Device.LocalAgent.Controller." param_path = "Device.LocalAgent.Controller.1.EndpointID" diff_path = req_handler._diff_paths(req_path, param_path) assert diff_path == "1.EndpointID"
def test_is_set_path_searching(): endpoint_id = "ENDPOINT-ID" mock_db = mock.create_autospec(agent_db.Database) req_handler = request_handler.UspRequestHandler(endpoint_id, mock_db) assert not req_handler._is_partial_path_searching( "Device.LocalAgent."), "Static Path Failure" assert not req_handler._is_partial_path_searching( "Device.Controller.1."), "Instance Number Addressing Path Failure" assert req_handler._is_partial_path_searching( "Device.Controller.*."), "Wildcard-based Searching Path Failure"
def __init__(self, dm_file, db_file, net_intf, cfg_file_name, debug=False): """Initialize the Abstract Agent""" self._service_map = {} self._periodic_handler_list = [] self._boot_notif_sender_list = [] self._cfg_file_name = cfg_file_name self._value_change_notif_poller = None self._logger = logging.getLogger(self.__class__.__name__) self._db = agent_db.Database(dm_file, db_file, net_intf) self._endpoint_id = self._db.get("Device.LocalAgent.EndpointID") self._load_services() self._msg_handler = request_handler.UspRequestHandler( self._endpoint_id, self._db, self._service_map, debug)
def test_get_affected_paths_for_get_three_layers(): endpoint_id = "ENDPOINT-ID" my_mock = dm_mock = mock.mock_open(read_data=get_dm_file_contents()) db_mock = mock.mock_open(read_data=get_db_file_contents()) my_mock.side_effect = [dm_mock.return_value, db_mock.return_value] partial_path = "Device.Services.HomeAutomation.*.Camera.*.Pic.*." with mock.patch("builtins.open", my_mock): my_db = agent_db.Database("mock_dm.json", "mock_db.json", "intf") req_handler = request_handler.UspRequestHandler(endpoint_id, my_db) affected_path_list = req_handler._get_affected_paths_for_get( partial_path) assert len(affected_path_list) == 5, "expecting 5, found " + str( len(affected_path_list))
def test_get_affected_paths_for_get_partial_path(): endpoint_id = "ENDPOINT-ID" my_mock = dm_mock = mock.mock_open(read_data=get_dm_file_contents()) db_mock = mock.mock_open(read_data=get_db_file_contents()) my_mock.side_effect = [dm_mock.return_value, db_mock.return_value] partial_path = "Device.Subscription." with mock.patch("builtins.open", my_mock): my_db = agent_db.Database("mock_dm.json", "mock_db.json", "intf") req_handler = request_handler.UspRequestHandler(endpoint_id, my_db) affected_path_list = req_handler._get_affected_paths_for_get( partial_path) assert len(affected_path_list) == 1, "expecting 1, found " + str( len(affected_path_list)) assert affected_path_list[0] == "Device.Subscription."