예제 #1
0
class TestGetTimezone(unittest.TestCase):

    def setUp(self):
        from naaya.core.zope2util import getExtConfiguration as getConfiguration
        from Products.Naaya.NySite import NySite

        self.config = getConfiguration()
        self.config_patch = patch.object(self.config, 'environment', {},
                                         create=True)
        self.config_patch.start()

        self.environ_patch = patch.dict(os.environ)
        self.environ_patch.start()

        self.portal = NySite('test-site')

    def tearDown(self):
        self.environ_patch.stop()
        self.config_patch.stop()

    def test_get_timezone1_zope_conf(self):
        # 1. From buildout::zope-conf-additional
        self.config.environment['TZ'] = 'Europe/Bucharest'
        tzinfo = self.portal.get_tzinfo()
        date_here = winter.astimezone(tzinfo)
        self.failUnlessEqual(date_here.date(), winter.date())
        self.failUnlessEqual(date_here.hour, 12)

    def test_get_timezone2_os_environ(self):
        # 2. From os.environ
        os.environ['TZ'] = 'Europe/Bucharest'
        tzinfo = self.portal.get_tzinfo()
        date_here = winter.astimezone(tzinfo)
        self.failUnlessEqual(date_here.date(), winter.date())
        self.failUnlessEqual(date_here.hour, 12)

    def test_get_timezone3_time_tzname(self):
        # 3. From time.tzname
        # We can't assume a certain timezone for the machine running this script
        expected = time.tzname
        timezone = self.portal.get_timezone()
        self.failUnlessEqual(timezone, expected[0])

    @patch.object(time, 'tzname')
    def test_get_timezone4_time_fallback(self, mock_method):
        # 4. Hardcoded fallback
        time.tzname = ()
        timezone = self.portal.get_timezone()
        self.failUnlessEqual(timezone, 'Europe/Copenhagen')

    def test_dst(self):
        self.config.environment['TZ'] = 'Europe/Bucharest'
        tzinfo = self.portal.get_tzinfo()
        date_nodst = winter.astimezone(tzinfo)
        date_dst = summer.astimezone(tzinfo)
        self.failUnlessEqual(date_nodst.date(), winter.date())
        self.failUnlessEqual(date_dst.date(), summer.date())
        self.failUnlessEqual(date_nodst.hour, 12 )
        self.failUnlessEqual(date_dst.hour, 12 + 1)
예제 #2
0
class TestGetTimezone(unittest.TestCase):
    def setUp(self):
        from naaya.core.zope2util import getExtConfiguration as getConfiguration
        from Products.Naaya.NySite import NySite

        self.config = getConfiguration()
        self.config_patch = patch.object(self.config,
                                         'environment', {},
                                         create=True)
        self.config_patch.start()

        self.environ_patch = patch.dict(os.environ)
        self.environ_patch.start()

        self.portal = NySite('test-site')

    def tearDown(self):
        self.environ_patch.stop()
        self.config_patch.stop()

    def test_get_timezone1_zope_conf(self):
        # 1. From buildout::zope-conf-additional
        self.config.environment['TZ'] = 'Europe/Bucharest'
        tzinfo = self.portal.get_tzinfo()
        date_here = winter.astimezone(tzinfo)
        self.failUnlessEqual(date_here.date(), winter.date())
        self.failUnlessEqual(date_here.hour, 12)

    def test_get_timezone2_os_environ(self):
        # 2. From os.environ
        os.environ['TZ'] = 'Europe/Bucharest'
        tzinfo = self.portal.get_tzinfo()
        date_here = winter.astimezone(tzinfo)
        self.failUnlessEqual(date_here.date(), winter.date())
        self.failUnlessEqual(date_here.hour, 12)

    def test_get_timezone3_time_tzname(self):
        # 3. From time.tzname
        # We can't assume a certain timezone for the machine running this script
        expected = time.tzname
        timezone = self.portal.get_timezone()
        self.failUnlessEqual(timezone, expected[0])

    @patch.object(time, 'tzname')
    def test_get_timezone4_time_fallback(self, mock_method):
        # 4. Hardcoded fallback
        time.tzname = ()
        timezone = self.portal.get_timezone()
        self.failUnlessEqual(timezone, 'Europe/Copenhagen')

    def test_dst(self):
        self.config.environment['TZ'] = 'Europe/Bucharest'
        tzinfo = self.portal.get_tzinfo()
        date_nodst = winter.astimezone(tzinfo)
        date_dst = summer.astimezone(tzinfo)
        self.failUnlessEqual(date_nodst.date(), winter.date())
        self.failUnlessEqual(date_dst.date(), summer.date())
        self.failUnlessEqual(date_nodst.hour, 12)
        self.failUnlessEqual(date_dst.hour, 12 + 1)
예제 #3
0
 def test_set_bundle(self):
     self.bundle_names.append('bundle-for-portal-test')
     bundle = bundles.get('bundle-for-portal-test')
     portal = NySite('portal')
     portal.set_bundle(bundle)
     ob = MyClass()
     bundle.registerUtility(ob)
     portal_site_manager = portal.getSiteManager()
     self.assertTrue(portal_site_manager.getUtility(ITestUtil) is ob)
예제 #4
0
 def test_set_bundle(self):
     self.bundle_names.append('bundle-for-portal-test')
     bundle = bundles.get('bundle-for-portal-test')
     portal = NySite('portal')
     portal.set_bundle(bundle)
     ob = MyClass()
     bundle.registerUtility(ob)
     portal_site_manager = portal.getSiteManager()
     self.assertTrue(portal_site_manager.getUtility(ITestUtil) is ob)
예제 #5
0
 def setUp(self):
     from Products.Naaya.interfaces import INySite
     from Products.Naaya.NySite import NySite
     from naaya.core.interfaces import IFilesystemBundleFactory
     from naaya.core.fsbundles import register_bundle_factory
     self.bundle_names = []
     self.tmp = tempfile.mkdtemp()
     register_bundle_factory(self.tmp, 'FooSites-', 'Foo')
     self.site = NySite('bar')
     self.site.set_bundle(bundles.get('Foo'))
예제 #6
0
class BundleFactoryTest(unittest.TestCase):

    def setUp(self):
        from Products.Naaya.interfaces import INySite
        from Products.Naaya.NySite import NySite
        from naaya.core.interfaces import IFilesystemBundleFactory
        from naaya.core.fsbundles import register_bundle_factory
        self.bundle_names = []
        self.tmp = tempfile.mkdtemp()
        register_bundle_factory(self.tmp, 'FooSites-', 'Foo')
        self.site = NySite('bar')
        self.site.set_bundle(bundles.get('Foo'))

    def tearDown(self):
        from Products.Naaya.interfaces import INySite
        from naaya.core.interfaces import IFilesystemBundleFactory
        shutil.rmtree(self.tmp)
        for name in self.bundle_names:
            clean_up_bundle(name)
        gsm = getGlobalSiteManager()
        assert gsm.unregisterAdapter(required=(INySite,),
                                     provided=IFilesystemBundleFactory,
                                     name='Foo')

    def test_create_bundle(self):
        from naaya.core.fsbundles import get_filesystem_bundle_factory
        factory = get_filesystem_bundle_factory(self.site)
        bundle = factory()
        self.assertEqual(bundle.__name__, 'FooSites-bar')
        self.assertEqual(os.listdir(self.tmp), ['FooSites-bar.bundle'])
        self.assertEqual(self.site.get_bundle(), bundle)

    def test_bundle_cfg(self):
        from naaya.core.fsbundles import get_filesystem_bundle_factory
        factory = get_filesystem_bundle_factory(self.site)
        bundle = factory()
        cfg_path = os.path.join(self.tmp, 'FooSites-bar.bundle', 'bundle.cfg')
        f = open(cfg_path, 'rb')
        data = list(f)
        f.close()
        self.assertTrue('parent-bundle = Foo\n') in data

    def test_create_preexisting_bundle(self):
        from naaya.core.fsbundles import get_filesystem_bundle_factory
        factory = get_filesystem_bundle_factory(self.site)
        bundle = factory()
        self.assertRaises(ValueError, factory)

    def test_wrong_site_bundle(self):
        from naaya.core.fsbundles import get_filesystem_bundle_factory
        self.site.set_bundle(bundles.get('Baz'))
        factory = get_filesystem_bundle_factory(self.site)
        self.assertTrue(factory is None)
예제 #7
0
class BundleFactoryTest(unittest.TestCase):
    def setUp(self):
        from Products.Naaya.interfaces import INySite
        from Products.Naaya.NySite import NySite
        from naaya.core.interfaces import IFilesystemBundleFactory
        from naaya.core.fsbundles import register_bundle_factory
        self.bundle_names = []
        self.tmp = tempfile.mkdtemp()
        register_bundle_factory(self.tmp, 'FooSites-', 'Foo')
        self.site = NySite('bar')
        self.site.set_bundle(bundles.get('Foo'))

    def tearDown(self):
        from Products.Naaya.interfaces import INySite
        from naaya.core.interfaces import IFilesystemBundleFactory
        shutil.rmtree(self.tmp)
        for name in self.bundle_names:
            clean_up_bundle(name)
        gsm = getGlobalSiteManager()
        assert gsm.unregisterAdapter(required=(INySite, ),
                                     provided=IFilesystemBundleFactory,
                                     name='Foo')

    def test_create_bundle(self):
        from naaya.core.fsbundles import get_filesystem_bundle_factory
        factory = get_filesystem_bundle_factory(self.site)
        bundle = factory()
        self.assertEqual(bundle.__name__, 'FooSites-bar')
        self.assertEqual(os.listdir(self.tmp), ['FooSites-bar.bundle'])
        self.assertEqual(self.site.get_bundle(), bundle)

    def test_bundle_cfg(self):
        from naaya.core.fsbundles import get_filesystem_bundle_factory
        factory = get_filesystem_bundle_factory(self.site)
        bundle = factory()
        cfg_path = os.path.join(self.tmp, 'FooSites-bar.bundle', 'bundle.cfg')
        f = open(cfg_path, 'rb')
        data = list(f)
        f.close()
        self.assertTrue('parent-bundle = Foo\n') in data

    def test_create_preexisting_bundle(self):
        from naaya.core.fsbundles import get_filesystem_bundle_factory
        factory = get_filesystem_bundle_factory(self.site)
        bundle = factory()
        self.assertRaises(ValueError, factory)

    def test_wrong_site_bundle(self):
        from naaya.core.fsbundles import get_filesystem_bundle_factory
        self.site.set_bundle(bundles.get('Baz'))
        factory = get_filesystem_bundle_factory(self.site)
        self.assertTrue(factory is None)
예제 #8
0
 def test_process_querystring(self):
     site = NySite('test')
     arg_expected = [
         ('', ''),
         ('x', ''),
         ('x=oops', 'x=oops'),
         ('x=oops&skey=&rkey=23', 'x=oops'),
         ('x=&skey=&rkey=23', ''),
         ('start=zz&skey=34&rkey=23&m=&n=oops', 'n=oops'),
         ('m=once&f&start=zz&rkey=1&x=again&n=oops', 'm=once&x=again&n=oops')
     ]
     for arg, expected in arg_expected:
         self.assertEqual(site.process_querystring(arg), expected)
예제 #9
0
    def setUp(self):
        from naaya.core.zope2util import getExtConfiguration as getConfiguration
        from Products.Naaya.NySite import NySite

        self.config = getConfiguration()
        self.config_patch = patch.object(self.config,
                                         'environment', {},
                                         create=True)
        self.config_patch.start()

        self.environ_patch = patch.dict(os.environ)
        self.environ_patch.start()

        self.portal = NySite('test-site')
예제 #10
0
 def setUp(self):
     from Products.Naaya.interfaces import INySite
     from Products.Naaya.NySite import NySite
     from naaya.core.interfaces import IFilesystemBundleFactory
     from naaya.core.fsbundles import register_bundle_factory
     self.bundle_names = []
     self.tmp = tempfile.mkdtemp()
     register_bundle_factory(self.tmp, 'FooSites-', 'Foo')
     self.site = NySite('bar')
     self.site.set_bundle(bundles.get('Foo'))
예제 #11
0
    def add_portal(self):
        try:
            from Products.Naaya.NySite import NySite
        except ImportError:
            self.portal = self.app
            return

        self.app._setObject('portal', NySite(
            'portal', 'portal', 'Naaya Test Site', 'en'))
        self.portal = getattr(self.app, 'portal')
예제 #12
0
    def setUp(self):
        from naaya.core.zope2util import getExtConfiguration as getConfiguration
        from Products.Naaya.NySite import NySite

        self.config = getConfiguration()
        self.config_patch = patch.object(self.config, 'environment', {},
                                         create=True)
        self.config_patch.start()

        self.environ_patch = patch.dict(os.environ)
        self.environ_patch.start()

        self.portal = NySite('test-site')
예제 #13
0
    def setUp(self):
        from App.config import getConfiguration
        from Products.Naaya.NySite import NySite

        self.config = getConfiguration()
        self.config_patch = patch.object(self.config,
                                         'environment', {},
                                         create=True)
        self.config_patch.start()

        self.environ_patch = patch.dict(os.environ)
        self.environ_patch.start()

        self.portal = NySite('test')
        self.portal.portal_email = EmailTool('id_email_tool',
                                             'Test email tool')

        self.TMP_FOLDER = tempfile.mkdtemp()