Browse Source

Append results of Testrun to existing file(s) + Updated examples

bernhardbuhl 3 years ago
parent
commit
1e06d59854

+ 21 - 9
baangt/base/ExportResults/Append2BaseXLS.py

@@ -1,17 +1,21 @@
 from logging import getLogger
 import baangt.base.GlobalConstants as GC
-from icopy2xls import
+from icopy2xls import Mover
+from baangt.base.PathManagement import ManagedPaths
 
 logger = getLogger("pyC")
 
+
 class Append2BaseXLS:
     """
     If in the globals of the current testrun the parameter AR2BXLS (Append Results to Base XLS) is set,
     we execute baangt Move-Corresponding module accordingly.
     """
-    def __init__(self, testRunInstance, resultsFileName:str=None):
+    def __init__(self, testRunInstance, resultsFileName: str=None):
         self.testRunInstance = testRunInstance
         self.resultsFileName = resultsFileName
+        self.mp = ManagedPaths()
+
         self._append2BaseXLS()
 
     def _append2BaseXLS(self):
@@ -25,14 +29,22 @@ class Append2BaseXLS:
         if ";" in lGlobals.get("AR2BXLS"):
             files = lGlobals.get("AR2BXLS").split(";")
             for file in files:
-                fileTuples.append(file.split(",")[0], file.split(",")[1])
+                fileTuples.append(self.checkAppend(file))
         else:
-            fileTuples.append([lGlobals["AR2BXLS"].split(",")[0], lGlobals["AR2BXLS"].split(",")[1]])
+            fileTuples.append(self.checkAppend(lGlobals["AR2BXLS"]))
 
         for fileTuple in fileTuples:
-            MC.Mover(source_file_path=self.resultsFileName,
-                     source_sheet="Output",
-                     destination_file_path=fileTuple[0],
-                     destination_sheet=fileTuple[1])
-
+            logger.debug(f"Starting to append results to: {str(fileTuple)}")
+            lMover = Mover(source_file_path=self.resultsFileName,
+                           source_sheet="Output",
+                           destination_file_path=fileTuple[0],
+                           destination_sheet=fileTuple[1])
+            lMover.move(add_missing_columns=False)
 
+    def checkAppend(self, file):
+        lFileAndPath = self.mp.findFileInAnyPath(filename=file.split(",")[0])
+        if lFileAndPath:
+            return [lFileAndPath, file.split(",")[1]]
+        else:
+            logger.critical(f"File not found anywhere: {file.split(',')[0]}")
+            return None

+ 25 - 0
baangt/base/ExportResults/ExportResults.py

@@ -67,6 +67,9 @@ class ExportResults:
 
         logger.info("Export-Sheet for results: " + self.fileName)
 
+        self.__removeUnwantedFields()  # Will remove Password-Contents AND fields from data records, that came from
+                                       # Globals-File.
+
         # export results to DB
         self.testcase_uuids = []
         self.exportToDataBase()
@@ -118,6 +121,28 @@ class ExportResults:
             except Exception as ex:
                 logger.debug(ex)
 
+    def __removeUnwantedFields(self):
+        lListPasswordFieldNames = ["PASSWORD", "PASSWORT", "PASSW"]
+        if not self.testRunInstance.globalSettings.get("LetPasswords"):
+            # If there's a password in GlobalSettings, remove the value:
+            for key, value in self.testRunInstance.globalSettings.items():
+                if key.upper() in lListPasswordFieldNames:
+                    self.testRunInstance.globalSettings[key] = "*" * 8
+
+            # If there's a password in the datafile, remove the value
+            # Also remove all columns, that are anyway included in the global settings
+            for key, fields in self.dataRecords.items():
+                fieldsToPop = []
+                for field, value in fields.items():
+                    if field.upper() in ["PASSWORD", "PASSWORT"]:
+                        self.dataRecords[key][field] = "*" * 8
+                    if field in self.testRunInstance.globalSettings.keys():
+                        logger.debug(
+                            f"Added {field} to fields to be removed from data record as it exists in GlobalSettings already.")
+                        fieldsToPop.append(field)
+                for field in fieldsToPop:
+                    logger.debug(f"Removed field {field} from data record.")
+                    fields.pop(field)
 
     def exportAdditionalData(self):
         # Runs only, when KWARGS-Parameter is set.

+ 15 - 0
baangt/base/PathManagement.py

@@ -257,3 +257,18 @@ class ManagedPaths(metaclass=Singleton):
 
         self.__makeAndCheckDir(self.IniPath)
         return self.IniPath
+
+    def findFileInAnyPath(self, filename):
+        if Path(filename).exists():
+            return filename
+
+        if Path(self.getOrSetExportPath()).joinpath(filename).exists():
+            return Path(self.getOrSetExportPath()).joinpath(filename)
+
+        if Path(self.getOrSetImportPath()).joinpath(filename).exists():
+            return Path(self.getOrSetImportPath()).joinpath(filename)
+
+        if Path(self.getOrSetRootPath()).joinpath(filename).exists():
+            return Path(self.getOrSetRootPath()).joinpath(filename)
+
+        return None

BIN
examples/CompleteBaangtWebdemo.xlsx


BIN
examples/CompleteBaangtWebdemo_ResultsCombined.xlsx


+ 6 - 4
examples/globals.json

@@ -1,10 +1,10 @@
 {
-    "TC.Lines": "",
+    "TC.Lines": "1",
     "TC.dontCloseBrowser": "False",
     "TC.slowExecution": "False",
     "TC.NetworkInfo": "False",
-    "TX.DEBUG": "False",
-    "TC.Browser": "Chrome",
+    "TX.DEBUG": "True",
+    "TC.Browser": "FF",
     "TC.BrowserAttributes": "",
     "TC.ParallelRuns": "1",
     "TC.BrowserWindowSize": "1024x768",
@@ -16,5 +16,7 @@
     "SlackWebHook": "",
     "TelegramBot": "",
     "TelegramChannel": "",
-    "DeactivateStatistics": "False"
+    "DeactivateStatistics": "False",
+    "Password": "Franzi1234",
+    "AR2BXLS": "CompleteBaangtWebdemo_ResultsCombined.xlsx,CombinedResults"
 }