# abstract class for instance components # --------------------------------------------------------------------- from datetime import datetime import ulrich.message import inspect """ A component represents an application of the system-under-test As the representation it has to knowlegde of the url, which other components depends on this component. During a test-run the component must be checked, prepared, appfiles has to be collected, etc. For this doing there are some standard-methods implemented. """ class Component: def init(self): """ The range of the test-system is defined by the dependancy graph which starts at the application.and indate each component. By this way it is possible to use the same component in different test-systems and so the application-knowlegde of this component must be defined only once. A component can be a software-instance or a data. Initialisation of concrete component it is controlled by their configuration """ job = ulrich.program.Job.getInstance() verify = job.getDebugLevel(self.name) self.m.debug(verify, "--- " + str(inspect.currentframe().f_code.co_name) + "() " + str(self.name)) def prepare_system(self): """ In order to preparate the test system test data should be cleaned and loaded with actual data. This can happen on different granularities: for each testcase or for each test sequences or for a test set or for a whole test. The loaded test data should be selected for a later comparison. :return: """ pass def init_Testset(self): """ main methode for system-preparation :param self: :return: """ job = ulrich.program.Job.getInstance() verify = -1+job.getDebugLevel(self.name) self.m.logInfo("--- " + str(inspect.currentframe().f_code.co_name) + "() started at " + datetime.now().strftime("%Y%m%d_%H%M%S") + " for " + str(self.name).upper()) self.m.setMsg("checkInstance for " + self.name + " is OK") self.m.logInfo("--- " + str(inspect.currentframe().f_code.co_name) + "() finished at " + datetime.now().strftime("%Y%m%d_%H%M%S") + " for " + str(self.name).upper()) def reset_TsData(self): job = ulrich.program.Job.getInstance() verify = -1+job.getDebugLevel(self.name) self.m.logDebug(verify, "--- " + str(inspect.currentframe().f_code.co_name) + "() started at " + datetime.now().strftime("%Y%m%d_%H%M%S") + " for " + str(self.name).upper()) if "log" in self.conf["artifact"]: self.m.logInfo("log rotate in "+ self.name) if "db" in self.conf["artifact"]: self.m.logInfo("delete db-content "+ self.name) if "lob" in self.conf["artifact"]: self.m.logInfo("lob is deleted with db "+ self.name) if "file" in self.conf["artifact"]: self.m.logInfo("rm files in "+ self.name) self.m.setMsg("checkInstance for " + self.name + " is OK") self.m.logDebug(verify, "--- " + str(inspect.currentframe().f_code.co_name) + "() finished at " + datetime.now().strftime("%Y%m%d_%H%M%S") + " for " + str(self.name).upper()) def load_TsData(self, testdata): job = ulrich.program.Job.getInstance() verify = -1+job.getDebugLevel(self.name) self.m.logDebug(verify, "--- " + str(inspect.currentframe().f_code.co_name) + "() started at " + datetime.now().strftime("%Y%m%d_%H%M%S") + " for " + str(self.name).upper()) if "testdata" in self.conf: if self.conf["testdata"] == "db": self.m.logInfo("insert db-content " + self.name) self.m.setMsg("data loaded for " + self.name + " is OK") self.m.logDebug(verify, "--- " + str(inspect.currentframe().f_code.co_name) + "() finished at " + datetime.now().strftime("%Y%m%d_%H%M%S") + " for " + str(self.name).upper()) def read_TsData(self): job = ulrich.program.Job.getInstance() verify = -1+job.getDebugLevel(self.name) self.m.logDebug(verify, "--- " + str(inspect.currentframe().f_code.co_name) + "() started at " + datetime.now().strftime("%Y%m%d_%H%M%S") + " for " + str(self.name).upper()) if "db" in self.conf["artifact"]: self.m.logInfo("select db-content "+ self.name) if "lob" in self.conf["artifact"]: self.m.logInfo("check lob if is deleted with db "+ self.name) self.m.setMsg("checkInstance for " + self.name + " is OK") self.m.logDebug(verify, "--- " + str(inspect.currentframe().f_code.co_name) + "() finished at " + datetime.now().strftime("%Y%m%d_%H%M%S") + " for " + str(self.name).upper()) def init_Testcase(self): """ main methode for system-preparation :param self: :return: """ job = ulrich.program.Job.getInstance() verify = -1+job.getDebugLevel(self.name) self.m.logInfo("--- " + str(inspect.currentframe().f_code.co_name) + "() started at " + datetime.now().strftime("%Y%m%d_%H%M%S") + " for " + str(self.name).upper()) self.m.logInfo("something in "+ self.name) self.m.setMsg("checkInstance for " + self.name + " is OK") self.m.logInfo("--- " + str(inspect.currentframe().f_code.co_name) + "() finished at " + datetime.now().strftime("%Y%m%d_%H%M%S") + " for " + str(self.name).upper()) def reset_TcData(self): job = ulrich.program.Job.getInstance() verify = -1+job.getDebugLevel(self.name) self.m.logDebug(verify, "--- " + str(inspect.currentframe().f_code.co_name) + "() started at " + datetime.now().strftime("%Y%m%d_%H%M%S") + " for " + str(self.name).upper()) if "log" in self.conf["artifact"]: self.m.logInfo("log rotate in "+ self.name) if "db" in self.conf["artifact"]: self.m.logInfo("delete db-content "+ self.name) if "lob" in self.conf["artifact"]: self.m.logInfo("lob is deleted with db "+ self.name) if "file" in self.conf["artifact"]: self.m.logInfo("rm files in "+ self.name) self.m.setMsg("checkInstance for " + self.name + " is OK") self.m.logDebug(verify, "--- " + str(inspect.currentframe().f_code.co_name) + "() finished at " + datetime.now().strftime("%Y%m%d_%H%M%S") + " for " + str(self.name).upper()) def load_TcData(self): job = ulrich.program.Job.getInstance() verify = -1+job.getDebugLevel(self.name) self.m.logDebug(verify, "--- " + str(inspect.currentframe().f_code.co_name) + "() started at " + datetime.now().strftime("%Y%m%d_%H%M%S") + " for " + str(self.name).upper()) if "testdata" in self.conf: if self.conf["testdata"] == "db": self.m.logInfo("insert db-content " + self.name) self.m.setMsg("data loaded for " + self.name + " is OK") self.m.logDebug(verify, "--- " + str(inspect.currentframe().f_code.co_name) + "() finished at " + datetime.now().strftime("%Y%m%d_%H%M%S") + " for " + str(self.name).upper()) def read_TcData(self): job = ulrich.program.Job.getInstance() verify = -1+job.getDebugLevel(self.name) self.m.logDebug(verify, "--- " + str(inspect.currentframe().f_code.co_name) + "() started at " + datetime.now().strftime("%Y%m%d_%H%M%S") + " for " + str(self.name).upper()) if "db" in self.conf["artifact"]: self.m.logInfo("select db-content "+ self.name) if "lob" in self.conf["artifact"]: self.m.logInfo("check lob if is deleted with db "+ self.name) self.m.setMsg("checkInstance for " + self.name + " is OK") self.m.logDebug(verify, "--- " + str(inspect.currentframe().f_code.co_name) + "() finished at " + datetime.now().strftime("%Y%m%d_%H%M%S") + " for " + str(self.name).upper()) def test_system(self): """ :return: """ pass def spiele_ein(self): pass def erzeuge_Anfrage(self): pass def sende_Anfrage(self, testdata): pass def lese_Antwort(self): pass def finish_Testcase(self): """ initialization-routine for finish-step :return: """ job = ulrich.program.Job.getInstance() verify = -1+job.getDebugLevel(self.name) self.m.logInfo("--- " + str(inspect.currentframe().f_code.co_name) + "() started at " + datetime.now().strftime("%Y%m%d_%H%M%S") + " for " + str(self.name).upper()) self.m.logInfo("something in "+ self.name) self.m.setMsg("checkInstance for " + self.name + " is OK") self.m.logInfo("--- " + str(inspect.currentframe().f_code.co_name) + "() finished at " + datetime.now().strftime("%Y%m%d_%H%M%S") + " for " + str(self.name).upper()) def collect_system(self): """ After the test the test data of each component should be selected again - to get the post-condition. In each component is configured how these data can be collected. In this phase the collected data have to be transformed to comparable files. :return: """ pass def collect_TcArtifact(self): """ collects the artifacts from the test-system. the result is written as original in subfolder {tcorigin} post: a further contact zo the test-system is not necessary :return: """ job = ulrich.program.Job.getInstance() verify = job.getDebugLevel(self.name) if "log" in self.conf["artifact"]: self.m.logInfo("get files in for "+ self.name + " in " + self.conf["artifact"]["log"]["path"]) if "db" in self.conf["artifact"]: self.m.logInfo("select db-content "+ self.name) if "lob" in self.conf["artifact"]: pass # after selection get file from db if "file" in self.conf["artifact"]: self.m.logInfo("get files in for "+ self.name + " in " + self.conf["artifact"]["file"]["path"]) self.m.debug(verify, "--- " + str(inspect.currentframe().f_code.co_name) + "() " + str(self.name)) def split_TcResult(self): """ transforms the result from subfolder {tcorigin}. the result is written as utf-8-readable parts in subfolder {tcparts} :return: """ job = ulrich.program.Job.getInstance() verify = job.getDebugLevel(self.name) self.m.debug(verify, "--- " + str(inspect.currentframe().f_code.co_name) + "() " + str(self.name)) if "log" in self.conf["artifact"]: pass # if "db" in self.conf["artifact"]: pass # stored in table if "lob" in self.conf["artifact"]: self.m.logInfo("move file from db "+ self.name) self.m.logInfo("tidy files in for " + self.name + " in " + self.conf["artifact"]["lob"]["format"]) if "file" in self.conf["artifact"]: self.m.logInfo("tidy files in for "+ self.name + " in " + self.conf["artifact"]["file"]["format"]) def fix_TcResult(self): """ fixes the result which is collected and transformed from the test-system. the result is written in comparable form in folder {tcresult} with the identifiable name - like in target :return: """ job = ulrich.program.Job.getInstance() verify = job.getDebugLevel(self.name) self.m.debug(verify, "--- " + str(inspect.currentframe().f_code.co_name) + "() " + str(self.name)) def compare_results(self): """ to compare the actual result with the target result has three steps: 1 matching each element so you get a comparable pair 2 comparing this pair so maybe you get differences 3 rating the difference if this can be accepted :return: """ pass def collect_TcResult(self): """ collects the result from the folder {tcresult}. the content is stored intern for comparison :return: """ job = ulrich.program.Job.getInstance() verify = job.getDebugLevel(self.name) self.m.logInfo("get files in for " + self.name + " in tcresult ") self.m.debug(verify, "--- " + str(inspect.currentframe().f_code.co_name) + "() " + str(self.name)) def collect_Target(self): """ pre: only for components which be collected at the end of the test-set collects the result from the folder {rsresult}. post: a further contact zo the test-system is not necessary :return: """ job = ulrich.program.Job.getInstance() verify = job.getDebugLevel(self.name) self.m.debug(verify, "--- " + str(inspect.currentframe().f_code.co_name) + "() " + str(self.name)) def compare_TcResults(self): """ compares the result with the target (1) the elements of both sides are assigned [2) looks for differences in assigned pairs (3) try to accept the difference with inherent rules (4) writes the result of comparison as html in folder {diff*} (5) the summary result is returned :return: """ pass def getHitscore(self, typ, rs, tg): """ calculates the difference between the given elements. the score is a number [00000-99999] with prefix h_ - 00000 is the best, 99999 the worst :param typ: :param rs: :param tg: :return: """ def report_TcResults(self): """ reports the result-code :return: """ pass def finish_Testset(self): pass def collect_TsArtifact(self): """ collects the artifacts from the test-system. the result is written as original in subfolder {tsorigin} :return: """ pass def split_TsResult(self): """ transforms the result which is collected from the test-system. the result is written as utf-8-readable parts in the specific subfolder {tcparts} the relevant testcases will be called :return: """ job = ulrich.program.Job.getInstance() verify = job.getDebugLevel(self.name) self.m.debug(verify, "--- " + str(inspect.currentframe().f_code.co_name) + "() " + str(self.name)) # for tc in testcases: # self.fix_TcResult(self) def compare_TsResults(self): """ controles the comparison the result with the target :return: """ job = ulrich.program.Job.getInstance() verify = job.getDebugLevel(self.name) self.m.debug(verify, "--- " + str(inspect.currentframe().f_code.co_name) + "() " + str(self.name)) # for tc in testcases: # self.collect_TcResult # self.collect_Target # self.compare_TcResults def report_TsResults(self): """ (1.2) extraction of diff-files (only not accepted differences) as html-file in test-set - result-report - (2.3) visualization of final result-code of each component and each testcase in test-set - result-report - (2.4) visualization of statistical result-codes of each component and each test-set in test-context - result-report - :return: """ job = ulrich.program.Job.getInstance() verify = job.getDebugLevel(self.name) self.m.debug(verify, "--- " + str(inspect.currentframe().f_code.co_name) + "() " + str(self.name)) reportheader = '' reportbody = '' testreport = "" # if job.par.context == "tset": # for tc in testcases: # header = utils.report_tool.getTcHeader() # body = utils.report_tool.getTcExtraction() # if job.par.context == "tcontext": # for ts in testsets: reportheader = reportheader +'<\head>' reportbody = reportbody + '<\body>' testreport = reportheader + reportbody return testreport def report_result(self): """ When you finish your test run you have to report the result for your customer. 1 Your testers have recherche the results which are not acceptable. They need detailed information of all test results in order to proof if the difference has their cause in test-technicals or in system-technicals. They should be able to declare the cause. 2 Your testmanager wants to know what is done - the percentage of the necessary test metrik and the status of each test - and which principle faults are found and which cause the faults have. 3 Your projectmanager wants to know if the system is working correct - the percentage of the necessary test metrik and founded system errors. :return: """ pass def maintain_tests(self): """ :return: """ pass def declare_Target(self): job = ulrich.program.Job.getInstance() verify = -1+job.getDebugLevel(self.name) self.m.logInfo("--- " + str(inspect.currentframe().f_code.co_name) + "() started at " + datetime.now().strftime("%Y%m%d_%H%M%S") + " for " + str(self.name).upper()) self.m.logInfo("something in "+ self.name) self.m.setMsg("checkInstance for " + self.name + " is OK") self.m.logInfo("--- " + str(inspect.currentframe().f_code.co_name) + "() finished at " + datetime.now().strftime("%Y%m%d_%H%M%S") + " for " + str(self.name).upper()) def catalog_tests(self): """ Its not only a nice-to-have to know which tests are exactly running and which special cases they tests. Each test running in a special context a special case. Each of such cases are defined by some attributes. But often nobody knows in which testcases these attributes are tested. If you want to proof your test metrik for some very special cases a database of these attributes can be very helpful! Otherwise you must specify always new test cases for a correction of such special case, the existent test cases must be found afterwards and must be correct in their expectation. :return: """ pass