source: main/waeup.sirp/trunk/src/waeup/sirp/utils/tests/test_converters.py @ 6261

Last change on this file since 6261 was 6261, checked in by uli, 13 years ago

Update tests. Still just experimental. Also to test svnmailer.

File size: 3.4 KB
Line 
1##
2## test_converters.py
3## Login : <uli@pu.smp.net>
4## Started on  Tue May 31 08:34:44 2011 Uli Fouquet
5## $Id$
6##
7## Copyright (C) 2011 Uli Fouquet
8## This program is free software; you can redistribute it and/or modify
9## it under the terms of the GNU General Public License as published by
10## the Free Software Foundation; either version 2 of the License, or
11## (at your option) any later version.
12##
13## This program is distributed in the hope that it will be useful,
14## but WITHOUT ANY WARRANTY; without even the implied warranty of
15## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16## GNU General Public License for more details.
17##
18## You should have received a copy of the GNU General Public License
19## along with this program; if not, write to the Free Software
20## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21##
22"""
23Tests for converterts.
24"""
25import os
26import shutil
27import tempfile
28import unittest
29from zope.app.testing.functional import FunctionalTestCase
30from zope.component.hooks import setSite, clearSite
31from zope.interface.verify import verifyClass, verifyObject
32
33from waeup.sirp.app import University
34from waeup.sirp.interfaces import ISchemaTypeConverter
35from waeup.sirp.testing import FunctionalLayer, doctestsuite_for_module
36
37
38class ConverterTests(FunctionalTestCase):
39
40    layer = FunctionalLayer
41
42    def setUp(self):
43        super(ConverterTests, self).setUp()
44
45        # Setup a sample site for each test
46        app = University()
47        self.dc_root = tempfile.mkdtemp()
48        app['datacenter'].setStoragePath(self.dc_root)
49
50        # Prepopulate the ZODB...
51        self.getRootFolder()['app'] = app
52        self.app = self.getRootFolder()['app']
53
54        self.workdir = tempfile.mkdtemp()
55        return
56
57    def tearDown(self):
58        super(ConverterTests, self).tearDown()
59        shutil.rmtree(self.workdir)
60        shutil.rmtree(self.dc_root)
61        clearSite()
62        return
63
64    def test_foo(self):
65        from zope import schema
66        from zope.interface import Interface, implements
67
68        class IContact(Interface):
69            name = schema.TextLine(
70                title = u'Name',
71                default = u'Manfred'
72                )
73            age = schema.Int(
74                title = u'Age',
75                default = 23,
76                required = True,
77                )
78            city = schema.TextLine(
79                title = u'City',
80                required = True,
81                )
82
83
84        class Contact(object):
85            implements(IContact)
86            name = None
87            age = None
88
89        from waeup.sirp.utils.helpers import attrs_to_fields
90        Contact = attrs_to_fields(Contact)
91
92        #field = IContact['name']
93        context = Contact()
94        conv = ISchemaTypeConverter(IContact)
95        input_data = dict(name='Foo')
96        input_data = dict(name='Foo', age='sweet sixteen')
97        err, inv_err, data = conv.applyRowData(input_data, context)
98        #print context.name, context.age
99        #print err, inv_err, data
100        #import pdb; pdb.set_trace()
101        #val = conv._convertValueFromString('Foo', context=context)
102        #print field, conv
103
104def test_suite():
105    suite = unittest.TestSuite()
106    for testcase in [
107        ConverterTests,
108        ]:
109        suite.addTest(unittest.TestLoader().loadTestsFromTestCase(
110                testcase
111                )
112        )
113    return suite
114
Note: See TracBrowser for help on using the repository browser.