def test_invoice_has_default_payment_date(): from datetime import date, timedelta pay_date = date.today() + timedelta(14) task = parse(INVOICE_YAML) invoice = task["invoice"] assert pay_date == invoice.payment_date
def test_parser_parses_customer(): task = parse(INVOICE_YAML) invoice = task["invoice"] assert { "id": "Klient Widmo", "tax_id": "0000000000", "prefix": "PL", } == invoice.known_customer
def test_parser_parses_positions(): task = parse(INVOICE_YAML) invoice = task["invoice"] [_p1, p2] = invoice.positions assert p2.full_name == "Kolejna drozsza od 👆 o tej" assert p2.base_price == 9.99 assert p2.unit == "szt" assert p2.quantity == 1
def test_simple_invoice_without_ban_and_comments(): simple_invoice = """ known_customer: name: Klient Widmo tax_id: '0000000000' positions: - name: Waciki amount: 100.00 """ task = parse(simple_invoice) invoice = task["invoice"] assert None == invoice.bank_account_no assert None == invoice.comments
def test_simple_invoice_with_issue_date(): from datetime import date simple_invoice = """ issue_date: 2020-06-19 known_customer: name: Klient Widmo tax_id: '0000000000' positions: - name: Waciki amount: 100.00 """ task = parse(simple_invoice) invoice = task["invoice"] assert date(2020, 6, 19) == invoice.issue_date
def test_simple_invoice_with_flat_rate(): from datetime import date simple_invoice = """ issue_date: 2020-06-19 known_customer: name: Klient Widmo tax_id: '0000000000' positions: - name: Waciki amount: 100.00 flat_rate: 0.085 """ task = parse(simple_invoice) invoice = task["invoice"] [position] = invoice.positions assert 0.085 == position.flat_rate
module_path = os.path.dirname(os.path.dirname(script_path)) sys.path.append(module_path) print("Module path: " + module_path) from ifirma.yaml_parser import parse import ifirma.api as Api if __name__ == "__main__": if len(sys.argv) == 1 or not sys.argv[1].strip(): sys.exit('Provide a yaml file name containing the invoice') else: filename = sys.argv[1] print('Reading file: ' + filename) with open(filename) as f: task = parse(f) create_invoice_response = Api.create_invoice(task['invoice']) print(f'Invoice created successfully {create_invoice_response}') invoice_id = create_invoice_response.invoice_id if create_invoice_response.success and (email_address := task.get('send_to')): email_send_response = Api.email_invoice(invoice_id, email_address, task['message']) print(f'Email sent {email_send_response}') if create_invoice_response.success and (download_dir := task.get('download')): download_path = Path(download_dir) / f"invoice_{invoice_id}.pdf" Api.download_invoice(invoice_id, download_path)
def test_invoice_has_todays_issue_date(): from datetime import date task = parse(INVOICE_YAML) invoice = task["invoice"] assert date.today() == invoice.issue_date
def test_parser_parses_issuer(): task = parse(INVOICE_YAML) invoice = task["invoice"] assert "Jan Nowak" == invoice.issuer
def test_parser_parses_issue_place(): task = parse(INVOICE_YAML) invoice = task["invoice"] assert "Krychnowice" == invoice.issue_place
def test_parser_parses_comment(): task = parse(INVOICE_YAML) invoice = task["invoice"] assert "FakturÄ™ tÄ™ komentujÄ™ jÄ…" == invoice.comments
def test_parser_parses_ban(): task = parse(INVOICE_YAML) invoice = task["invoice"] assert "00000000000000000000000000000000" == invoice.bank_account_no
def test_parser_parses_positions_smoke(): task = parse(INVOICE_YAML) invoice = task["invoice"] assert 2 == len(invoice.positions)
def test_parser_returns_invoice(): task = parse(INVOICE_YAML) assert "invoice" in task.keys() assert isinstance(task["invoice"], Invoice)
def test_invoice_with_download_path(): task = parse(INVOICE_YAML + DOWNLOAD_INVOICE_YAML) assert task["download"] == "/home/me/invoices"
def test_sending_invoice_by_email(): task = parse(INVOICE_YAML + SEND_EMAIL_YAML) email = task["send_to"] assert email == "*****@*****.**"