vendor/CMF/1.6.3/CMFCore

view exportimport/tests/test_mailhost.py @ 0:587011552858

import CMF 1.6.3
author bdelbosc
date Mon, 23 Apr 2007 13:58:01 +0000
parents
children
line source
1 ##############################################################################
2 #
3 # Copyright (c) 2005 Zope Corporation and Contributors. All Rights Reserved.
4 #
5 # This software is subject to the provisions of the Zope Public License,
6 # Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
7 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
8 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
9 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
10 # FOR A PARTICULAR PURPOSE.
11 #
12 ##############################################################################
13 """Mailhost setup handler unit tests.
15 $Id$
16 """
18 import unittest
19 import Testing
21 from OFS.Folder import Folder
22 from Products.Five import zcml
24 from Products.GenericSetup.tests.common import BaseRegistryTests
25 from Products.GenericSetup.tests.common import DummyExportContext
26 from Products.GenericSetup.tests.common import DummyImportContext
28 from Products.CMFCore.tests.base.testcase import PlacelessSetup
30 _DEFAULT_EXPORT = """\
31 <?xml version="1.0"?>
32 <object name="MailHost" meta_type="Mail Host" smtp_host="localhost"
33 smtp_port="25" smtp_pwd="" smtp_uid=""/>
34 """
36 _CHANGED_EXPORT = """\
37 <?xml version="1.0"?>
38 <object name="MailHost" meta_type="Mail Host" smtp_host="value2"
39 smtp_port="1" smtp_pwd="value1" smtp_uid="value3"/>
40 """
43 class _MailHostSetup(PlacelessSetup, BaseRegistryTests):
45 def _initSite(self, use_changed=False):
46 from Products.MailHost.MailHost import MailHost
48 self.root.site = Folder(id='site')
49 site = self.root.site
50 mh = site.MailHost = MailHost('MailHost')
52 if use_changed:
53 mh.smtp_port='1'
54 mh.smtp_pwd="value1"
55 mh.smtp_host="value2"
56 mh.smtp_uid="value3"
58 return site
60 def setUp(self):
61 import Products.GenericSetup.MailHost
63 PlacelessSetup.setUp(self)
64 BaseRegistryTests.setUp(self)
65 zcml.load_config('meta.zcml', Products.Five)
66 zcml.load_config('configure.zcml', Products.GenericSetup.MailHost)
68 def tearDown(self):
69 BaseRegistryTests.tearDown(self)
70 PlacelessSetup.tearDown(self)
73 class exportMailHostTests(_MailHostSetup):
75 def test_unchanged(self):
76 from Products.CMFCore.exportimport.mailhost import exportMailHost
78 site = self._initSite(use_changed=False)
79 context = DummyExportContext(site)
80 exportMailHost(context)
82 self.assertEqual(len(context._wrote), 1)
83 filename, text, content_type = context._wrote[0]
84 self.assertEqual(filename, 'mailhost.xml')
85 self._compareDOM(text, _DEFAULT_EXPORT)
86 self.assertEqual(content_type, 'text/xml')
88 def test_changed(self):
89 from Products.CMFCore.exportimport.mailhost import exportMailHost
91 site = self._initSite(use_changed=True)
92 context = DummyExportContext(site)
93 exportMailHost(context)
95 self.assertEqual(len(context._wrote), 1)
96 filename, text, content_type = context._wrote[0]
97 self.assertEqual(filename, 'mailhost.xml')
98 self._compareDOM(text, _CHANGED_EXPORT)
99 self.assertEqual(content_type, 'text/xml')
102 class importMailHostTests(_MailHostSetup):
104 def test_normal(self):
105 from Products.CMFCore.exportimport.mailhost import importMailHost
107 site = self._initSite()
108 mh = site.MailHost
110 context = DummyImportContext(site)
111 context._files['mailhost.xml'] = _CHANGED_EXPORT
112 importMailHost(context)
114 self.assertEqual( mh.smtp_pwd, 'value1' )
115 self.assertEqual( mh.smtp_host, 'value2' )
116 self.assertEqual( mh.smtp_uid, 'value3' )
117 self.assertEqual( mh.smtp_port, 1 )
120 def test_suite():
121 return unittest.TestSuite((
122 unittest.makeSuite(exportMailHostTests),
123 unittest.makeSuite(importMailHostTests),
124 ))
126 if __name__ == '__main__':
127 unittest.main(defaultTest='test_suite')