Index: /main/waeup.sirp/trunk/src/waeup/sirp/applicants/jambtables/tests/test_jambtables.py
===================================================================
--- /main/waeup.sirp/trunk/src/waeup/sirp/applicants/jambtables/tests/test_jambtables.py	(revision 5739)
+++ /main/waeup.sirp/trunk/src/waeup/sirp/applicants/jambtables/tests/test_jambtables.py	(revision 5740)
@@ -24,4 +24,5 @@
 
 """
+import logging
 import os
 import shutil
@@ -31,4 +32,5 @@
 import grok
 
+from cStringIO import StringIO
 from datetime import datetime
 
@@ -39,7 +41,11 @@
 from waeup.sirp.app import University
 from waeup.sirp.datacenter import DataCenter
-from waeup.sirp.applicants.jambtables import JAMBDataTable
+from waeup.sirp.applicants.jambtables import (
+    JAMBDataTable, JAMBDataPlugin, JAMBDataRoot,
+    )
 from waeup.sirp.applicants.jambtables.interfaces import IJAMBDataTable
 
+class FakeSite(dict):
+    pass
 
 class JAMBTableTestCaseBase(unittest.TestCase):
@@ -191,4 +197,96 @@
         return
 
+class JAMBDataPluginTestCase(unittest.TestCase):
+    def create_logger(self):
+        # create a logger suitable for local tests.
+        test_logger = logging.getLogger('waeup.sirp.jambdata.testlogger')
+        log = StringIO()
+        handler = logging.StreamHandler(log)
+        handler.setLevel(logging.DEBUG)
+        test_logger.addHandler(handler)
+        test_logger.setLevel(logging.DEBUG)
+        self.logger = test_logger
+        self.log = log
+        self.handler = handler
+        return self.logger
+
+    def remove_logger(self):
+        del self.handler
+        del self.logger
+        del self.log
+        pass
+
+    def get_log(self):
+        self.log.seek(0)
+        return self.log.read()
+
+    def setUp(self):
+        self.create_logger()
+        return
+
+    def tearDown(self):
+        self.remove_logger()
+        return
+
+    # Real tests start here...
+    def test_pluginsetup(self):
+        # Make sure we can add ApplicantsRoot to sites.
+        site = FakeSite()
+        plugin = JAMBDataPlugin()
+        plugin.setup(site, 'blah', self.logger)
+        self.assertTrue('jambdata' in site.keys())
+        log = self.get_log()
+        self.assertTrue('JAMBDataPlugin: Installed JAMB data root.' in log)
+        return
+
+    def test_update_new(self):
+        # Run update on a site without applicants root.
+        site = FakeSite()
+        plugin = JAMBDataPlugin()
+        plugin.update(site, 'blah', self.logger)
+        self.assertTrue('jambdata' in site.keys())
+        log = self.get_log()
+        self.assertTrue('Updating site at <Unnamed Site>' in log)
+        self.assertTrue('Installed JAMB data root.' in log)
+        return
+
+    def test_update_outdated(self):
+        # Run update on a site with outdated applicants root.
+        site = FakeSite()
+        root = object() # # This is not a proper applicants root
+        site['jambdata'] = root
+        plugin = JAMBDataPlugin()
+        plugin.update(site, 'blah', self.logger)
+        self.assertTrue(site['jambdata'] is not root)
+        self.assertTrue(isinstance(site['jambdata'], JAMBDataRoot))
+        log = self.get_log()
+        self.assertTrue('Outdated JAMB data folder detected' in log)
+        self.assertTrue('Updating site at <Unnamed Site>' in log)
+        self.assertTrue('Installed JAMB data root.' in log)
+        return
+
+    def test_update_uptodate(self):
+        # Run update on a site with proper applicants root.
+        site = FakeSite()
+        root = JAMBDataRoot()
+        site['jambdata'] = root
+        plugin = JAMBDataPlugin()
+        plugin.update(site, 'blah', self.logger)
+        self.assertTrue(site['jambdata'] is root)
+        log = self.get_log()
+        self.assertTrue('Updating site at <Unnamed Site>' in log)
+        self.assertTrue('Nothing to do' in log)
+        return
+
+    def test_update_log(self):
+        # Check that sitename is used in log messages on updates.
+        site = FakeSite()
+        site.__name__ = 'my_site'
+        plugin = JAMBDataPlugin()
+        plugin.update(site, 'blah', self.logger)
+        log = self.get_log()
+        self.assertTrue('Updating site at my_site.' in log)
+        return
+
         
 def test_suite():
@@ -197,4 +295,5 @@
         JAMBTableTestCase,
         JAMBTableFunctionalTestCase,
+        JAMBDataPluginTestCase,
         ]:
         suite.addTest(unittest.TestLoader().loadTestsFromTestCase(
