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