def test_overridden_realms_config(self):
        self.layer.load_zcml_string(
            '\n'.join((
                    '<configure xmlns:publisher="http://namespaces.' + \
                        'zope.org/ftw.publisher">',

                    '    <publisher:override-realm',
                    '        url="http://localhost:9090/site"',
                    '        username="******"',
                    '        password="******" />',

                    '</configure>'
                    )))

        portal = self.providing_stub([IPloneSiteRoot, IAttributeAnnotatable])
        self.expect(portal.portal_url.getPortalObject()).result(portal)
        self.replay()

        config = IConfig(portal)
        self.assertTrue(config)
        self.assertFalse(config.is_update_realms_possible())

        self.assertEquals(len(config.getRealms()), 1)

        with self.assertRaises(AttributeError):
            config.appendRealm(Realm(1, 'http://site', 'foo', 'pw'))
Ejemplo n.º 2
0
    def test_overridden_realms_config(self):
        self.layer.load_zcml_string(
            '\n'.join((
                    '<configure xmlns:publisher="http://namespaces.' + \
                        'zope.org/ftw.publisher">',

                    '    <publisher:override-realm',
                    '        url="http://localhost:9090/site"',
                    '        username="******"',
                    '        password="******" />',

                    '</configure>'
                    )))

        portal = self.providing_stub([IPloneSiteRoot, IAttributeAnnotatable])
        portal.portal_url.getPortalObject.return_value = portal

        config = IConfig(portal)
        self.assertTrue(config)
        self.assertFalse(config.is_update_realms_possible())

        self.assertEquals(len(config.getRealms()), 1)

        with self.assertRaises(AttributeError):
            config.appendRealm(Realm(1, 'http://site', 'foo', 'pw'))
Ejemplo n.º 3
0
 def handleAdd(self, action):
     """
     This handler handles a click on the "Add Realm"-Button.
     If no errors occured, it adds a new Realm to the Config.
     @param action:      ActionInfo object provided by z3c.form
     @return:            None (form is shown) or Response-redirect
     """
     data, errors = self.extractData()
     config = IConfig(self.context)
     if len(errors)==0:
         assert config.is_update_realms_possible()
         # url + username has to be unique
         for realm in config.getRealms():
             if realm.url==data['url'] and realm.username==data['username']:
                 self.statusMessage(
                     'This URL / Username combination already exists!',
                     'error')
                 return
         kwargs = {
             'active': data['active'] and 1 or 0,
             'url': data['url'],
             'username': data['username'],
             'password': data['password'],
             }
         realm = Realm(**kwargs)
         config.appendRealm(realm)
         self.statusMessage('Added realm successfully')
         return self.request.RESPONSE.redirect('./@@publisher-config')
Ejemplo n.º 4
0
 def handleSave(self, action):
     """
     """
     data, errors = self.extractData()
     config = IConfig(self.context)
     assert config.is_update_realms_possible()
     if len(errors)==0:
         # get realm
         currentRealm = self.getRealmById(data['id'])
         if not currentRealm:
             raise Exception('Could not find realm')
         # no other realm should have same url+username
         for realm in config.getRealms():
             if realm!=currentRealm:
                 if realm.username==data['username'] and\
                    realm.url==data['url']:
                     self.statusMessage(
                         'This URL / Username combination already exists!',
                         )
                     return
         # update realm
         currentRealm.active = data['active'] and 1 or 0
         currentRealm.url = data['url']
         currentRealm.username = data['username']
         if data['password'] and len(data['password'])>0:
             currentRealm.password = data['password']
         self.statusMessage('Updated realm successfully')
         return self.request.RESPONSE.redirect('./@@publisher-config')
Ejemplo n.º 5
0
 def handleAdd(self, action):
     """
     This handler handles a click on the "Add Realm"-Button.
     If no errors occured, it adds a new Realm to the Config.
     @param action:      ActionInfo object provided by z3c.form
     @return:            None (form is shown) or Response-redirect
     """
     data, errors = self.extractData()
     config = IConfig(self.context)
     if len(errors)==0:
         assert config.is_update_realms_possible()
         # url + username has to be unique
         for realm in config.getRealms():
             if realm.url==data['url'] and realm.username==data['username']:
                 self.statusMessage(
                     'This URL / Username combination already exists!',
                     'error')
                 return
         kwargs = {
             'active': data['active'] and 1 or 0,
             'url': data['url'],
             'username': data['username'],
             'password': data['password'],
             }
         realm = Realm(**kwargs)
         config.appendRealm(realm)
         self.statusMessage('Added realm successfully')
         return self.request.RESPONSE.redirect('./@@publisher-config')
Ejemplo n.º 6
0
 def handleSave(self, action):
     """
     """
     data, errors = self.extractData()
     config = IConfig(self.context)
     assert config.is_update_realms_possible()
     if len(errors)==0:
         # get realm
         currentRealm = self.getRealmById(data['id'])
         if not currentRealm:
             raise Exception('Could not find realm')
         # no other realm should have same url+username
         for realm in config.getRealms():
             if realm!=currentRealm:
                 if realm.username==data['username'] and\
                    realm.url==data['url']:
                     self.statusMessage(
                         'This URL / Username combination already exists!',
                         )
                     return
         # update realm
         currentRealm.active = data['active'] and 1 or 0
         currentRealm.url = data['url']
         currentRealm.username = data['username']
         if data['password'] and len(data['password'])>0:
             currentRealm.password = data['password']
         self.statusMessage('Updated realm successfully')
         return self.request.RESPONSE.redirect('./@@publisher-config')
Ejemplo n.º 7
0
    def test_default_realms_config(self):
        portal = self.providing_stub([IPloneSiteRoot, IAttributeAnnotatable])
        portal.portal_url.getPortalObject.return_value = portal
        config = IConfig(portal)
        self.assertTrue(config)
        self.assertTrue(config.is_update_realms_possible())

        self.assertEquals(len(config.getRealms()), 0)
        config.appendRealm(Realm(1, 'http://site', 'foo', 'pw'))
        self.assertEquals(len(config.getRealms()), 1)
    def test_default_realms_config(self):
        portal = self.providing_stub([IPloneSiteRoot, IAttributeAnnotatable])
        self.expect(portal.portal_url.getPortalObject()).result(portal)
        self.replay()

        config = IConfig(portal)
        self.assertTrue(config)
        self.assertTrue(config.is_update_realms_possible())

        self.assertEquals(len(config.getRealms()), 0)
        config.appendRealm(Realm(1, 'http://site', 'foo', 'pw'))
        self.assertEquals(len(config.getRealms()), 1)