source: OpenRLabs-Git/deploy/rlabs-docker/web2py-rlabs/gluon/tests/test_contribs.py @ 42095c5

mainqndtest v1.1.1
Last change on this file since 42095c5 was 42bd667, checked in by David Fuertes <dfuertes@…>, 4 years ago

Historial Limpio

  • Property mode set to 100755
File size: 2.0 KB
Line 
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3
4""" Unit tests for contribs """
5
6import unittest
7import os
8
9from gluon._compat import to_bytes
10from gluon.storage import Storage
11from gluon.contrib import fpdf as fpdf
12from gluon.contrib import pyfpdf as pyfpdf
13from gluon.contrib.appconfig import AppConfig
14
15
16def setUpModule():
17    pass
18
19
20def tearDownModule():
21    if os.path.isfile('appconfig.json'):
22        os.unlink('appconfig.json')
23
24
25class TestContribs(unittest.TestCase):
26    """ Tests the contrib package """
27
28    def test_fpdf(self):
29        """ Basic PDF test and sanity checks """
30
31        self.assertEqual(
32            fpdf.FPDF_VERSION, pyfpdf.FPDF_VERSION, 'version mistmatch')
33        self.assertEqual(fpdf.FPDF, pyfpdf.FPDF, 'class mistmatch')
34
35        pdf = fpdf.FPDF()
36        pdf.add_page()
37        pdf.compress = False
38        pdf.set_font('Arial', '', 14)
39        pdf.ln(10)
40        pdf.write(5, 'hello world')
41        pdf_out = pdf.output('', 'S')
42
43        self.assertTrue(to_bytes(fpdf.FPDF_VERSION) in pdf_out, 'version string')
44        self.assertTrue(to_bytes('hello world') in pdf_out, 'sample message')
45
46    def test_appconfig(self):
47        """
48        Test for the appconfig module
49        """
50        from gluon import current
51        s = Storage({'application': 'admin',
52                     'folder': 'applications/admin'})
53        current.request = s
54        simple_config = '{"config1" : "abc", "config2" : "bcd", "config3" : { "key1" : 1, "key2" : 2} }'
55        with open('appconfig.json', 'w') as g:
56            g.write(simple_config)
57        myappconfig = AppConfig('appconfig.json')
58        self.assertEqual(myappconfig['config1'], 'abc')
59        self.assertEqual(myappconfig['config2'], 'bcd')
60        self.assertEqual(myappconfig.take('config1'), 'abc')
61        self.assertEqual(myappconfig.take('config3.key1', cast=str), '1')
62        # once parsed, can't be casted to other types
63        self.assertEqual(myappconfig.take('config3.key1', cast=int), '1')
64
65        self.assertEqual(myappconfig.take('config3.key2'), 2)
66
67        current.request = {}
Note: See TracBrowser for help on using the repository browser.