Ignore:
Timestamp:
10 Dec 2012, 01:12:21 (12 years ago)
Author:
uli
Message:

Add regression tests for last fix.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.kofa/trunk/src/waeup/kofa/tests/test_async.py

    r9217 r9793  
    1414from zope.container.interfaces import IContainer
    1515from zope.interface import verify
     16from zope.site.folder import rootFolder
     17from zope.site.testing import createSiteManager
    1618from waeup.kofa.interfaces import (
    1719    WAEUP_KEY, IProgressable, IJobManager, IJobContainer
     
    113115        manager = getUtility(IJobManager)
    114116        self.assertTrue(isinstance(manager, JobManager))
     117        return
     118
     119    def test_get_site_no_site(self):
     120        # if no site is around, we get a lookup error
     121        manager = getUtility(IJobManager)
     122        self.assertRaises(LookupError, manager._get_site, None)
     123        return
     124
     125    def test_get_site_invalid_site(self):
     126        # if we pass an invalid site, we get a lookup error
     127        manager = getUtility(IJobManager)
     128        self.assertRaises(LookupError, manager._get_site, object())
     129        return
     130
     131    def test_get_site_valid_site(self):
     132        # if we pass a valid site, that will be respected
     133        manager = getUtility(IJobManager)
     134        result = manager._get_site(self.root_folder)
     135        self.assertEqual(result, self.root_folder)
     136        return
     137
     138    def test_get_site_externally_set_site(self):
     139        # if, however, a site was set externally, it will be found
     140        # even if passed in site is not valid
     141        manager = getUtility(IJobManager)
     142        site = rootFolder()
     143        self.root_folder['application'] = site
     144        createSiteManager(site, setsite=True)
     145        transaction.commit()
     146        result1 = manager._get_site(None)     # no site given
     147        result2 = manager._get_site(site)     # valid site given
     148        result3 = manager._get_site(object()) # invalid site given
     149        result4 = manager._get_site(self.root_folder) # valid persisted obj
     150        # we always get the externally set site...
     151        self.assertEqual(result1, site)
     152        self.assertEqual(result2, site)
     153        self.assertEqual(result3, site)
     154        # except if the passed object is already a valid persisted one
     155        self.assertEqual(result4, self.root_folder)
    115156        return
    116157
Note: See TracChangeset for help on using the changeset viewer.