Browse Source

PDF-Comparison End2End implemented

bernhardbuhl 4 years ago
parent
commit
e859992362
3 changed files with 17 additions and 7 deletions
  1. 3 1
      baangt/TestSteps/TestStepMaster.py
  2. 14 6
      baangt/base/PDFCompare.py
  3. BIN
      examples/pdfDownloadCompare.xlsx

+ 3 - 1
baangt/TestSteps/TestStepMaster.py

@@ -184,7 +184,9 @@ class TestStepMaster:
             lPDFDataClass.referenceID = lValue
             lDict = {"": lPDFDataClass}
             lPDFCompare = PDFCompare()
-            lPDFCompare.compare_multiple(lDict)
+            lDict = lPDFCompare.compare_multiple(lDict)
+            self.testcaseDataDict["DOC_Compare_Status"] = lDict[""].Status
+            self.testcaseDataDict["DOC_Compare_Results"] = lDict[""].StatusText
 
     def replaceAllVariables(self, lValue, lValue2):
         # Replace variables from data file

+ 14 - 6
baangt/base/PDFCompare.py

@@ -93,7 +93,7 @@ class PDFCompare:
         details = self.__callUploadService(details)
 
         if details.newUUID:
-            self.__callComparisonServiceExecution(details, details.newUUID)
+            details = self.__callComparisonServiceExecution(details)
 
         return details
 
@@ -126,20 +126,28 @@ class PDFCompare:
 
     def __callComparisonServiceExecution(self, details: PDFCompareDetails):
         # Requests Comparison of the two IDs, typically after they were uploaded
-        params = {"uuid1": details.referenceID,
-                  "uuid2": details.newUUID}
+        # UUID 1 = new ID of this file
+        # UUID 2 = Reference ID of old file (Uploaded as a reference and given as parameter in the Testcase!
+        params = {"uuid1": details.newUUID,
+                  "uuid2": details.referenceID}
         lResponse = self.__executeRequest(endpoint='/comparison', params=params, methodGetOrPost="get")
 
         if lResponse.status_code == 200:
             details.Status = "OK"
             lJson = lResponse.json()
-            # fixme: No idea, what is in this response. Find out!
+            if lJson["result"] == "OK":
+                details.Status = "OK"
+                details.StatusText = ""
+            else:
+                details.Status = "NOK"
+                details.StatusText = "Diff in Original: " + lJson["result"]["orig_file_diff"] + \
+                                     "\nDiff in Reference:" +  lJson["result"]["orig_file_diff"]
         else:
             details.Status = "NOK"
             details.StatusText = f"Error {lResponse.status_code} from Request to Service. " \
                                  f"Error from service was {lResponse.text}"
 
-        pass
+        return details
 
     def __executeRequest(self, endpoint, params, methodGetOrPost="get", files=None):
         lUrl = f"{self.baseURL}/{endpoint}"
@@ -173,7 +181,7 @@ class PDFCompare:
 
         try:
             blob = open(file, "rb").read()
-            blob = b64encode(blob)
+            # blob = b64encode(blob)
         except FileNotFoundError as e:
             logger.critical(f"File {file} not found to read current PDF for comparison")
             return None

BIN
examples/pdfDownloadCompare.xlsx