Author: jmorliaguet
Date: Thu Mar 23 11:49:36 2006
New Revision: 2703

Added:
   cpsskins/branches/jmo-perspectives/ftests/test_appsetup.py   (contents, 
props changed)
Log:

- added first test for the application setup



Added: cpsskins/branches/jmo-perspectives/ftests/test_appsetup.py
==============================================================================
--- (empty file)
+++ cpsskins/branches/jmo-perspectives/ftests/test_appsetup.py  Thu Mar 23 
11:49:36 2006
@@ -0,0 +1,100 @@
+##############################################################################
+#
+# Copyright (c) 2005-2006 Nuxeo and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""Application setup tests
+
+$Id$
+"""
+__docformat__ = "reStructuredText"
+
+import unittest
+
+import cpsskins.configuration
+import cpsskins.setup
+
+from zope.interface import implements, Interface
+from zope.app.testing import ztapi
+from zope.app.testing.functional import BrowserTestCase
+from zope.component import getUtility
+
+from cpsskins.setup.interfaces import IResourceManager, ISettings
+from cpsskins.setup.manager import ResourceManager
+from cpsskins.tests.setup import addThemeManager
+
+def printrepr(obj):
+    if isinstance(obj, list):
+        return [repr(r) for r in obj]
+    return repr(obj)
+
+class IDummyResource(Interface):
+     """Dummy resource interface"""
+
+class DummyResource(object):
+    """A dummy resource for testing.
+    """
+    implements(IDummyResource)
+
+    def __init__(self, id=u''):
+        self.id = id
+
+    def __repr__(self):
+        return '<Dummy resource: %s>' % self.id
+
+class TestAppSetup(BrowserTestCase):
+
+    def setUp(self):
+        super(TestAppSetup, self).setUp()
+
+        self.root = self.getRootFolder()
+        tmutil = addThemeManager(self.root)
+
+        ztapi.provideUtility(IResourceManager, ResourceManager())
+        self.resources = getUtility(IResourceManager)
+
+    def test_register_and_lookup_global_resources(self):
+        resources = self.resources
+        resource1 = DummyResource(u'resource1')
+        resource2 = DummyResource(u'resource2')
+        self.root[u'resource1'] = resource1
+        self.root[u'resource2'] = resource2
+        # no resource is available yet
+        self.assertEqual(self.resources.lookup('setting1'), None)
+        self.assertEqual(self.resources.lookup('setting2'), None)
+        # register the resource
+        resources.register(name=u'setting1', title=u'Setting 1',
+                                resource=resource1)
+        # lookup resources
+        self.assertEqual(printrepr(resources.lookup('setting1')),
+                         u'<Dummy resource: resource1>')
+        self.assertEqual(resources.lookup('setting2'), None)
+        # list resources
+        self.assertEqual(printrepr(resources.list(type=IDummyResource)),
+                         ['<Dummy resource: resource1>'])
+        # register new resource
+        self.resources.register(name=u'setting2', title=u'Setting 2',
+                                resource=resource2)
+        # lookup resources
+        self.assertEqual(printrepr(resources.lookup('setting2')),
+                         u'<Dummy resource: resource2>')
+        # list resources
+        self.assertEqual(printrepr(resources.list(type=IDummyResource)),
+           ['<Dummy resource: resource1>', '<Dummy resource: resource2>'])
+
+
+def test_suite():
+    return unittest.TestSuite((
+        unittest.makeSuite(TestAppSetup),
+        ))
+
+if __name__ == '__main__':
+    unittest.main(defaultTest='test_suite')
-- 
http://lists.nuxeo.com/mailman/listinfo/z3lab-checkins

Reply via email to