|
| 1 | +import os |
| 2 | +import unittest |
| 3 | +from datetime import datetime |
| 4 | + |
| 5 | +from quickbooks.client import QuickBooks |
| 6 | +from quickbooks.objects.attachable import Attachable |
| 7 | +from quickbooks.objects.base import Ref, AttachableRef |
| 8 | +from quickbooks.objects.vendor import Vendor |
| 9 | + |
| 10 | + |
| 11 | +class AttachableTest(unittest.TestCase): |
| 12 | + def setUp(self): |
| 13 | + self.qb_client = QuickBooks( |
| 14 | + sandbox=True, |
| 15 | + consumer_key=os.environ.get('CONSUMER_KEY'), |
| 16 | + consumer_secret=os.environ.get('CONSUMER_SECRET'), |
| 17 | + access_token=os.environ.get('ACCESS_TOKEN'), |
| 18 | + access_token_secret=os.environ.get('ACCESS_TOKEN_SECRET'), |
| 19 | + company_id=os.environ.get('COMPANY_ID') |
| 20 | + ) |
| 21 | + |
| 22 | + self.time = datetime.now() |
| 23 | + |
| 24 | + def test_create_note(self): |
| 25 | + attachable = Attachable() |
| 26 | + |
| 27 | + vendor = Vendor.all(max_results=1, qb=self.qb_client)[0] |
| 28 | + |
| 29 | + attachable_ref = AttachableRef() |
| 30 | + attachable_ref.EntityRef = vendor.to_ref() |
| 31 | + attachable.AttachableRef.append(attachable_ref) |
| 32 | + |
| 33 | + attachable.Note = "Test note added on {}".format(self.time.strftime("%Y-%m-%d %H:%M:%S")) |
| 34 | + |
| 35 | + attachable.save(qb=self.qb_client) |
| 36 | + query_attachable = Attachable.get(attachable.Id, qb=self.qb_client) |
| 37 | + |
| 38 | + self.assertEquals(query_attachable.AttachableRef[0].EntityRef.value, vendor.Id) |
| 39 | + self.assertEquals(query_attachable.Note, "Test note added on {}".format(self.time.strftime("%Y-%m-%d %H:%M:%S"))) |
| 40 | + |
| 41 | + def test_update_note(self): |
| 42 | + attachable = Attachable.all(max_results=1, qb=self.qb_client)[0] |
| 43 | + |
| 44 | + attachable.Note = "Note updated on {}".format(self.time.strftime("%Y-%m-%d %H:%M:%S")) |
| 45 | + attachable.save(qb=self.qb_client) |
| 46 | + |
| 47 | + query_attachable = Attachable.get(attachable.Id, qb=self.qb_client) |
| 48 | + self.assertEquals(query_attachable.Note, "Note updated on {}".format(self.time.strftime("%Y-%m-%d %H:%M:%S"))) |
0 commit comments