From b32a5db504ee5872a7d0f27b69ea0e30f0dd7436 Mon Sep 17 00:00:00 2001 From: dx-tan Date: Fri, 3 May 2024 08:51:05 +0700 Subject: [PATCH] Update: Test cases --- test_samples/test_26/result.json | 2 +- tests/__init__.py | 0 tests/test_set_00_invoice_05_imeis.py | 134 ++++++++++++------------ tests/test_set_06_invoice_only.py | 18 +++- tests/test_set_07_01_invoice_06_imei.py | 50 +-------- tests/test_set_21_to_25.py | 90 ++++++++-------- 6 files changed, 131 insertions(+), 163 deletions(-) create mode 100644 tests/__init__.py diff --git a/test_samples/test_26/result.json b/test_samples/test_26/result.json index 415cd37..5cef4ca 100644 --- a/test_samples/test_26/result.json +++ b/test_samples/test_26/result.json @@ -20,7 +20,7 @@ }, { "label": "invoice_no", - "value": "CTSM-I001676" + "value": "CTSM-1001676" } ], "doc_type": "sbt_document", diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/test_set_00_invoice_05_imeis.py b/tests/test_set_00_invoice_05_imeis.py index 691aa53..bc62e3f 100644 --- a/tests/test_set_00_invoice_05_imeis.py +++ b/tests/test_set_00_invoice_05_imeis.py @@ -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(): diff --git a/tests/test_set_06_invoice_only.py b/tests/test_set_06_invoice_only.py index fb88b24..f709090 100644 --- a/tests/test_set_06_invoice_only.py +++ b/tests/test_set_06_invoice_only.py @@ -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) \ No newline at end of file diff --git a/tests/test_set_07_01_invoice_06_imei.py b/tests/test_set_07_01_invoice_06_imei.py index 6642199..c283128 100644 --- a/tests/test_set_07_01_invoice_06_imei.py +++ b/tests/test_set_07_01_invoice_06_imei.py @@ -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}" \ No newline at end of file + assert "Limit reached. Number of imei_file limit at 2" in str(data["data"]) diff --git a/tests/test_set_21_to_25.py b/tests/test_set_21_to_25.py index 25e08c9..bdb7b91 100644 --- a/tests/test_set_21_to_25.py +++ b/tests/test_set_21_to_25.py @@ -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}"