|
|
|
""" Stub file for testing the project
|
|
|
|
|
|
|
|
There are three predefined ways to run tests:
|
|
|
|
|
|
|
|
make test:
|
|
|
|
runs only unit tests, that are not marked with "fun" (for functional test)
|
|
|
|
in a random order. If a test failed before, only the failed tests will be
|
|
|
|
run. This is intended to be the default testing method while developing.
|
|
|
|
|
|
|
|
make testall:
|
|
|
|
runs unit tests and functional tests in random order. Will give a complete
|
|
|
|
overview of the test suite.
|
|
|
|
|
|
|
|
make coverage:
|
|
|
|
runs only tests marked with "fun" (for functional tests) and generates a
|
|
|
|
coverage report for the test run. The idea is to check the test coverage
|
|
|
|
only on functinal tests to see if a) everything is as much covered as
|
|
|
|
possible and b) to find dead code that is not called in end-to-end tests.
|
|
|
|
|
|
|
|
all three test strategies will run "make lint" before to catch easily made
|
|
|
|
mistakes.
|
|
|
|
"""
|
|
|
|
|
|
|
|
import pytest
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
def root_dir(request):
|
|
|
|
import pathlib
|
|
|
|
|
|
|
|
return pathlib.Path(request.path).parent
|
|
|
|
|
|
|
|
|
|
|
|
def test_open_file(root_dir):
|
|
|
|
from bs4 import BeautifulSoup
|
|
|
|
|
|
|
|
from xinvoice import open_invoice
|
|
|
|
|
|
|
|
result = open_invoice(root_dir / "carl-roth-1.xml")
|
|
|
|
|
|
|
|
assert isinstance(result, BeautifulSoup)
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
|
|
"file_name, recipient", [("carl-roth-1.xml", "Calvino")]
|
|
|
|
)
|
|
|
|
def test_get_recipient_with_name(root_dir, file_name, recipient):
|
|
|
|
from xinvoice import open_invoice, get_recipient
|
|
|
|
|
|
|
|
soup = open_invoice(root_dir / file_name)
|
|
|
|
|
|
|
|
result = get_recipient(soup)
|
|
|
|
|
|
|
|
assert recipient in result
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize("file_name", ["fisher-1.xml"])
|
|
|
|
def test_get_recipient_without_name(root_dir, file_name):
|
|
|
|
from xinvoice import open_invoice, get_recipient
|
|
|
|
|
|
|
|
soup = open_invoice(root_dir / file_name)
|
|
|
|
|
|
|
|
result = get_recipient(soup)
|
|
|
|
|
|
|
|
assert result is None
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
|
|
"file_name, expected_items",
|
|
|
|
[
|
|
|
|
("carl-roth-1.xml", ["Schwefelsäure 96 %"]),
|
|
|
|
("fisher-1.xml", ["MTT, 1g, (3(4,5dimethylthiazol2yl) 2,"]),
|
|
|
|
],
|
|
|
|
)
|
|
|
|
def test_get_items(root_dir, file_name, expected_items):
|
|
|
|
from xinvoice import get_items, open_invoice
|
|
|
|
|
|
|
|
soup = open_invoice(root_dir / file_name)
|
|
|
|
|
|
|
|
result = get_items(soup)
|
|
|
|
|
|
|
|
assert result == expected_items
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
|
|
"file_name, expected_name",
|
|
|
|
[
|
|
|
|
("carl-roth-1.xml", "Céline"),
|
|
|
|
("fisher-1.xml", "+++ UNKNOWN +++"),
|
|
|
|
],
|
|
|
|
)
|
|
|
|
def test_get_recipient_short_name(root_dir, file_name, expected_name):
|
|
|
|
from xinvoice import open_invoice, get_recipient_short_name
|
|
|
|
|
|
|
|
soup = open_invoice(root_dir / file_name)
|
|
|
|
|
|
|
|
result = get_recipient_short_name(soup)
|
|
|
|
|
|
|
|
assert result == expected_name
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
|
|
"file_name, expected_content",
|
|
|
|
[
|
|
|
|
("carl-roth-1.xml", ["Céline", "Schwefelsäure"]),
|
|
|
|
("fisher-1.xml", ["UNKNOWN", "MTT"]),
|
|
|
|
],
|
|
|
|
)
|
|
|
|
def test_parse(root_dir, file_name, expected_content):
|
|
|
|
from xinvoice import parse
|
|
|
|
|
|
|
|
result = parse(root_dir / file_name)
|
|
|
|
|
|
|
|
for part in expected_content:
|
|
|
|
assert part in result
|