1+ import unittest
2+ try :
3+ from mock import patch
4+ except ImportError :
5+ from unittest .mock import patch
6+ from quickbooks .cdc import change_data_capture
7+ from quickbooks .objects import Invoice , Customer
8+ from quickbooks import QuickBooks
9+ from datetime import datetime
10+
11+ class ChangeDataCaptureTest (unittest .TestCase ):
12+
13+ def setUp (self ):
14+ self .qb_client = QuickBooks (
15+ sandbox = True ,
16+ consumer_key = "update_consumer_key" ,
17+ consumer_secret = "update_consumer_secret" ,
18+ access_token = "update_access_token" ,
19+ access_token_secret = "update_access_token_secret" ,
20+ company_id = "update_company_id" ,
21+ callback_url = "update_callback_url"
22+ )
23+
24+ self .cdc_json_response = {
25+ "CDCResponse" : [
26+ {
27+ "QueryResponse" : [
28+ {
29+ "Customer" : [
30+ {
31+ "Id" : 1 ,
32+ "DisplayName" : "TestCustomer" ,
33+ "Job" : False ,
34+ "Balance" : 0
35+ }
36+ ],
37+ "startPosition" : 1 ,
38+ "maxResults" : 1
39+ },
40+ {
41+ "Invoice" : [
42+ {
43+ "DocNumber" : "12344" ,
44+ "TxnDate" : "2017-01-01" ,
45+ "Line" : [
46+ {
47+ "Id" : 1
48+ },
49+ {
50+ "Id" : 2
51+ }
52+ ]
53+ },
54+ {
55+ "DocNumber" : "12345" ,
56+ "TxnDate" : "2017-01-01" ,
57+ "Line" : [
58+ {
59+ "Id" : 1
60+ },
61+ {
62+ "Id" : 2
63+ }
64+ ]
65+ },
66+ ],
67+ "startPosition" : 1 ,
68+ "maxResults" : 2
69+ }
70+ ]
71+ }
72+ ],
73+ "time" : "2016-01-01T00:00:00"
74+ }
75+
76+
77+ @patch ('quickbooks.client.QuickBooks.make_request' )
78+ def test_change_data_capture (self , make_request ):
79+ make_request .return_value = self .cdc_json_response .copy ()
80+ cdc_response = change_data_capture ([Invoice , Customer ], "2017-01-01T00:00:00" )
81+ self .assertEquals (1 , len (cdc_response .Customer ))
82+ self .assertEquals (2 , len (cdc_response .Invoice ))
83+
84+
85+ @patch ('quickbooks.client.QuickBooks.make_request' )
86+ def test_change_data_capture_with_timestamp (self , make_request ):
87+ make_request .return_value = self .cdc_json_response .copy ()
88+ cdc_response_with_datetime = change_data_capture ([Invoice , Customer ], datetime (2017 , 1 , 1 , 0 , 0 , 0 ))
89+ self .assertEquals (1 , len (cdc_response_with_datetime .Customer ))
90+ self .assertEquals (2 , len (cdc_response_with_datetime .Invoice ))
0 commit comments