Skip to content

Commit b7b8184

Browse files
authored
Merge pull request #154 from XeroAPI/PETOSS-559-Replace-existing-tests-in-python-using-Prism
PETOSS-559 replace existing tests in python using prism
2 parents 536904b + 407cbd9 commit b7b8184

File tree

1 file changed

+83
-62
lines changed

1 file changed

+83
-62
lines changed

tests/accounting/api/test_accounting_api.py

Lines changed: 83 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
Attachment,
3232
)
3333
from xero_python.api_client import ApiClient
34+
from xero_python.assets import Pagination
3435
from xero_python.rest import RESTClientObject
3536

3637

@@ -43,7 +44,7 @@ def accounting_api(api_client):
4344
def sandbox_accounting_api(api_client):
4445
return AccountingApi(
4546
api_client=api_client,
46-
base_url="https://25faf04a-c71e-40e7-b7ce-f1fae0149465.mock.pstmn.io/api.xro/2.0",
47+
base_url="http://127.0.0.1:4010",
4748
)
4849

4950

@@ -339,31 +340,27 @@ def test_get_account_attachments(sandbox_accounting_api: AccountingApi, xero_ten
339340
def test_get_invoices(sandbox_accounting_api: AccountingApi, xero_tenant_id):
340341
# Given sandbox API, tenant id, and hardcoded test invoices data
341342
# When getting all invoices
342-
result = sandbox_accounting_api.get_invoices(xero_tenant_id)
343+
result: Invoices = sandbox_accounting_api.get_invoices(xero_tenant_id)
343344
# Then expect correct invoices received
344-
expected = Invoices(
345+
expected = Invoices (
345346
invoices=[
346347
Invoice(
347-
amount_credited=Decimal("0.00"),
348-
amount_due=Decimal("0.00"),
349-
amount_paid=Decimal("0.00"),
348+
amount_credited = Decimal(0),
349+
amount_due = Decimal(0),
350+
amount_paid= Decimal(0),
350351
contact=Contact(
352+
addresses=[],
353+
contact_groups=[],
351354
contact_id="a3675fc4-f8dd-4f03-ba5b-f1870566bcd7",
355+
contact_persons=[],
352356
has_attachments=False,
353357
has_validation_errors=False,
354358
name="Barney Rubble-83203",
355-
addresses=[],
356-
contact_groups=[],
357-
contact_persons=[],
358359
phones=[],
359360
),
360361
credit_notes=[],
361-
line_items=[],
362-
overpayments=[],
363-
payments=[],
364-
prepayments=[],
365362
currency_code=CurrencyCode.NZD,
366-
currency_rate=Decimal("1.000000"),
363+
currency_rate=Decimal(1),
367364
date=datetime.date(2018, 10, 20),
368365
due_date=datetime.date(2018, 12, 30),
369366
has_attachments=False,
@@ -372,38 +369,37 @@ def test_get_invoices(sandbox_accounting_api: AccountingApi, xero_tenant_id):
372369
invoice_number="INV-0001",
373370
is_discounted=False,
374371
line_amount_types=LineAmountTypes.EXCLUSIVE,
372+
line_items=[],
373+
overpayments=[],
374+
payments=[],
375+
prepayments=[],
375376
reference="Red Fish, Blue Fish",
376377
repeating_invoice_id="428c0d75-909f-4b04-8403-a48dc27283b0",
377378
sent_to_contact=True,
378379
status="VOIDED",
379-
sub_total=Decimal("40.00"),
380-
total=Decimal("40.00"),
381-
total_tax=Decimal("0.00"),
380+
sub_total=Decimal(40),
381+
total=Decimal(40),
382+
total_tax=Decimal(0),
382383
type="ACCREC",
383-
updated_date_utc=datetime.datetime(
384-
2018, 11, 2, 16, 31, 30, 160000, tzinfo=tz.UTC
385-
),
384+
updated_date_utc=datetime.datetime(2018, 11, 2, 16, 31, 30, 160000, tzinfo=tz.UTC),
386385
),
387386
Invoice(
388-
amount_credited=Decimal("0.00"),
389-
amount_due=Decimal("0.00"),
390-
amount_paid=Decimal("46.00"),
387+
amount_credited=Decimal(0),
388+
amount_due=Decimal(0),
389+
amount_paid=Decimal(46),
391390
contact=Contact(
391+
addresses=[],
392+
contact_groups=[],
392393
contact_id="a3675fc4-f8dd-4f03-ba5b-f1870566bcd7",
394+
contact_persons=[],
393395
has_attachments=False,
394396
has_validation_errors=False,
395397
name="Barney Rubble-83203",
396-
addresses=[],
397-
contact_groups=[],
398-
contact_persons=[],
399398
phones=[],
400399
),
401400
credit_notes=[],
402-
line_items=[],
403-
overpayments=[],
404-
prepayments=[],
405401
currency_code=CurrencyCode.NZD,
406-
currency_rate=Decimal("1.000000"),
402+
currency_rate=Decimal(1),
407403
date=datetime.date(2018, 10, 20),
408404
due_date=datetime.date(2018, 12, 30),
409405
fully_paid_on_date=datetime.date(2018, 11, 29),
@@ -413,70 +409,75 @@ def test_get_invoices(sandbox_accounting_api: AccountingApi, xero_tenant_id):
413409
invoice_number="INV-0002",
414410
is_discounted=False,
415411
line_amount_types=LineAmountTypes.EXCLUSIVE,
412+
line_items=[],
413+
overpayments=[],
416414
payments=[
417415
Payment(
418-
amount=Decimal("46.00"),
419-
currency_rate=Decimal("1.000000"),
416+
amount=Decimal(46),
417+
currency_rate=Decimal(1),
420418
date=datetime.date(2018, 11, 29),
421419
has_account=False,
422420
has_validation_errors=False,
423421
payment_id="99ea7f6b-c513-4066-bc27-b7c65dcd76c2",
424422
)
425-
],
423+
],
424+
prepayments=[],
426425
reference="Red Fish, Blue Fish",
426+
#repeating_invoice_id="428c0d75-909f-4b04-8403-a48dc27283b0",
427427
sent_to_contact=True,
428428
status="PAID",
429-
sub_total=Decimal("40.00"),
430-
total=Decimal("46.00"),
431-
total_tax=Decimal("6.00"),
429+
sub_total=Decimal(40),
430+
total=Decimal(46),
431+
total_tax=Decimal(6),
432432
type="ACCREC",
433-
updated_date_utc=datetime.datetime(
434-
2018, 11, 2, 16, 36, 32, 690000, tzinfo=tz.UTC
435-
),
433+
updated_date_utc=datetime.datetime(2018, 11, 2, 16, 36, 32, 690000, tzinfo=tz.UTC),
436434
),
437435
Invoice(
438-
amount_credited=Decimal("0.00"),
439-
amount_due=Decimal("115.00"),
440-
amount_paid=Decimal("0.00"),
436+
amount_credited=Decimal(0),
437+
amount_due=Decimal(115),
438+
amount_paid=Decimal(0),
441439
contact=Contact(
440+
addresses=[],
441+
contact_groups=[],
442442
contact_id="a3675fc4-f8dd-4f03-ba5b-f1870566bcd7",
443+
contact_persons=[],
443444
has_attachments=False,
444445
has_validation_errors=False,
445446
name="Barney Rubble-83203",
446-
addresses=[],
447-
contact_groups=[],
448-
contact_persons=[],
449447
phones=[],
450448
),
451449
credit_notes=[],
452-
line_items=[],
453-
overpayments=[],
454-
payments=[],
455-
prepayments=[],
456450
currency_code=CurrencyCode.NZD,
457-
currency_rate=Decimal("1.000000"),
451+
currency_rate=Decimal(1),
458452
date=datetime.date(2018, 11, 2),
459453
due_date=datetime.date(2018, 11, 7),
460454
has_attachments=False,
461455
has_errors=False,
462-
invoice_id="7ef31b20-de17-4312-8382-412f869b1510",
463456
invoice_number="INV-0003",
457+
invoice_id="7ef31b20-de17-4312-8382-412f869b1510",
464458
is_discounted=False,
465459
line_amount_types=LineAmountTypes.EXCLUSIVE,
460+
line_items=[],
461+
overpayments=[],
462+
payments=[],
463+
prepayments=[],
466464
reference="",
467465
status="AUTHORISED",
468-
sub_total=Decimal("100.00"),
469-
total=Decimal("115.00"),
470-
total_tax=Decimal("15.00"),
466+
sub_total=Decimal(100),
467+
total=Decimal(115),
468+
total_tax=Decimal(15),
471469
type="ACCREC",
472-
updated_date_utc=datetime.datetime(
473-
2018, 11, 2, 16, 37, 28, 927000, tzinfo=tz.UTC
474-
),
475-
),
470+
updated_date_utc=datetime.datetime(2018, 11, 2, 16, 37, 28, 927000, tzinfo=tz.UTC)
471+
)
476472
],
473+
pagination= Pagination(
474+
item_count= 3,
475+
page = 1,
476+
page_count= 1,
477+
page_size= 100
478+
)
477479
)
478-
assert result == expected
479-
480+
assert str(result) == str(expected)
480481

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

491507

@@ -647,7 +663,12 @@ def test_create_invoice_history(sandbox_accounting_api: AccountingApi, xero_tena
647663
xero_tenant_id, invoice_id, history_records
648664
)
649665
# Then expect created invoice history records
650-
expected = HistoryRecords() # todo confirm empty response from sandbox is correct
666+
expected = HistoryRecords(
667+
[HistoryRecord(
668+
date_utc=datetime.datetime(2019, 2, 23, 5, 23, 20, 362000, tzinfo=tz.UTC),
669+
details="Hello World"
670+
)]
671+
)
651672
assert result == expected
652673

653674

0 commit comments

Comments
 (0)