Пример #1
0
def test_this():
    import os
    from test_bl.test_sonata_plugin.structs_sonata import sonata_msg
    from test_bl.test_bl_tools import logging_tools
    """
    BASIC TEST BASIC CONFIG
    """
    '''
    Read test data from json
    '''
    '''And where we are'''
    module_abs_path = os.path.abspath(os.path.dirname(__file__))
    path_to_data = "..\\test_sonata_plugin\\resources_sonata\\sonata_test_data.json"
    def_mgs_location = os.path.join(module_abs_path, path_to_data)
    path_to_log_conf = "..\\test_bl_configs\\logging_conf.json"

    lt = logging_tools.LoggingTools(path_to_json=path_to_log_conf)
    logger = lt.get_logger(__name__)

    rd = ReadData(def_mgs_location, test_data_type=test_data_type.json)

    sonata_msg_struct = sonata_msg.SonataMsg(logging_tools=lt)
    rd.read_json_to_map()
    testsuite_data = rd.get_testsuite_data(msg_struct=sonata_msg_struct)
    test_ids = [
        "test_sonata_messages01", "test_sonata_messages05",
        "test_sonata_messages02", "test_sonata_messages07",
        "test_sonata_messages05"
    ]
    for id in test_ids:
        test_messages = rd.get_testcase_messages(id)
        test_data = rd.get_testcase_data(id)
    logger.info("test messages collected: " + str(test_messages) + "\n")
    logger.info("test data collected: " + str(test_data) + "\n")
    logger.info("End of test read data_from")
Пример #2
0
def get_test_messages(test_case_id):
    import os
    from test_bl.test_sonata_plugin.structs_sonata import sonata_msg
    from test_bl.test_bl_tools import read_test_data
    """
    BASIC TEST BASIC CONFIG
    """
    logger = logging.getLogger(__name__)
    '''here we are'''
    module_abs_path = os.path.abspath(os.path.dirname(__file__))
    '''
    Read test data from json    '''

    # path_to_data = "..\\test_sonata_plugin\\resources_sonata\\sonata_test_data.json"
    # path_to_data = "..\\test_sonata_plugin\\resources_sonata\\sonata_test_data_gen.json"
    # path_to_data = "..\\test_sonata_plugin\\resources_sonata\\failig_test_data.json"
    # path_to_data = "..\\test_sonata_plugin\\resources_sonata\\sonata_test_data_gen_over_500.json"
    path_to_data = "..\\test_sonata_plugin\\resources_sonata\\sonata_test_data_gen500.json"
    # path_to_data = "..\\test_sonata_plugin\\resources_sonata\\sonata_test_data_vel_knots presision.json"
    # path_to_data = "D:\\data\\python\\projects\\bl_frame_work\\bl_frame_work\\test_bl\\test_sonata_plugin\\resources_sonata\sonata_test_data.json"
    # path_to_data = "C:\\data\\kronshtadt\\QA\\BL\\AutomationFrameworkDesign\\bl_frame_work\\test_bl\\test_sonata_plugin\\resources_sonata\\sonata_test_data.json"

    path_to_data = os.path.join(module_abs_path, path_to_data)
    rd = read_test_data.ReadData(
        path_to_data, test_data_type=read_test_data.test_data_type.json)
    sonata_msg_struct = sonata_msg.SonataMsg()
    tests_data = rd.get_testsuite_data(msg_struct=sonata_msg_struct)
    # test_ids = ["test_sonata_messages01", "test_sonata_messages05", "test_sonata_messages02", "test_sonata_messages07","test_sonata_messages05"]
    # test_ids = ["test_sonata_messages05","test_sonata_messages06","test_sonata_messages07"]

    test_messages_list = rd.get_testcase_messages(test_case_id=test_case_id)
    test_data_list = rd.get_testcase_data(test_case_id=test_case_id)
    result = (test_messages_list, test_data_list)
    return result
Пример #3
0
    def load_test_messages(self):
        """
        self.messages_type,
        self.messages_src,
        self.messages_dir_json

        Here we want to pick messages for the test selectively.
            1) In the simplest case by loading them from the text file as it was done for the case of prototype sending UDP
            2) In more elaborate cases use some utility classes to load data_from from json into proper structure
            for later usage it in the test
        :return:
        """
        '''
        Store messages to be sent out
        '''
        udp_msgs = []
        '''
        Clean up ultimate receiver of 
        actual, properly formatted 
        TEST messages
        '''
        self.msgs_to_send = None
        '''
        Clean up DATA STORAGE used for 
        DATA FIELDS USED to CONSTRUCT 
        actual, properly formatted 
        TEST messages
        in
        ultimate receiver above
        '''
        self.reset_test_messages_to_sent()

        if self.messages_src == self.messages_src_txt:
            if self.messages_type == self.messages_type_sonata:
                '''
                TODO:
                Better more flexible mechanism
                for data storage 
                should be used.
                Ideally look up 

                FOR NOW
                an assumption is that 
                NEEDED granularity for message
                content control
                is one message
                because messages can be 
                diverse in some cases

                So HERE (Sonata) in OTHER cases
                other message types are 
                constructed per 
                individual data for that particular message
                pattern provided from some source                
                '''

                s_msg = sonata_msg.SonataMsg(self)
                s_msg.set_sonata_values_map()
                msg = s_msg.get_sonata_msg()

                s_msg_range = [1, 2, 3]

                for i in s_msg_range:
                    try:
                        udp_msgs.append(''.join([msg, '\n\n']))
                    except (OSError, IOError) as e:
                        print(str(e))
                self.msgs_to_send = udp_msgs
                return
            else:
                '''            
                Read stuff from the file directly
                '''
                try:
                    # with open(filename, 'r') as fin:
                    with open(self.message_dir, 'r') as fin:

                        for line in fin:
                            start = line.find('$')
                            msg = (line[start:]
                                   if start != -1 else line).strip()
                            '''do not get this messaging yet '''
                            # msg = filter_message(msg, msg_filter)
                            if not msg:
                                continue
                            udp_msgs.append(''.join([msg, '\n\n']))
                except (OSError, IOError) as e:
                    print(str(e))
                self.msgs_to_send = udp_msgs
                return

        elif self.messages_src == self.messages_src_json:
            '''
            First load RAW data from JSON 
            for current test 
            which name is configured            
            in
            self.curr_test VAR           
            '''
            '''
            Get RAW test data 
            '''
            self.data_reader = read_test_data.ReadData(self.messages_dir_json)
            self.data_reader.read_json_to_map()
            self.raw_test_data = self.data_reader.final_map
            self.subdict_kwords = [self.curr_test]
            self.curr_test_data = self.subdict(self.subdict_kwords)
            '''------------------------------------------------------------------------------------------------------'''

            if self.messages_type == self.messages_type_sonata:
                for key_sonata_tcase in self.curr_test_data.keys():
                    sonata_msgs = self.curr_test_data.get(key_sonata_tcase)

                    for key_sonata_msg in sonata_msgs:
                        self.sonata_msg = sonata_msgs.get(key_sonata_msg)
                        s_msg = sonata_msg.SonataMsg(self)
                        s_msg.set_sonata_values_from_json_map()
                        msg = s_msg.get_sonata_msg()
                        udp_msgs.append(msg)
            '''
            MAKE MESSAGES constructed from 
            JSON AVAILABLE TO 
            sender 
            through config file
            '''
            self.conf.msgs_to_send = udp_msgs
            #self.msgs_to_send = udp_msgs
            return
Пример #4
0
 def __init__(self):
     """
     """
     '''-----------------------------------------------------------------------------------------------------------
     SETUP
     '''
     '''
     CURRENT LOCATION
     '''
     self.curr_dir_name = os.path.dirname(__file__)
     self.module_abs_path = os.path.abspath(os.path.dirname(__file__))
     #self.path_to_proj=re.findall(r".*\\test_bl",self.module_abs_path)
     '''-----------------------------------------------------------------------------------------------------------
     GET GENERAL PREFERENCES
     '''
     self.g_prefs = config_test_env.ConfigTestEnv()
     '''
     GET TEST SUITE PREFERENCES
     '''
     self.s_prefs = config_sonata_suite.ConfigSonataSuite()
     self.g_prefs.set_suite_conf(self.s_prefs.get_sonata_configuration())
     '''-----------------------------------------------------------------------------------------------------------
     CONFIG LOGGING
     '''
     path_to_logging_conf = self.g_prefs.get_tests_logging_config()
     '''
     Logging for all classes used here 
     is configured from the config file in
     logging tools class.
     All configuration that pertains to individual modules 
     is there in the config
     '''
     self._config_loggers(path_to_logging_conf)
     self.logger = logging.getLogger(__name__)
     '''-----------------------------------------------------------------------------------------------------------
     SEND RECEIVE 
     '''
     self.positive_test_kword = "pass"
     self.negative_test_kword = "fail"
     self.sr = send_receive.SendReceive(q_based=True)
     '''
     UDP SENDER (process based)
     '''
     self.udp_snd_name = self.sr.set_udp_sender(
         ip_to=self.g_prefs.get_udp_ip_to(),
         port_to=self.g_prefs.get_udp_port_to())
     '''
     UDP SERVER (thread based)
     '''
     self.udp_srv_name = self.sr.set_udp_server(
         ip_address=self.g_prefs.get_udp_ip_from(),
         port=self.g_prefs.get_udp_port_from())
     self.sr.start_udp_server(self.udp_srv_name)
     '''-----------------------------------------------------------------------------------------------------------
     DATA PROCESSING
     '''
     self.test_type_k_word = "test_type"
     self.test_skip_k_word = "skip"
     '''
     TEST SUITE TEST DATA
     path_to_data is module specific
     '''
     self.path_to_test_data = self.s_prefs.get_path_to_sonata_data(
         project_path=self.g_prefs.get_proj_dir_path())
     '''
     TEST DATA READER  
     '''
     self.rd = read_test_data.ReadData(
         data_location=self.path_to_test_data,
         test_data_type=read_test_data.test_data_type.json)
     '''
     TARGET MESSAGE STRUCTURE (Sonata)
     '''
     self.sonata_msg_struct = sonata_msg.SonataMsg()
     '''
     GET TEST DATA FOR MANIPULATIONS
     '''
     self._test_suite_test_data = self.rd.get_testsuite_data(
         self.sonata_msg_struct)
     '''------------------------------------------------------------------------------------------------------------
     TESTS TO EXCLUDE
     '''
     self.tests_to_exclude = self._set_excluded_tests()
     '''
     GET TEST CASES NAMES
     '''
     self._test_suite_test_names = self.rd.get_test_names()
     '''
     PARSER (module specific) 
     used by processing class       
     '''
     self._s_parser = sonata_test_parser.SonataTestParser()
     '''
     RECEIVED TEST DATA PROCESSING
     processing class doing parsing of the received data and comparison with the data been sent out
     '''
     self.proc_data = process_received_data.ProcessReceivedData()
     '''------------------------------------------------------------------------------------------------------------
     COMPARISON (SENT/RECEIVED)
     stuctures to hold sent and received data 
     for further comparison
     '''
     self.test_suite_parsed_data = {}
     self.test_suite_compared_data = None
     self.test_suite_sent_data = {}
     '''------------------------------------------------------------------------------------------------------------
     SETUP VIRTUAL ENV FOR TESTS
     '''
     self.ext_scripts = external_scripts.ExtScripts()
     self.setup_external_scripts()
     '''------------------------------------------------------------------------------------------------------------
Пример #5
0
    def load_test_messages(self):
        """
        self.messages_type,
        self.messages_src,
        self.messages_dir_json

        Here we want to pick messages for the test selectively.
            1) In the simplest case by loading them from the text file as it was done for the case of prototype sending UDP
            2) In more elaborate cases use some utility classes to load data_from from json into proper structure
            for later usage it in the test
        :return:
        """
        '''
        Store messages to be sent out
        '''
        udp_msgs = []
        '''
        Clean up ultimate receiver of 
        actual, properly formatted 
        TEST messages
        '''
        self.msgs_to_send = None
        '''
        Clean up DATA STORAGE used for 
        DATA FIELDS USED to CONSTRUCT 
        actual, properly formatted 
        TEST messages
        in
        ultimate receiver above
        '''
        self.reset_test_messages_to_sent()

        if self.messages_src == "TXT":
            if self.messages_type == "SONATA":
                '''
                TODO:
                Better more flexible mechanism
                for data storage 
                should be used.
                Ideally look up 
                
                FOR NOW
                an assumption is that 
                NEEDED granularity for message
                content control
                is one message
                because messages can be 
                diverse in some cases
                
                So HERE (Sonata) in OTHER cases
                other message types are 
                constructed per 
                individual data for that particular message
                pattern provided from some source                
                '''

                s_msg = sonata_msg.SonataMsg(self)
                s_msg.set_sonata_values_map()
                msg = s_msg.get_msg()

                s_msg_range = [1, 2, 3]

                for i in s_msg_range:
                    try:
                        udp_msgs.append(''.join([msg, '\n\n']))
                    except (OSError, IOError) as e:
                        print(str(e))
                self.msgs_to_send = udp_msgs
                return
            else:
                '''            
                Read stuff from the file directly
                '''
                try:
                    # with open(filename, 'r') as fin:
                    with open(self.message_dir, 'r') as fin:

                        for line in fin:
                            start = line.find('$')
                            msg = (line[start:]
                                   if start != -1 else line).strip()
                            '''do not get this messaging yet '''
                            # msg = filter_message(msg, msg_filter)
                            if not msg:
                                continue
                            udp_msgs.append(''.join([msg, '\n\n']))
                except (OSError, IOError) as e:
                    print(str(e))
                self.msgs_to_send = udp_msgs
                return

        elif self.messages_src == "JSON":
            '''
            Read stuff from the JSON config.
            TODO: the JSON reading part 
            For now 5.06.18
            just get a couple of Sonata messages
            for 
            testing purposes
            '''
            if self.messages_type == "SONATA":
                s_msg = sonata_msg.SonataMsg(self)
                s_msg.set_sonata_values_map()
                msg = s_msg.get_msg()
                s_msg_range = [1, 2, 3]
                for i in s_msg_range:
                    try:
                        udp_msgs.append(''.join([msg, '\n\n']))
                    except (OSError, IOError) as e:
                        print(str(e))
            self.msgs_to_send = udp_msgs
            return