Changeset 5659
- Timestamp:
- 24 Jan 2011, 23:29:04 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.sirp/trunk/src/waeup/sirp/applications/tests/test_root.py
r5646 r5659 23 23 Test applications root. 24 24 """ 25 import logging 25 26 import unittest 27 from StringIO import StringIO 26 28 from zope.interface.verify import verifyClass, verifyObject 27 29 from waeup.sirp.applications import interfaces 28 from waeup.sirp.applications.root import ApplicationsRoot 30 from waeup.sirp.applications.root import ( 31 ApplicationsRoot, ApplicationsPlugin, 32 ) 33 34 class FakeSite(dict): 35 pass 29 36 30 37 class ApplicationsRootTestCase(unittest.TestCase): … … 42 49 return 43 50 51 class ApplicationsRootPluginTestCase(unittest.TestCase): 52 def create_logger(self): 53 # create a logger suitable for local tests. 54 test_logger = logging.getLogger('waeup.sirp.applications.testlogger') 55 log = StringIO() 56 handler = logging.StreamHandler(log) 57 handler.setLevel(logging.DEBUG) 58 test_logger.addHandler(handler) 59 test_logger.setLevel(logging.DEBUG) 60 self.logger = test_logger 61 self.log = log 62 self.handler = handler 63 return self.logger 64 65 def remove_logger(self): 66 del self.handler 67 del self.logger 68 del self.log 69 pass 70 71 def get_log(self): 72 self.log.seek(0) 73 return self.log.read() 74 75 def setUp(self): 76 self.create_logger() 77 return 78 79 def tearDown(self): 80 self.remove_logger() 81 return 82 83 # Real tests start here... 84 def test_pluginsetup(self): 85 # Make sure we can add ApplicationsRoot to sites. 86 site = FakeSite() 87 plugin = ApplicationsPlugin() 88 plugin.setup(site, 'blah', self.logger) 89 self.assertTrue('applications' in site.keys()) 90 log = self.get_log() 91 self.assertTrue('Installed applications root.' in log) 92 return 93 94 def test_update_new(self): 95 # Run update on a site without applications root. 96 site = FakeSite() 97 plugin = ApplicationsPlugin() 98 plugin.update(site, 'blah', self.logger) 99 self.assertTrue('applications' in site.keys()) 100 log = self.get_log() 101 self.assertTrue('Updating site at Unnamed Site' in log) 102 self.assertTrue('Installed applications root.' in log) 103 return 104 105 def test_update_outdated(self): 106 # Run update on a site with outdated applications root. 107 site = FakeSite() 108 root = object() # # This is not a proper applications root 109 site['applications'] = root 110 plugin = ApplicationsPlugin() 111 plugin.update(site, 'blah', self.logger) 112 self.assertTrue(site['applications'] is not root) 113 self.assertTrue(isinstance(site['applications'], ApplicationsRoot)) 114 log = self.get_log() 115 self.assertTrue('Outdated applications folder detected' in log) 116 self.assertTrue('Updating site at Unnamed Site' in log) 117 self.assertTrue('Installed applications root.' in log) 118 return 119 120 def test_update_uptodate(self): 121 # Run update on a site with proper applications root. 122 site = FakeSite() 123 root = ApplicationsRoot() 124 site['applications'] = root 125 plugin = ApplicationsPlugin() 126 plugin.update(site, 'blah', self.logger) 127 self.assertTrue(site['applications'] is root) 128 log = self.get_log() 129 self.assertTrue('Updating site at Unnamed Site' in log) 130 self.assertTrue('Nothing to do' in log) 131 return 132 133 def test_update_log(self): 134 # Check that sitename is used in log messages on updates. 135 site = FakeSite() 136 site.__name__ = 'my_site' 137 plugin = ApplicationsPlugin() 138 plugin.update(site, 'blah', self.logger) 139 log = self.get_log() 140 self.assertTrue('Updating site at my_site.' in log) 141 return 142 44 143 def suite(): 45 144 suite = unittest.TestSuite() 46 suite.addTests( 47 unittest.TestLoader().loadTestsFromTestCase( 145 for testcase in [ 48 146 ApplicationsRootTestCase, 49 ) 50 ) 147 ApplicationsRootPluginTestCase, 148 ]: 149 suite.addTests(unittest.TestLoader().loadTestsFromTestCase(testcase)) 51 150 return suite 52 151
Note: See TracChangeset for help on using the changeset viewer.