forked from routablehq/python-quickbooks
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_attachable.py
More file actions
60 lines (41 loc) · 2.22 KB
/
test_attachable.py
File metadata and controls
60 lines (41 loc) · 2.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import os
import tempfile
from datetime import datetime
from quickbooks.objects.attachable import Attachable
from quickbooks.objects.base import AttachableRef
from quickbooks.objects.vendor import Vendor
from tests.integration.test_base import QuickbooksTestCase
class AttachableTest(QuickbooksTestCase):
def setUp(self):
super(AttachableTest, self).setUp()
self.time = datetime.now()
def test_create_note(self):
attachable = Attachable()
vendor = Vendor.all(max_results=1, qb=self.qb_client)[0]
attachable_ref = AttachableRef()
attachable_ref.EntityRef = vendor.to_ref()
attachable.AttachableRef.append(attachable_ref)
attachable.Note = "Test note added on {}".format(self.time.strftime("%Y-%m-%d %H:%M:%S"))
attachable.save(qb=self.qb_client)
query_attachable = Attachable.get(attachable.Id, qb=self.qb_client)
self.assertEquals(query_attachable.AttachableRef[0].EntityRef.value, vendor.Id)
self.assertEquals(query_attachable.Note, "Test note added on {}".format(self.time.strftime("%Y-%m-%d %H:%M:%S")))
def test_update_note(self):
attachable = Attachable.all(max_results=1, qb=self.qb_client)[0]
attachable.Note = "Note updated on {}".format(self.time.strftime("%Y-%m-%d %H:%M:%S"))
attachable.save(qb=self.qb_client)
query_attachable = Attachable.get(attachable.Id, qb=self.qb_client)
self.assertEquals(query_attachable.Note, "Note updated on {}".format(self.time.strftime("%Y-%m-%d %H:%M:%S")))
def test_create_file(self):
attachable = Attachable()
test_file = tempfile.NamedTemporaryFile(suffix=".txt")
vendor = Vendor.all(max_results=1, qb=self.qb_client)[0]
attachable_ref = AttachableRef()
attachable_ref.EntityRef = vendor.to_ref()
attachable.AttachableRef.append(attachable_ref)
attachable.FileName = os.path.basename(test_file.name)
attachable._FilePath = test_file.name
attachable.ContentType = 'text/plain'
attachable.save(qb=self.qb_client)
query_attachable = Attachable.get(attachable.Id, qb=self.qb_client)
self.assertEquals(query_attachable.AttachableRef[0].EntityRef.value, vendor.Id)