|
@@ -2,15 +2,42 @@ import pytest
|
|
|
from os import getcwd
|
|
|
from pathlib import Path
|
|
|
from baangt.base.PDFCompare import PDFCompare, PDFCompareDetails
|
|
|
+import socket
|
|
|
|
|
|
+"""
|
|
|
#####################
|
|
|
### Attention #######
|
|
|
#####################
|
|
|
-# Before you run these tests, you'll have to run **flask run** in PDF-Comparison service on local host, or these
|
|
|
-# Tests will fail.
|
|
|
+# Before you run these tests, you'll have to run **flask run** in PDF-Comparison service on local host, or most of these
|
|
|
+# Tests will be skipped.
|
|
|
+
|
|
|
+# To do so (first start)
|
|
|
+git clone https://gogs.earthsquad.global/athos/baangt-PDFComparison
|
|
|
+cd baangt-PDFComparison
|
|
|
+virtualenv venv
|
|
|
+source venv/bin/activate
|
|
|
+pip install -r pdf_comaprison_flask_api/requirements.txt
|
|
|
+
|
|
|
+# Everytime:
|
|
|
+cd pdf_comaprison_flask_api
|
|
|
+export FLASK_APP=app.py
|
|
|
+flask run
|
|
|
+"""
|
|
|
|
|
|
newOriginalFile1_UUID = None # UUID of new example file 1
|
|
|
|
|
|
+def __checkSocketOpen() -> bool:
|
|
|
+ aSocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
|
|
+ result = aSocket.connect_ex(("127.0.0.1", 5000))
|
|
|
+ aSocket.close()
|
|
|
+ if result == 0:
|
|
|
+ return True
|
|
|
+ else:
|
|
|
+ return False
|
|
|
+
|
|
|
+lPortOpen = __checkSocketOpen()
|
|
|
+
|
|
|
+
|
|
|
def __getDictStructure():
|
|
|
return {"referenceID": "",
|
|
|
"BLOB": "",
|
|
@@ -22,7 +49,8 @@ def __getDictStructure():
|
|
|
def __uploadNewFiles():
|
|
|
global newOriginalFile2_UUID
|
|
|
global newOriginalFile1_UUID
|
|
|
- newOriginalFile1_UUID = __uploadNewFile(Path(getcwd()).joinpath("pdfs").joinpath("sample.pdf"))
|
|
|
+ newOriginalFile1_UUID = __uploadNewFile(Path(getcwd()).joinpath("tests").joinpath("pdfs").joinpath("sample.pdf"))
|
|
|
+
|
|
|
|
|
|
def __uploadNewFile(fileNameAndPath):
|
|
|
lFileDetails = PDFCompareDetails()
|
|
@@ -32,6 +60,8 @@ def __uploadNewFile(fileNameAndPath):
|
|
|
assert lFileDetails.Status == "OK"
|
|
|
return lFileDetails.newUUID
|
|
|
|
|
|
+
|
|
|
+@pytest.mark.skipif(lPortOpen==False, reason="PDF-Comparison service not available")
|
|
|
def test_UploadNewFilesForTests():
|
|
|
__uploadNewFiles()
|
|
|
assert newOriginalFile1_UUID
|
|
@@ -55,9 +85,11 @@ def test_PDFCompare_withWrongFile():
|
|
|
|
|
|
assert lDict["pdfThatdoesntExist.pdf"]["Status"] == 'NOK'
|
|
|
|
|
|
+
|
|
|
+@pytest.mark.skipif(lPortOpen==False, reason="PDF-Comparison service not available")
|
|
|
def test_PDFCompare_withFileLoadOK():
|
|
|
pdfCompare = PDFCompare()
|
|
|
- lFile = Path(getcwd()).joinpath("pdfs").joinpath("sample.pdf")
|
|
|
+ lFile = Path(getcwd()).joinpath("tests").joinpath("pdfs").joinpath("sample.pdf")
|
|
|
|
|
|
lDict = {lFile: __getDictStructure()}
|
|
|
lDict[lFile]["referenceID"] = newOriginalFile1_UUID
|
|
@@ -67,9 +99,11 @@ def test_PDFCompare_withFileLoadOK():
|
|
|
assert len(lDict[lFile]["newUUID"]) > 0
|
|
|
assert lDict[lFile]["Status"] == "OK"
|
|
|
|
|
|
+
|
|
|
+@pytest.mark.skipif(lPortOpen==False, reason="PDF-Comparison service not available")
|
|
|
def test_PDFCompare_withFileLoadNOK():
|
|
|
pdfCompare = PDFCompare()
|
|
|
- lFile = Path(getcwd()).joinpath("pdfs").joinpath("sample2.pdf")
|
|
|
+ lFile = Path(getcwd()).joinpath("tests").joinpath("pdfs").joinpath("sample2.pdf")
|
|
|
|
|
|
lDict = {lFile: __getDictStructure()}
|
|
|
lDict[lFile]["referenceID"] = newOriginalFile1_UUID
|
|
@@ -79,10 +113,11 @@ def test_PDFCompare_withFileLoadNOK():
|
|
|
assert len(lDict[lFile]["newUUID"]) > 0
|
|
|
assert lDict[lFile]["Status"] == "NOK"
|
|
|
|
|
|
+
|
|
|
def test_PDFCompare_withDataClass():
|
|
|
pdfCompare = PDFCompare()
|
|
|
pdfDataClass = PDFCompareDetails()
|
|
|
- pdfDataClass.fileName = Path(getcwd()).joinpath("pdfs").joinpath("sample.pdf")
|
|
|
+ pdfDataClass.fileName = Path(getcwd()).joinpath("tests").joinpath("pdfs").joinpath("sample.pdf")
|
|
|
pdfDataClass.referenceID = "12345"
|
|
|
|
|
|
lDict = {pdfDataClass.fileName: pdfDataClass}
|
|
@@ -92,9 +127,10 @@ def test_PDFCompare_withDataClass():
|
|
|
assert lDict[pdfDataClass.fileName].Status == "NOK"
|
|
|
assert "Config wrong?" in lDict[pdfDataClass.fileName].StatusText
|
|
|
|
|
|
+
|
|
|
def test_PDFCompare_withWrongURL():
|
|
|
pdfCompare = PDFCompare(baseURL="http://franzi.fritzi:4711")
|
|
|
- lFile = Path(getcwd()).joinpath("pdfs").joinpath("sample.pdf")
|
|
|
+ lFile = Path(getcwd()).joinpath("tests").joinpath("pdfs").joinpath("sample.pdf")
|
|
|
|
|
|
lDict = {lFile: __getDictStructure()}
|
|
|
|