-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathtest_url_input_source_integration.py
More file actions
68 lines (49 loc) · 2.11 KB
/
test_url_input_source_integration.py
File metadata and controls
68 lines (49 loc) · 2.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import os
from pathlib import Path
import pytest
from mindee import Client
from mindee.product.invoice import InvoiceV4
@pytest.fixture
def client():
return Client()
@pytest.fixture
def output_file_path():
return Path("tests/data/output/")
@pytest.fixture
def reference_file_path():
return "https://github.com/mindee/client-lib-test-data/blob/main/v1/products/invoice_splitter/invoice_5p.pdf?raw=true"
@pytest.mark.integration
def test_load_local_file(client, reference_file_path):
url_source = client.source_from_url(reference_file_path)
local_source = url_source.as_local_input_source()
result = client.parse(InvoiceV4, local_source)
assert result.document.n_pages == 5
assert result.document.filename == "invoice_5p.pdf"
@pytest.mark.integration
def test_custom_file_name(client, reference_file_path):
url_source = client.source_from_url(reference_file_path)
local_source = url_source.as_local_input_source("customName.pdf")
result = client.parse(InvoiceV4, local_source)
assert result.document.n_pages == 5
assert result.document.filename == "customName.pdf"
@pytest.mark.integration
def test_save_file(client, reference_file_path, output_file_path):
url_source = client.source_from_url(reference_file_path)
url_source.save_to_file(output_file_path)
assert os.path.exists(os.path.join(output_file_path, "invoice_5p.pdf"))
@pytest.mark.integration
def test_save_file_with_filename(client, reference_file_path, output_file_path):
url_source = client.source_from_url(reference_file_path)
url_source.save_to_file(output_file_path, "customFileName.pdf")
assert os.path.exists(os.path.join(output_file_path, "customFileName.pdf"))
@pytest.fixture(autouse=True)
def cleanup(request, output_file_path: Path):
def remove_test_files():
generated_files = [
Path.resolve(output_file_path / "invoice_5p.pdf"),
Path.resolve(output_file_path / "customFileName.pdf"),
]
for filepath in generated_files:
if os.path.exists(filepath):
os.remove(filepath)
request.addfinalizer(remove_test_files)