31
31
Attachment ,
32
32
)
33
33
from xero_python .api_client import ApiClient
34
+ from xero_python .assets import Pagination
34
35
from xero_python .rest import RESTClientObject
35
36
36
37
@@ -43,7 +44,7 @@ def accounting_api(api_client):
43
44
def sandbox_accounting_api (api_client ):
44
45
return AccountingApi (
45
46
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 " ,
47
48
)
48
49
49
50
@@ -339,31 +340,27 @@ def test_get_account_attachments(sandbox_accounting_api: AccountingApi, xero_ten
339
340
def test_get_invoices (sandbox_accounting_api : AccountingApi , xero_tenant_id ):
340
341
# Given sandbox API, tenant id, and hardcoded test invoices data
341
342
# 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 )
343
344
# Then expect correct invoices received
344
- expected = Invoices (
345
+ expected = Invoices (
345
346
invoices = [
346
347
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 ),
350
351
contact = Contact (
352
+ addresses = [],
353
+ contact_groups = [],
351
354
contact_id = "a3675fc4-f8dd-4f03-ba5b-f1870566bcd7" ,
355
+ contact_persons = [],
352
356
has_attachments = False ,
353
357
has_validation_errors = False ,
354
358
name = "Barney Rubble-83203" ,
355
- addresses = [],
356
- contact_groups = [],
357
- contact_persons = [],
358
359
phones = [],
359
360
),
360
361
credit_notes = [],
361
- line_items = [],
362
- overpayments = [],
363
- payments = [],
364
- prepayments = [],
365
362
currency_code = CurrencyCode .NZD ,
366
- currency_rate = Decimal ("1.000000" ),
363
+ currency_rate = Decimal (1 ),
367
364
date = datetime .date (2018 , 10 , 20 ),
368
365
due_date = datetime .date (2018 , 12 , 30 ),
369
366
has_attachments = False ,
@@ -372,38 +369,37 @@ def test_get_invoices(sandbox_accounting_api: AccountingApi, xero_tenant_id):
372
369
invoice_number = "INV-0001" ,
373
370
is_discounted = False ,
374
371
line_amount_types = LineAmountTypes .EXCLUSIVE ,
372
+ line_items = [],
373
+ overpayments = [],
374
+ payments = [],
375
+ prepayments = [],
375
376
reference = "Red Fish, Blue Fish" ,
376
377
repeating_invoice_id = "428c0d75-909f-4b04-8403-a48dc27283b0" ,
377
378
sent_to_contact = True ,
378
379
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 ),
382
383
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 ),
386
385
),
387
386
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 ),
391
390
contact = Contact (
391
+ addresses = [],
392
+ contact_groups = [],
392
393
contact_id = "a3675fc4-f8dd-4f03-ba5b-f1870566bcd7" ,
394
+ contact_persons = [],
393
395
has_attachments = False ,
394
396
has_validation_errors = False ,
395
397
name = "Barney Rubble-83203" ,
396
- addresses = [],
397
- contact_groups = [],
398
- contact_persons = [],
399
398
phones = [],
400
399
),
401
400
credit_notes = [],
402
- line_items = [],
403
- overpayments = [],
404
- prepayments = [],
405
401
currency_code = CurrencyCode .NZD ,
406
- currency_rate = Decimal ("1.000000" ),
402
+ currency_rate = Decimal (1 ),
407
403
date = datetime .date (2018 , 10 , 20 ),
408
404
due_date = datetime .date (2018 , 12 , 30 ),
409
405
fully_paid_on_date = datetime .date (2018 , 11 , 29 ),
@@ -413,70 +409,75 @@ def test_get_invoices(sandbox_accounting_api: AccountingApi, xero_tenant_id):
413
409
invoice_number = "INV-0002" ,
414
410
is_discounted = False ,
415
411
line_amount_types = LineAmountTypes .EXCLUSIVE ,
412
+ line_items = [],
413
+ overpayments = [],
416
414
payments = [
417
415
Payment (
418
- amount = Decimal ("46.00" ),
419
- currency_rate = Decimal ("1.000000" ),
416
+ amount = Decimal (46 ),
417
+ currency_rate = Decimal (1 ),
420
418
date = datetime .date (2018 , 11 , 29 ),
421
419
has_account = False ,
422
420
has_validation_errors = False ,
423
421
payment_id = "99ea7f6b-c513-4066-bc27-b7c65dcd76c2" ,
424
422
)
425
- ],
423
+ ],
424
+ prepayments = [],
426
425
reference = "Red Fish, Blue Fish" ,
426
+ #repeating_invoice_id="428c0d75-909f-4b04-8403-a48dc27283b0",
427
427
sent_to_contact = True ,
428
428
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 ),
432
432
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 ),
436
434
),
437
435
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 ),
441
439
contact = Contact (
440
+ addresses = [],
441
+ contact_groups = [],
442
442
contact_id = "a3675fc4-f8dd-4f03-ba5b-f1870566bcd7" ,
443
+ contact_persons = [],
443
444
has_attachments = False ,
444
445
has_validation_errors = False ,
445
446
name = "Barney Rubble-83203" ,
446
- addresses = [],
447
- contact_groups = [],
448
- contact_persons = [],
449
447
phones = [],
450
448
),
451
449
credit_notes = [],
452
- line_items = [],
453
- overpayments = [],
454
- payments = [],
455
- prepayments = [],
456
450
currency_code = CurrencyCode .NZD ,
457
- currency_rate = Decimal ("1.000000" ),
451
+ currency_rate = Decimal (1 ),
458
452
date = datetime .date (2018 , 11 , 2 ),
459
453
due_date = datetime .date (2018 , 11 , 7 ),
460
454
has_attachments = False ,
461
455
has_errors = False ,
462
- invoice_id = "7ef31b20-de17-4312-8382-412f869b1510" ,
463
456
invoice_number = "INV-0003" ,
457
+ invoice_id = "7ef31b20-de17-4312-8382-412f869b1510" ,
464
458
is_discounted = False ,
465
459
line_amount_types = LineAmountTypes .EXCLUSIVE ,
460
+ line_items = [],
461
+ overpayments = [],
462
+ payments = [],
463
+ prepayments = [],
466
464
reference = "" ,
467
465
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 ),
471
469
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
+ )
476
472
],
473
+ pagination = Pagination (
474
+ item_count = 3 ,
475
+ page = 1 ,
476
+ page_count = 1 ,
477
+ page_size = 100
478
+ )
477
479
)
478
- assert result == expected
479
-
480
+ assert str (result ) == str (expected )
480
481
481
482
@pytest .mark .sandbox
482
483
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_
485
486
# When getting invoice history
486
487
result = sandbox_accounting_api .get_invoice_history (xero_tenant_id , invoice_id )
487
488
# 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
+ )
489
505
assert result == expected
490
506
491
507
@@ -647,7 +663,12 @@ def test_create_invoice_history(sandbox_accounting_api: AccountingApi, xero_tena
647
663
xero_tenant_id , invoice_id , history_records
648
664
)
649
665
# 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
+ )
651
672
assert result == expected
652
673
653
674
0 commit comments