• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

chift-oneapi / chift-python-sdk / 7666915815

26 Jan 2024 10:18AM UTC coverage: 98.637%. First build
7666915815

push

github

hhertoghe
reformat

3112 of 3155 relevant lines covered (98.64%)

0.99 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

92.86
/tests/test_invoicing.py
1
import datetime
1✔
2
import uuid
1✔
3

4
import pytest
1✔
5

6
from chift.api.exceptions import ChiftException
1✔
7
from chift.openapi.models import Consumer
1✔
8

9

10
def create_contact(consumer: Consumer):
1✔
11
    name = str(uuid.uuid1())
1✔
12
    data = {
1✔
13
        "first_name": name,
14
        "addresses": [
15
            {
16
                "address_type": "main",
17
                "street": "street",
18
                "city": "city",
19
                "postal_code": "postal_code",
20
                "country": "BE",
21
            }
22
        ],
23
    }
24
    return consumer.invoicing.Contact.create(data)
1✔
25

26

27
def test_contact(evoliz_consumer: Consumer):
1✔
28
    consumer = evoliz_consumer
1✔
29

30
    expected_contact = create_contact(consumer)
1✔
31

32
    assert expected_contact.id, "create() failed"
1✔
33

34
    # find it back with its id
35
    actual_contact = consumer.invoicing.Contact.get(str(expected_contact.id))
1✔
36

37
    assert expected_contact == actual_contact, "get() failed"
1✔
38

39

40
def test_contacts(evoliz_consumer: Consumer):
1✔
41
    consumer = evoliz_consumer
1✔
42

43
    contacts = consumer.invoicing.Contact.all(limit=2)
1✔
44

45
    assert contacts
1✔
46

47
    for contact in contacts:
1✔
48
        assert contact.id
1✔
49

50

51
def test_invoice(evoliz_consumer: Consumer):
1✔
52
    consumer = evoliz_consumer
1✔
53

54
    # find contact required in invoice
55
    contact = create_contact(consumer)
1✔
56

57
    # create invoice
58
    data = {
1✔
59
        "invoice_type": "customer_invoice",
60
        "invoice_number": str(uuid.uuid1()),
61
        "partner_id": str(contact.id),
62
        "status": "draft",
63
        "currency": "EUR",
64
        "invoice_date": datetime.date.today().strftime("%Y-%m-%d"),
65
        "tax_amount": 100,
66
        "untaxed_amount": 100,
67
        "total": 100,
68
        "lines": [
69
            {
70
                "product_code": "123",
71
                "description": "desc",
72
                "quantity": 1,
73
                "unit_price": 100,
74
                "tax_amount": 100,
75
                "total": 100,
76
                "untaxed_amount": 100,
77
                "tax_rate": 10.0,
78
            }
79
        ],
80
    }
81

82
    expected_invoice = consumer.invoicing.Invoice.create(data)
1✔
83

84
    assert expected_invoice.partner_id == contact.id, "create() failed"
1✔
85
    assert expected_invoice.invoice_type.value == "customer_invoice", "create() failed"
1✔
86

87
    # find it back with its id
88
    actual_invoice = consumer.invoicing.Invoice.get(str(expected_invoice.id))
1✔
89

90
    assert expected_invoice == actual_invoice, "get() failed"
1✔
91

92

93
def test_invoices(evoliz_consumer: Consumer):
1✔
94
    consumer = evoliz_consumer
1✔
95

96
    invoices = consumer.invoicing.Invoice.all(
1✔
97
        {"invoice_type": "customer_invoice"}, limit=2
98
    )
99

100
    assert invoices
1✔
101

102
    for invoice in invoices:
1✔
103
        assert invoice.id
1✔
104

105

106
def test_product(evoliz_consumer: Consumer):
1✔
107
    consumer = evoliz_consumer
1✔
108

109
    # create product
110
    data = {
1✔
111
        "code": str(uuid.uuid1())[:20],
112
        "name": str(uuid.uuid1()),
113
        "unit": "U",
114
        "unit_price": 100,
115
    }
116

117
    expected_product = consumer.invoicing.Product.create(data)
1✔
118

119
    assert expected_product.id, "create() failed"
1✔
120

121
    # find it back with its id
122
    actual_product = consumer.invoicing.Product.get(str(expected_product.id))
1✔
123

124
    assert expected_product.id == actual_product.id, "get() failed"
1✔
125
    assert expected_product.name == actual_product.name, "get() failed"
1✔
126

127

128
def test_products(evoliz_consumer: Consumer):
1✔
129
    consumer = evoliz_consumer
1✔
130

131
    products = consumer.invoicing.Product.all(limit=2)
1✔
132

133
    assert products
1✔
134

135
    for product in products:
1✔
136
        assert product.id
1✔
137

138

139
def test_tax(evoliz_consumer: Consumer):
1✔
140
    consumer = evoliz_consumer
1✔
141

142
    taxes = consumer.invoicing.Tax.all()
1✔
143

144
    expected_tax = taxes[0]
1✔
145

146
    actual_tax = consumer.invoicing.Tax.get(expected_tax.id)
1✔
147

148
    assert expected_tax == actual_tax, "get() failed"
1✔
149

150

151
def test_opportunity(evoliz_consumer: Consumer):
1✔
152
    consumer = evoliz_consumer
1✔
153

154
    with pytest.raises(ChiftException) as e:
1✔
155
        consumer.invoicing.Opportunity.all()
1✔
156

157
    assert e.value.message == "API Resource does not exist"
1✔
158

159

160
def test_custom(evoliz_consumer: Consumer):
1✔
161
    consumer = evoliz_consumer
1✔
162

163
    cashes = consumer.invoicing.Custom.all("cashes")
1✔
164
    # TODO: sometimes there is no cashes
165
    # assert cashes
166

167
    for cashe in cashes[:1]:  # 1 is enough
1✔
168
        entries = consumer.invoicing.Custom.all(f"cashes/{cashe.get('cashid')}/entries")
×
169
        assert entries
×
170

171
        with pytest.raises(ChiftException) as e:
×
172
            consumer.invoicing.Custom.create(
×
173
                f"cashes/{cashe.get('cashid')}/entries", {"ok": "ok"}
174
            )
175

176
        assert "was not created" in e.value.message
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc