Skip to content

Commit 2130ca9

Browse files
author
Vignesh Kennadi
committed
PETOSS-559 Replace existing tests in python SDK using Prism
1 parent 536904b commit 2130ca9

File tree

1 file changed

+85
-62
lines changed

1 file changed

+85
-62
lines changed

tests/accounting/api/test_accounting_api.py

Lines changed: 85 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
import filecmp
44
from decimal import Decimal
55
from pathlib import Path
6+
from pydoc import pager
67

78
import pytest
9+
from black import nullcontext
810
from dateutil import tz
911

1012
from xero_python.accounting import (
@@ -31,6 +33,7 @@
3133
Attachment,
3234
)
3335
from xero_python.api_client import ApiClient
36+
from xero_python.assets import Pagination
3437
from xero_python.rest import RESTClientObject
3538

3639

@@ -43,7 +46,7 @@ def accounting_api(api_client):
4346
def sandbox_accounting_api(api_client):
4447
return AccountingApi(
4548
api_client=api_client,
46-
base_url="https://25faf04a-c71e-40e7-b7ce-f1fae0149465.mock.pstmn.io/api.xro/2.0",
49+
base_url="http://127.0.0.1:4010",
4750
)
4851

4952

@@ -339,31 +342,27 @@ def test_get_account_attachments(sandbox_accounting_api: AccountingApi, xero_ten
339342
def test_get_invoices(sandbox_accounting_api: AccountingApi, xero_tenant_id):
340343
# Given sandbox API, tenant id, and hardcoded test invoices data
341344
# When getting all invoices
342-
result = sandbox_accounting_api.get_invoices(xero_tenant_id)
345+
result: Invoices = sandbox_accounting_api.get_invoices(xero_tenant_id)
343346
# Then expect correct invoices received
344-
expected = Invoices(
347+
expected = Invoices (
345348
invoices=[
346349
Invoice(
347-
amount_credited=Decimal("0.00"),
348-
amount_due=Decimal("0.00"),
349-
amount_paid=Decimal("0.00"),
350+
amount_credited = Decimal("0"),
351+
amount_due = Decimal("0"),
352+
amount_paid= Decimal("0"),
350353
contact=Contact(
354+
addresses=[],
355+
contact_groups=[],
351356
contact_id="a3675fc4-f8dd-4f03-ba5b-f1870566bcd7",
357+
contact_persons=[],
352358
has_attachments=False,
353359
has_validation_errors=False,
354360
name="Barney Rubble-83203",
355-
addresses=[],
356-
contact_groups=[],
357-
contact_persons=[],
358361
phones=[],
359362
),
360363
credit_notes=[],
361-
line_items=[],
362-
overpayments=[],
363-
payments=[],
364-
prepayments=[],
365364
currency_code=CurrencyCode.NZD,
366-
currency_rate=Decimal("1.000000"),
365+
currency_rate=Decimal(1),
367366
date=datetime.date(2018, 10, 20),
368367
due_date=datetime.date(2018, 12, 30),
369368
has_attachments=False,
@@ -372,38 +371,37 @@ def test_get_invoices(sandbox_accounting_api: AccountingApi, xero_tenant_id):
372371
invoice_number="INV-0001",
373372
is_discounted=False,
374373
line_amount_types=LineAmountTypes.EXCLUSIVE,
374+
line_items=[],
375+
overpayments=[],
376+
payments=[],
377+
prepayments=[],
375378
reference="Red Fish, Blue Fish",
376379
repeating_invoice_id="428c0d75-909f-4b04-8403-a48dc27283b0",
377380
sent_to_contact=True,
378381
status="VOIDED",
379-
sub_total=Decimal("40.00"),
380-
total=Decimal("40.00"),
381-
total_tax=Decimal("0.00"),
382+
sub_total=Decimal("40"),
383+
total=Decimal("40"),
384+
total_tax=Decimal("0"),
382385
type="ACCREC",
383-
updated_date_utc=datetime.datetime(
384-
2018, 11, 2, 16, 31, 30, 160000, tzinfo=tz.UTC
385-
),
386+
updated_date_utc=datetime.datetime(2018, 11, 2, 16, 31, 30, 160000, tzinfo=tz.UTC),
386387
),
387388
Invoice(
388-
amount_credited=Decimal("0.00"),
389-
amount_due=Decimal("0.00"),
390-
amount_paid=Decimal("46.00"),
389+
amount_credited=Decimal("0"),
390+
amount_due=Decimal("0"),
391+
amount_paid=Decimal("46"),
391392
contact=Contact(
393+
addresses=[],
394+
contact_groups=[],
392395
contact_id="a3675fc4-f8dd-4f03-ba5b-f1870566bcd7",
396+
contact_persons=[],
393397
has_attachments=False,
394398
has_validation_errors=False,
395399
name="Barney Rubble-83203",
396-
addresses=[],
397-
contact_groups=[],
398-
contact_persons=[],
399400
phones=[],
400401
),
401402
credit_notes=[],
402-
line_items=[],
403-
overpayments=[],
404-
prepayments=[],
405403
currency_code=CurrencyCode.NZD,
406-
currency_rate=Decimal("1.000000"),
404+
currency_rate=Decimal(1),
407405
date=datetime.date(2018, 10, 20),
408406
due_date=datetime.date(2018, 12, 30),
409407
fully_paid_on_date=datetime.date(2018, 11, 29),
@@ -413,70 +411,75 @@ def test_get_invoices(sandbox_accounting_api: AccountingApi, xero_tenant_id):
413411
invoice_number="INV-0002",
414412
is_discounted=False,
415413
line_amount_types=LineAmountTypes.EXCLUSIVE,
414+
line_items=[],
415+
overpayments=[],
416416
payments=[
417417
Payment(
418-
amount=Decimal("46.00"),
419-
currency_rate=Decimal("1.000000"),
418+
amount=Decimal("46"),
419+
currency_rate=Decimal(1),
420420
date=datetime.date(2018, 11, 29),
421421
has_account=False,
422422
has_validation_errors=False,
423423
payment_id="99ea7f6b-c513-4066-bc27-b7c65dcd76c2",
424424
)
425-
],
425+
],
426+
prepayments=[],
426427
reference="Red Fish, Blue Fish",
428+
#repeating_invoice_id="428c0d75-909f-4b04-8403-a48dc27283b0",
427429
sent_to_contact=True,
428430
status="PAID",
429-
sub_total=Decimal("40.00"),
430-
total=Decimal("46.00"),
431-
total_tax=Decimal("6.00"),
431+
sub_total=Decimal("40"),
432+
total=Decimal("46"),
433+
total_tax=Decimal("6"),
432434
type="ACCREC",
433-
updated_date_utc=datetime.datetime(
434-
2018, 11, 2, 16, 36, 32, 690000, tzinfo=tz.UTC
435-
),
435+
updated_date_utc=datetime.datetime(2018, 11, 2, 16, 36, 32, 690000, tzinfo=tz.UTC),
436436
),
437437
Invoice(
438-
amount_credited=Decimal("0.00"),
439-
amount_due=Decimal("115.00"),
440-
amount_paid=Decimal("0.00"),
438+
amount_credited=Decimal(0),
439+
amount_due=Decimal(115),
440+
amount_paid=Decimal("0"),
441441
contact=Contact(
442+
addresses=[],
443+
contact_groups=[],
442444
contact_id="a3675fc4-f8dd-4f03-ba5b-f1870566bcd7",
445+
contact_persons=[],
443446
has_attachments=False,
444447
has_validation_errors=False,
445448
name="Barney Rubble-83203",
446-
addresses=[],
447-
contact_groups=[],
448-
contact_persons=[],
449449
phones=[],
450450
),
451451
credit_notes=[],
452-
line_items=[],
453-
overpayments=[],
454-
payments=[],
455-
prepayments=[],
456452
currency_code=CurrencyCode.NZD,
457-
currency_rate=Decimal("1.000000"),
453+
currency_rate=Decimal(1),
458454
date=datetime.date(2018, 11, 2),
459455
due_date=datetime.date(2018, 11, 7),
460456
has_attachments=False,
461457
has_errors=False,
462-
invoice_id="7ef31b20-de17-4312-8382-412f869b1510",
463458
invoice_number="INV-0003",
459+
invoice_id="7ef31b20-de17-4312-8382-412f869b1510",
464460
is_discounted=False,
465461
line_amount_types=LineAmountTypes.EXCLUSIVE,
462+
line_items=[],
463+
overpayments=[],
464+
payments=[],
465+
prepayments=[],
466466
reference="",
467467
status="AUTHORISED",
468-
sub_total=Decimal("100.00"),
469-
total=Decimal("115.00"),
470-
total_tax=Decimal("15.00"),
468+
sub_total=Decimal("100"),
469+
total=Decimal("115"),
470+
total_tax=Decimal("15"),
471471
type="ACCREC",
472-
updated_date_utc=datetime.datetime(
473-
2018, 11, 2, 16, 37, 28, 927000, tzinfo=tz.UTC
474-
),
475-
),
472+
updated_date_utc=datetime.datetime(2018, 11, 2, 16, 37, 28, 927000, tzinfo=tz.UTC)
473+
)
476474
],
475+
pagination= Pagination(
476+
item_count= 3,
477+
page = 1,
478+
page_count= 1,
479+
page_size= 100
480+
)
477481
)
478-
assert result == expected
479-
482+
assert str(result) == str(expected)
480483

481484
@pytest.mark.sandbox
482485
def test_get_invoice_history(sandbox_accounting_api: AccountingApi, xero_tenant_id):
@@ -485,7 +488,22 @@ def test_get_invoice_history(sandbox_accounting_api: AccountingApi, xero_tenant_
485488
# When getting invoice history
486489
result = sandbox_accounting_api.get_invoice_history(xero_tenant_id, invoice_id)
487490
# Then expect invoice history to be received
488-
expected = HistoryRecords() # todo confirm empty response from sandbox is correct
491+
expected = HistoryRecords(
492+
[
493+
HistoryRecord(
494+
changes="Attached a file",
495+
date_utc= datetime.datetime(2018, 11, 8, 15, 1, 21, 470000, tzinfo=tz.UTC),
496+
details= "Attached the file sample2.jpg through the Xero API using Xero API Partner",
497+
user="System Generated",
498+
),
499+
HistoryRecord(
500+
changes="Credit Applied",
501+
date_utc=datetime.datetime(2016, 10, 17, 20, 46, 1, 173000, tzinfo=tz.UTC),
502+
details="Bank transfer from Business Wells Fargo to My Savings on November 12, 2016 for 20.00.",
503+
user="System Generated",
504+
)
505+
]
506+
)
489507
assert result == expected
490508

491509

@@ -647,7 +665,12 @@ def test_create_invoice_history(sandbox_accounting_api: AccountingApi, xero_tena
647665
xero_tenant_id, invoice_id, history_records
648666
)
649667
# Then expect created invoice history records
650-
expected = HistoryRecords() # todo confirm empty response from sandbox is correct
668+
expected = HistoryRecords(
669+
[HistoryRecord(
670+
date_utc=datetime.datetime(2019, 2, 23, 5, 23, 20, 362000, tzinfo=tz.UTC),
671+
details="Hello World"
672+
)]
673+
)
651674
assert result == expected
652675

653676

0 commit comments

Comments
 (0)