-
Notifications
You must be signed in to change notification settings - Fork 0
/
tests.py
44 lines (35 loc) · 1.18 KB
/
tests.py
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
import json
import os
try:
from cStringIO import StringIO as BytesIO
except ImportError:
try:
from StringIO import StringIO as BytesIO
except ImportError:
from io import BytesIO
import sys
import unittest
from pdfjinja import Attachment, PdfJinja
class PdfJinjaTestCase(unittest.TestCase):
datadir = os.path.join(os.path.dirname(__file__), "examples")
def setUp(self):
pdffile = os.path.join(self.datadir, "sample.pdf")
jsonfile = os.path.join(self.datadir, "sample.json")
Attachment.font = "examples/open-sans/regular.ttf"
with open(jsonfile) as f:
self.data = json.loads(f.read())
self.attachments = [
Attachment(**kwargs) for kwargs in self.data.pop("attachments")
]
self.pdfjinja = PdfJinja(pdffile)
def tearDown(self):
del self.data
del self.pdfjinja
def test_render(self):
output = self.pdfjinja(self.data, self.attachments)
outfile = BytesIO()
output.write(outfile)
outfile.seek(0)
self.assertTrue(len(outfile.read()) > 0, "Output PDF is not empty.")
if __name__ == '__main__':
unittest.main(argv=sys.argv)