Changeset 5740 for main


Ignore:
Timestamp:
12 Feb 2011, 22:34:11 (14 years ago)
Author:
uli
Message:

Add tests for JAMB data plugin. Mainly copied from
waeup.sirp.applicants plugin.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.sirp/trunk/src/waeup/sirp/applicants/jambtables/tests/test_jambtables.py

    r5689 r5740  
    2424
    2525"""
     26import logging
    2627import os
    2728import shutil
     
    3132import grok
    3233
     34from cStringIO import StringIO
    3335from datetime import datetime
    3436
     
    3941from waeup.sirp.app import University
    4042from waeup.sirp.datacenter import DataCenter
    41 from waeup.sirp.applicants.jambtables import JAMBDataTable
     43from waeup.sirp.applicants.jambtables import (
     44    JAMBDataTable, JAMBDataPlugin, JAMBDataRoot,
     45    )
    4246from waeup.sirp.applicants.jambtables.interfaces import IJAMBDataTable
    4347
     48class FakeSite(dict):
     49    pass
    4450
    4551class JAMBTableTestCaseBase(unittest.TestCase):
     
    191197        return
    192198
     199class JAMBDataPluginTestCase(unittest.TestCase):
     200    def create_logger(self):
     201        # create a logger suitable for local tests.
     202        test_logger = logging.getLogger('waeup.sirp.jambdata.testlogger')
     203        log = StringIO()
     204        handler = logging.StreamHandler(log)
     205        handler.setLevel(logging.DEBUG)
     206        test_logger.addHandler(handler)
     207        test_logger.setLevel(logging.DEBUG)
     208        self.logger = test_logger
     209        self.log = log
     210        self.handler = handler
     211        return self.logger
     212
     213    def remove_logger(self):
     214        del self.handler
     215        del self.logger
     216        del self.log
     217        pass
     218
     219    def get_log(self):
     220        self.log.seek(0)
     221        return self.log.read()
     222
     223    def setUp(self):
     224        self.create_logger()
     225        return
     226
     227    def tearDown(self):
     228        self.remove_logger()
     229        return
     230
     231    # Real tests start here...
     232    def test_pluginsetup(self):
     233        # Make sure we can add ApplicantsRoot to sites.
     234        site = FakeSite()
     235        plugin = JAMBDataPlugin()
     236        plugin.setup(site, 'blah', self.logger)
     237        self.assertTrue('jambdata' in site.keys())
     238        log = self.get_log()
     239        self.assertTrue('JAMBDataPlugin: Installed JAMB data root.' in log)
     240        return
     241
     242    def test_update_new(self):
     243        # Run update on a site without applicants root.
     244        site = FakeSite()
     245        plugin = JAMBDataPlugin()
     246        plugin.update(site, 'blah', self.logger)
     247        self.assertTrue('jambdata' in site.keys())
     248        log = self.get_log()
     249        self.assertTrue('Updating site at <Unnamed Site>' in log)
     250        self.assertTrue('Installed JAMB data root.' in log)
     251        return
     252
     253    def test_update_outdated(self):
     254        # Run update on a site with outdated applicants root.
     255        site = FakeSite()
     256        root = object() # # This is not a proper applicants root
     257        site['jambdata'] = root
     258        plugin = JAMBDataPlugin()
     259        plugin.update(site, 'blah', self.logger)
     260        self.assertTrue(site['jambdata'] is not root)
     261        self.assertTrue(isinstance(site['jambdata'], JAMBDataRoot))
     262        log = self.get_log()
     263        self.assertTrue('Outdated JAMB data folder detected' in log)
     264        self.assertTrue('Updating site at <Unnamed Site>' in log)
     265        self.assertTrue('Installed JAMB data root.' in log)
     266        return
     267
     268    def test_update_uptodate(self):
     269        # Run update on a site with proper applicants root.
     270        site = FakeSite()
     271        root = JAMBDataRoot()
     272        site['jambdata'] = root
     273        plugin = JAMBDataPlugin()
     274        plugin.update(site, 'blah', self.logger)
     275        self.assertTrue(site['jambdata'] is root)
     276        log = self.get_log()
     277        self.assertTrue('Updating site at <Unnamed Site>' in log)
     278        self.assertTrue('Nothing to do' in log)
     279        return
     280
     281    def test_update_log(self):
     282        # Check that sitename is used in log messages on updates.
     283        site = FakeSite()
     284        site.__name__ = 'my_site'
     285        plugin = JAMBDataPlugin()
     286        plugin.update(site, 'blah', self.logger)
     287        log = self.get_log()
     288        self.assertTrue('Updating site at my_site.' in log)
     289        return
     290
    193291       
    194292def test_suite():
     
    197295        JAMBTableTestCase,
    198296        JAMBTableFunctionalTestCase,
     297        JAMBDataPluginTestCase,
    199298        ]:
    200299        suite.addTest(unittest.TestLoader().loadTestsFromTestCase(
Note: See TracChangeset for help on using the changeset viewer.