sbt-idp/tests/test_set_00_invoice_05_imeis.py
2023-12-26 15:58:44 +07:00

148 lines
4.9 KiB
Python

import sys
sys.path.append(".")
from tests.utils import login, make_sbt_request, get_field
import os
import logging
HOST = os.environ.get("IDP_HOST", "XXXXXXXXXXXXXXXXXXXXX")
USERNAME = os.environ.get("IDP_USERNAME", "XXXXXXXXXXXXXXXXXXXXX")
PASSWORD = os.environ.get("IDP_PASSWORD", "XXXXXXXXXXXXXXXXXXXXX")
token = login(HOST, USERNAME, PASSWORD)
def check_invoice_data(document):
assert document["doc_type"] == "sbt_document"
assert get_field(document, "retailername") == "Arrow Communication"
assert get_field(document, "sold_to_party") is None
assert "2021-02-09" in get_field(document, "purchase_date")
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_1_invoice_1_imei():
invoice_files = [
"test_samples/sbt/invoice.jpg"
]
imei_files = [
"test_samples/sbt/imei1.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"] == 2
assert data["ocr_num_pages"] == 2
assert data["status"] == 200
document = data["document"][0]
assert document["end_page"] == 2
assert document["start_page"] == 1
check_invoice_data(document)
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)
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)
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)
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)
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)
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
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():
invoice_files = [
"test_samples/sbt/20220303025923NHNE_20220222_Starhub_Order_Confirmation_by_Email.pdf"
]
imei_files = [
"test_samples/sbt/imei1.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"] == 2
assert data["ocr_num_pages"] == 2
assert data["status"] == 200
document = data["document"][0]
assert document["end_page"] == 2
assert document["start_page"] == 1
check_invoice_data_2(document)
assert "358975990917032" == get_field(document, "imei_number")[0]