コード例 #1
0
ファイル: __init__.py プロジェクト: grodniewicz/oship
    def setUp(self):
        ZCMLFileLayer.setUp(self)

        # Set up site manager adapter
        zope.component.provideAdapter(
            SiteManagerAdapter, (Interface,), IComponentLookup)

        # Set up traversal
        traversingSetUp()
        zope.component.provideAdapter(
            ContainerTraversable, (ISimpleReadContainer,), ITraversable)

        # Session
        zope.component.provideAdapter(ClientId, (IRequest,), IClientId)
        zope.component.provideAdapter(Session, (IRequest,), ISession)
        zope.component.provideUtility(
            CookieClientIdManager(), IClientIdManager)
        sdc = PersistentSessionDataContainer()
        zope.component.provideUtility(sdc, ISessionDataContainer, '')

        # Set up site
        site = rootFolder()
        site.setSiteManager(LocalSiteManager(site))
        zope.component.hooks.setSite(site)

        return site
コード例 #2
0
ファイル: tests.py プロジェクト: trollfot/dolmen.app.content
    def setUp(self):
        ZCMLFileLayer.setUp(self)
        zope.component.hooks.setHooks()

        # Set up site
        site = rootFolder()
        site.setSiteManager(LocalSiteManager(site))
        zope.component.hooks.setSite(site)
コード例 #3
0
    def setUp(self):
        ZCMLFileLayer.setUp(self)
        zope.component.hooks.setHooks()

        # Set up site
        site = rootFolder()
        site.setSiteManager(LocalSiteManager(site))
        zope.component.hooks.setSite(site)
        security.newInteraction(Participation(Principal('zope.mgr')))
コード例 #4
0
ファイル: __init__.py プロジェクト: grodniewicz/oship
    def setUp(self):
        ZCMLFileLayer.setUp(self)

        # Set up site manager adapter
        zope.component.provideAdapter(
            SiteManagerAdapter, (Interface,), IComponentLookup)

        # Set up site
        site = rootFolder()
        site.setSiteManager(LocalSiteManager(site))
        zope.component.hooks.setSite(site)

        return site
コード例 #5
0
ファイル: test_all.py プロジェクト: trollfot/dolmen.beaker
    def setUp(self):
        ZCMLFileLayer.setUp(self)
        eventtesting.setUp()
        traversingSetUp()
        zope.component.hooks.setHooks()

        # Set up site manager adapter
        zope.component.provideAdapter(
            SiteManagerAdapter, (Interface,), IComponentLookup)

        # Set up site
        site = rootFolder()
        site.setSiteManager(LocalSiteManager(site))
        zope.component.hooks.setSite(site)
コード例 #6
0
class TestExportImport(unittest.TestCase):

    layer = ZCMLFileLayer(zope.app.i18n.tests)

    data = GETTEXT_IMPORT_DATA

    def setUp(self):
        super(TestExportImport, self).setUp()

        self._domain = TranslationDomain()
        self._domain.domain = 'default'

    def testImportExport(self):
        view = ExportImport()
        view.context = self._domain
        view.request = TestRequest()
        view.request.getURL = lambda _x: 'url'

        # Insert some extra lines and comments for the parser to skip
        import_data = b'\n\n'.join(self.data.split(b'\n'))

        view.importMessages(['de'], BytesIO(import_data % b'2002/02/02 02:02'))

        result = view.exportMessages('de')

        dt = time.time()
        dt = time.localtime(dt)
        dt = time.strftime('%Y/%m/%d %H:%M', dt)
        if not isinstance(dt, bytes):
            dt = dt.encode("utf-8")

        expected = self.data.replace(b'# comment\n', b'') % dt
        self.assertEqual(result.strip(), expected.strip())
コード例 #7
0
ファイル: tests.py プロジェクト: trollfot/dolmen.widget.image
    def setUp(self):
        ZCMLFileLayer.setUp(self)

        # Set up site manager adapter
        zope.component.provideAdapter(
            SiteManagerAdapter, (Interface,), IComponentLookup)

        # Set up traversal
        setUp()
        zope.component.provideAdapter(
            ContainerTraversable, (ISimpleReadContainer,), ITraversable)

        # Set up site
        site = rootFolder()
        site.setSiteManager(LocalSiteManager(site))
        zope.component.hooks.setSite(site)
        return site
コード例 #8
0
class ZCMLDependencies(unittest.TestCase):
    layer = ZCMLFileLayer(zope.app.publication.tests,
                          zcml_file='ftest_zcml_dependencies.zcml',
                          name='PublicationDependenciesLayer')

    def test_zcml_can_load_with_only_zope_component_meta(self):
        # this is just an example.  It is supposed to show that the
        # configure.zcml file has loaded successfully.

        request = TestRequest()

        sample = object()
        res = getMultiAdapter((sample, request), IBrowserPublisher)
        self.failUnless(isinstance(res, SimpleComponentTraverser))
        self.failUnless(res.context is sample)
コード例 #9
0
class TestConfiguredCountryUtility(unittest.TestCase):

    layer = ZCMLFileLayer(nti.i18n.locales, zcml_file='configure.zcml')

    def test_country_availability(self):
        availability = component.getUtility(ICountryAvailability)
        self.assertIn(u'us', availability.getAvailableCountries())
        self.assertIn(u"us", availability.getCountries())
        self.assertIn(u'us', [x[0] for x in availability.getCountryListing()])

        self.assertIsInstance(availability.getCountries()[u'us'][u'name'],
                              unicode)

    @skipIfNoPlone
    def test_lookup_utility_with_plone_iface(self):
        from plone.i18n.locales.interfaces import ICountryAvailability as IPlone
        from nti.i18n.locales.countries import CountryAvailability
        utility = component.getUtility(IPlone)
        self.assertIsInstance(utility, CountryAvailability)
コード例 #10
0
ファイル: test_cctld.py プロジェクト: NextThought/nti.i18n
class TestConfiguredTLDUtility(unittest.TestCase):

    layer = ZCMLFileLayer(nti.i18n, zcml_file='configure.zcml')

    def test_full_domain_list(self):
        info = component.getUtility(ICcTLDInformation)
        available = info.getAvailableTLDs()
        with_lang = info.getTLDs()
        for cc in available:
            self.assertIn(cc, with_lang)

        self.assertEqual([u"en"], info.getLanguagesForTLD('us'))
        self.assertIsInstance(info.getLanguagesForTLD('us')[0], unicode)

        # Bad tlds
        self.assertRaises(KeyError, info.getLanguagesForTLD, __name__)

    @skipIfNoPlone
    def test_lookup_utility_with_plone_iface(self):
        from plone.i18n.locales.interfaces import ICcTLDInformation as IPlone
        from nti.i18n.locales.cctld import CcTLDInformation
        utility = component.getUtility(IPlone)
        self.assertIsInstance(utility, CcTLDInformation)
コード例 #11
0
 def tearDown(self):
     endInteraction()
     ZCMLFileLayer.tearDown(self)
コード例 #12
0
 def setUp(self):
     ZCMLFileLayer.setUp(self)
     provideAdapter(get_locale, (Interface,), ILocale)
コード例 #13
0
 def tearDown(self):
     zope.component.hooks.resetHooks()
     zope.component.hooks.setSite()
     security.endInteraction()
     ZCMLFileLayer.tearDown(self)
コード例 #14
0
ファイル: tests.py プロジェクト: grodniewicz/oship
 def setUp(self):
     ZCMLFileLayer.setUp(self)
     newInteraction(TestRequest())
コード例 #15
0
ファイル: tests.py プロジェクト: trollfot/dolmen.xapian
 def setUp(self):
     ZCMLFileLayer.setUp(self)
     EventSetup()
コード例 #16
0
 def setUp(self):
     ZCMLFileLayer.setUp(self)
     newInteraction(TestRequest())
コード例 #17
0
ファイル: tests.py プロジェクト: grodniewicz/oship
 def tearDown(self):
     endInteraction()
     ZCMLFileLayer.tearDown(self)
コード例 #18
0
ファイル: __init__.py プロジェクト: trollfot/dolmen.storage
 def tearDown(self):
     ZCMLFileLayer.tearDown(self)
     zope.component.hooks.resetHooks()
     zope.component.hooks.setSite()
コード例 #19
0
class TestSynchronize(unittest.TestCase):

    layer = ZCMLFileLayer(zope.app.i18n.tests)

    def setUp(self):
        self._domain = domain = TranslationDomain()
        domain.domain = 'default'

        en_catalog = MessageCatalog('en', 'default')
        de_catalog = MessageCatalog('de', 'default')

        en_catalog.setMessage('short_greeting', 'Hello!')
        de_catalog.setMessage('short_greeting', 'Hallo!')

        en_catalog.setMessage('greeting', 'Hello $name, how are you?')
        de_catalog.setMessage('greeting', 'Hallo $name, wie geht es Dir?')

        domain['en-1'] = en_catalog
        domain['de-1'] = de_catalog

    def _getRequest(self, **kw):
        environ = kw.pop('environ', {})
        environ['HTTP_HOST'] = 'foo'
        request = BrowserRequest(BytesIO(), environ=environ, **kw)
        request._traversed_names = ['foo', 'bar']
        return request

    def test_synchronize_imports(self):
        # Trivial test that imports the module.  This would have triggered a
        # deprecation warning in previous versions.
        import zope.app.i18n.browser.synchronize

    def test_create_view_cover(self):
        from zope.app.i18n.browser.synchronize import Synchronize
        request = self._getRequest(
            form={
                'sync_username': '******',
                'sync_password': '******',
                'message_ids': ['short_greeting'],
                'update-msgid-short_greeting': 'short_greeting',
                'update-language-short_greeting': 'en',
            })
        request._cookies['sync_url'] = 'not a valid domain'
        s = Synchronize(self._domain, request)

        self.assertFalse(s._isConnected())
        s._disconnect()
        self.assertFalse(s.canConnect())

        self.assertEqual([], s.getAllLanguages())
        self.assertEqual({}, s.queryMessages())
        self.assertEqual([], s.queryMessageItems())

        self.assertEqual(u'Does not exist', s.getStatus(None, None))
        self.assertEqual(u'New Remote', s.getStatus({}, None))
        self.assertEqual(u'Out of Date',
                         s.getStatus({'mod_time': 1}, {'mod_time': 0}))
        self.assertEqual(u'Newer Local',
                         s.getStatus({'mod_time': 0}, {'mod_time': 1}))
        self.assertEqual(u'Up to Date',
                         s.getStatus({'mod_time': 1}, {'mod_time': 1}))

        s.saveSettings()
        s.synchronize()
        s.queryMessages = lambda: {
            ('short_greeting', 'en'): [{
                'mod_time': 0
            }, {
                'mod_time': 0
            }]
        }
        s.synchronizeMessages()

        del s.queryMessages

        # Now stub out the connection
        class Stub(object):
            def getAllLanguages(self):
                return ('en', )

            def getMessagesFor(self, langs):
                return []

        s._connection = Stub()

        self.assertTrue(s._isConnected())
        self.assertTrue(s.canConnect())
        self.assertEqual(('en', ), s.getAllLanguages())
        self.assertEqual({}, s.queryMessages())

    def test_make_url(self):
        from zope.app.i18n.browser.synchronize import Synchronize
        request = self._getRequest(
            form={
                'sync_username': '******',
                'sync_password': '******',
                'message_ids': ['short_greeting'],
                'update-msgid-short_greeting': 'short_greeting',
                'update-language-short_greeting': 'en',
            })
        s = Synchronize(self._domain, request)
        self.assertEqual(
            'http://*****:*****@localhost:8080/++etc++site/default/zope',
            s._make_sync_url())