Update: Test cases

This commit is contained in:
dx-tan 2024-05-03 08:51:05 +07:00
parent 2c141e3b60
commit b32a5db504
6 changed files with 131 additions and 163 deletions

View File

@ -20,7 +20,7 @@
},
{
"label": "invoice_no",
"value": "CTSM-I001676"
"value": "CTSM-1001676"
}
],
"doc_type": "sbt_document",

0
tests/__init__.py Normal file
View File

View File

@ -44,86 +44,86 @@ def test_1_invoice_1_imei():
assert "358975990917032" == get_field(document, "imei_number")[0]
def test_1_invoice_3_imei():
invoice_files = [
"test_samples/sbt/invoice.jpg"
]
imei_files = [
"test_samples/sbt/imei1.jpg",
"test_samples/sbt/imei2.jpg",
"test_samples/sbt/imei3.jpg"
]
data = make_sbt_request(host=HOST, token=token, invoice_files=invoice_files, imei_files=imei_files)
# def test_1_invoice_3_imei():
# invoice_files = [
# "test_samples/sbt/invoice.jpg"
# ]
# imei_files = [
# "test_samples/sbt/imei1.jpg",
# "test_samples/sbt/imei2.jpg",
# "test_samples/sbt/imei3.jpg"
# ]
# data = make_sbt_request(host=HOST, token=token, invoice_files=invoice_files, imei_files=imei_files)
data = data["data"]["data"]
assert data["total_pages"] == 4
assert data["ocr_num_pages"] == 4
assert data["status"] == 200
# data = data["data"]["data"]
# assert data["total_pages"] == 4
# assert data["ocr_num_pages"] == 4
# assert data["status"] == 200
document = data["document"][0]
assert document["end_page"] == 4
assert document["start_page"] == 1
check_invoice_data(document)
# document = data["document"][0]
# assert document["end_page"] == 4
# assert document["start_page"] == 1
# check_invoice_data(document)
assert 3 == len(get_field(document, "imei_number"))
assert "358975990917032" == get_field(document, "imei_number")[0]
assert "350731691693549" == get_field(document, "imei_number")[1]
assert "R52W70BHDWX" == get_field(document, "imei_number")[2]
# assert 3 == len(get_field(document, "imei_number"))
# assert "358975990917032" == get_field(document, "imei_number")[0]
# assert "350731691693549" == get_field(document, "imei_number")[1]
# assert "R52W70BHDWX" == get_field(document, "imei_number")[2]
def test_1_invoice_5_imei():
invoice_files = [
"test_samples/sbt/invoice.jpg"
]
imei_files = [
"test_samples/sbt/imei1.jpg",
"test_samples/sbt/imei2.jpg",
"test_samples/sbt/imei3.jpg",
"test_samples/sbt/imei4.jpeg",
"test_samples/sbt/imei5.jpg"
]
data = make_sbt_request(host=HOST, token=token, invoice_files=invoice_files, imei_files=imei_files)
# def test_1_invoice_5_imei():
# invoice_files = [
# "test_samples/sbt/invoice.jpg"
# ]
# imei_files = [
# "test_samples/sbt/imei1.jpg",
# "test_samples/sbt/imei2.jpg",
# "test_samples/sbt/imei3.jpg",
# "test_samples/sbt/imei4.jpeg",
# "test_samples/sbt/imei5.jpg"
# ]
# data = make_sbt_request(host=HOST, token=token, invoice_files=invoice_files, imei_files=imei_files)
data = data["data"]["data"]
assert data["total_pages"] == 6
assert data["ocr_num_pages"] == 6
assert data["status"] == 200
# data = data["data"]["data"]
# assert data["total_pages"] == 6
# assert data["ocr_num_pages"] == 6
# assert data["status"] == 200
document = data["document"][0]
assert document["end_page"] == 6
assert document["start_page"] == 1
check_invoice_data(document)
# document = data["document"][0]
# assert document["end_page"] == 6
# assert document["start_page"] == 1
# check_invoice_data(document)
assert 5 == len(get_field(document, "imei_number"))
assert "358975990917032" == get_field(document, "imei_number")[0]
assert "350731691693549" == get_field(document, "imei_number")[1]
assert "R52W70BHDWX" == get_field(document, "imei_number")[2]
assert "350073345090297" == get_field(document, "imei_number")[3]
assert "0PBL3NHW500023N" == get_field(document, "imei_number")[4]
# assert 5 == len(get_field(document, "imei_number"))
# assert "358975990917032" == get_field(document, "imei_number")[0]
# assert "350731691693549" == get_field(document, "imei_number")[1]
# assert "R52W70BHDWX" == get_field(document, "imei_number")[2]
# assert "350073345090297" == get_field(document, "imei_number")[3]
# assert "0PBL3NHW500023N" == get_field(document, "imei_number")[4]
def test_0_invoice_3_imei():
invoice_files = []
imei_files = [
"test_samples/sbt/imei1.jpg",
"test_samples/sbt/imei2.jpg",
"test_samples/sbt/imei3.jpg"
]
data = make_sbt_request(host=HOST, token=token, invoice_files=invoice_files, imei_files=imei_files)
# def test_0_invoice_3_imei():
# invoice_files = []
# imei_files = [
# "test_samples/sbt/imei1.jpg",
# "test_samples/sbt/imei2.jpg",
# "test_samples/sbt/imei3.jpg"
# ]
# data = make_sbt_request(host=HOST, token=token, invoice_files=invoice_files, imei_files=imei_files)
data = data["data"]["data"]
assert data["total_pages"] == 3
assert data["ocr_num_pages"] == 3
assert data["status"] == 200
# data = data["data"]["data"]
# assert data["total_pages"] == 3
# assert data["ocr_num_pages"] == 3
# assert data["status"] == 200
document = data["document"][0]
assert document["end_page"] == 3
assert document["start_page"] == 1
# document = data["document"][0]
# assert document["end_page"] == 3
# assert document["start_page"] == 1
assert 3 == len(get_field(document, "imei_number"))
assert "358975990917032" == get_field(document, "imei_number")[0]
assert "350731691693549" == get_field(document, "imei_number")[1]
assert "R52W70BHDWX" == get_field(document, "imei_number")[2]
# assert 3 == len(get_field(document, "imei_number"))
# assert "358975990917032" == get_field(document, "imei_number")[0]
# assert "350731691693549" == get_field(document, "imei_number")[1]
# assert "R52W70BHDWX" == get_field(document, "imei_number")[2]
def test_1_invoice_pdf_1_imei():

View File

@ -10,12 +10,26 @@ PASSWORD = os.environ.get("IDP_PASSWORD", "XXXXXXXXXXXXXXXXXXXXX")
token = login(HOST, USERNAME, PASSWORD)
def check_invoice_data_2(document):
assert document["doc_type"] == "sbt_document"
assert get_field(document, "retailername") == "Starhub Shop"
assert get_field(document, "sold_to_party") is None
assert "2022-02-22" in get_field(document, "purchase_date")
def test_invoice_only():
invoice_files = [
"test_samples/sbt/20220303025923NHNE_20220222_Starhub_Order_Confirmation_by_Email.pdf"
]
imei_files = []
data = make_sbt_request(host=HOST, token=token, invoice_files=invoice_files, imei_files=imei_files, ensure_success=False)
response_data = data["data"]
assert "imei_file param is required" in str(response_data)
data = data["data"]["data"]
assert data["total_pages"] == 1
assert data["ocr_num_pages"] == 1
assert data["status"] == 200
document = data["document"][0]
assert document["end_page"] == 1
assert document["start_page"] == 1
check_invoice_data_2(document)

View File

@ -26,7 +26,7 @@ def test_1_invoice_6_imei():
]
data = make_sbt_request(host=HOST, token=token, invoice_files=invoice_files, imei_files=imei_files, ensure_success=False)
assert "Limit reached. Number of imei_file limit at 5" in str(data["data"])
assert "Limit reached. Number of imei_file limit at 2" in str(data["data"])
def test_1_invoice_5_imei():
@ -42,50 +42,4 @@ def test_1_invoice_5_imei():
]
data = make_sbt_request(host=HOST, token=token, invoice_files=invoice_files, imei_files=imei_files, ensure_success=False)
data = data["data"]["data"]
assert data["total_pages"] == 6
assert data["ocr_num_pages"] == 6
assert data["status"] == 200
document = data["document"][0]
assert document["end_page"] == 6
assert document["start_page"] == 1
gt = {
"content": [
{
"label": "retailername",
"value": "Best Denki"
},
{
"label": "sold_to_party",
"value": None
},
{
"label": "purchase_date",
"value": [
"2022-02-18"
]
},
{
"label": "imei_number",
"value": [
"357822611219904",
"RFAW2022FED",
"5AWH14MT400396N",
"0HU33NIW200044K",
"0GJG4DBW200318X"
]
},
{
"label": "invoice_no",
"value": None
}
],
"doc_type": "sbt_document",
"end_page": 6,
"start_page": 1
}
diff = deepdiff.DeepDiff(document, gt)
assert diff == {}, f"Different result! GT: {gt}; RESULT: {document}"
assert "Limit reached. Number of imei_file limit at 2" in str(data["data"])

View File

@ -43,55 +43,55 @@ def test_1_invoice_2_imei():
assert diff == {}, f"Different result! GT: {gt}; RESULT: {document}"
def test_1_invoice_3_imei():
invoice_files = [
"test_samples/test_07/invoice_jpg.jpg",
]
imei_files = [
"test_samples/test_07/imei_valid_1.jpg",
"test_samples/test_07/imei_valid_2.jpg",
"test_samples/test_07/imei_valid_3.jpg",
]
data = make_sbt_request(host=HOST, token=token, invoice_files=invoice_files, imei_files=imei_files, ensure_success=False)
document = data["data"]["data"]["document"][0]
gt = json.load(open("test_samples/test_23.json", "r"))
diff = deepdiff.DeepDiff(document, gt)
# def test_1_invoice_3_imei():
# invoice_files = [
# "test_samples/test_07/invoice_jpg.jpg",
# ]
# imei_files = [
# "test_samples/test_07/imei_valid_1.jpg",
# "test_samples/test_07/imei_valid_2.jpg",
# "test_samples/test_07/imei_valid_3.jpg",
# ]
# data = make_sbt_request(host=HOST, token=token, invoice_files=invoice_files, imei_files=imei_files, ensure_success=False)
# document = data["data"]["data"]["document"][0]
# gt = json.load(open("test_samples/test_23.json", "r"))
# diff = deepdiff.DeepDiff(document, gt)
assert diff == {}, f"Different result! GT: {gt}; RESULT: {document}"
# assert diff == {}, f"Different result! GT: {gt}; RESULT: {document}"
def test_1_invoice_4_imei():
invoice_files = [
"test_samples/test_07/invoice_jpg.jpg",
]
imei_files = [
"test_samples/test_07/imei_valid_1.jpg",
"test_samples/test_07/imei_valid_2.jpg",
"test_samples/test_07/imei_valid_3.jpg",
"test_samples/test_07/imei_valid_4.jpg",
]
data = make_sbt_request(host=HOST, token=token, invoice_files=invoice_files, imei_files=imei_files, ensure_success=False)
document = data["data"]["data"]["document"][0]
gt = json.load(open("test_samples/test_24.json", "r"))
diff = deepdiff.DeepDiff(document, gt)
# def test_1_invoice_4_imei():
# invoice_files = [
# "test_samples/test_07/invoice_jpg.jpg",
# ]
# imei_files = [
# "test_samples/test_07/imei_valid_1.jpg",
# "test_samples/test_07/imei_valid_2.jpg",
# "test_samples/test_07/imei_valid_3.jpg",
# "test_samples/test_07/imei_valid_4.jpg",
# ]
# data = make_sbt_request(host=HOST, token=token, invoice_files=invoice_files, imei_files=imei_files, ensure_success=False)
# document = data["data"]["data"]["document"][0]
# gt = json.load(open("test_samples/test_24.json", "r"))
# diff = deepdiff.DeepDiff(document, gt)
assert diff == {}, f"Different result! GT: {gt}; RESULT: {document}"
# assert diff == {}, f"Different result! GT: {gt}; RESULT: {document}"
def test_1_invoice_5_imei():
invoice_files = [
"test_samples/test_07/invoice_jpg.jpg",
]
imei_files = [
"test_samples/test_07/imei_valid_1.jpg",
"test_samples/test_07/imei_valid_2.jpg",
"test_samples/test_07/imei_valid_3.jpg",
"test_samples/test_07/imei_valid_4.jpg",
"test_samples/test_07/imei_valid_5.jpg",
]
data = make_sbt_request(host=HOST, token=token, invoice_files=invoice_files, imei_files=imei_files, ensure_success=False)
document = data["data"]["data"]["document"][0]
gt = json.load(open("test_samples/test_25.json", "r"))
diff = deepdiff.DeepDiff(document, gt)
# def test_1_invoice_5_imei():
# invoice_files = [
# "test_samples/test_07/invoice_jpg.jpg",
# ]
# imei_files = [
# "test_samples/test_07/imei_valid_1.jpg",
# "test_samples/test_07/imei_valid_2.jpg",
# "test_samples/test_07/imei_valid_3.jpg",
# "test_samples/test_07/imei_valid_4.jpg",
# "test_samples/test_07/imei_valid_5.jpg",
# ]
# data = make_sbt_request(host=HOST, token=token, invoice_files=invoice_files, imei_files=imei_files, ensure_success=False)
# document = data["data"]["data"]["document"][0]
# gt = json.load(open("test_samples/test_25.json", "r"))
# diff = deepdiff.DeepDiff(document, gt)
assert diff == {}, f"Different result! GT: {gt}; RESULT: {document}"
# assert diff == {}, f"Different result! GT: {gt}; RESULT: {document}"