Changeset 2609 in products


Ignore:
Timestamp:
Jul 2, 2010 1:46:49 PM (14 years ago)
Author:
mylan
Message:

Register IGAuthUtility to LocalSiteManager? on installation and bound to configlet; some refactoring and updates

Location:
quintagroup.gauth/trunk/quintagroup/gauth
Files:
3 added
4 edited

Legend:

Unmodified
Added
Removed
  • quintagroup.gauth/trunk/quintagroup/gauth/configure.zcml

    r2603 r2609  
    77 
    88  <include package=".browser" /> 
    9  
    10   <utility 
    11       factory=".utility.GAuthUtility" /> 
    129 
    1310  <genericsetup:registerProfile 
  • quintagroup.gauth/trunk/quintagroup/gauth/interfaces.py

    r2606 r2609  
    11from zope.interface import Interface, Attribute 
    22 
    3 class IGAuthInterface(Interface): 
     3class IGAuthUtility(Interface): 
    44    """ Utility, which operate with authentication data, 
    55        stored in Google Data configlet. 
  • quintagroup.gauth/trunk/quintagroup/gauth/tests.py

    r2608 r2609  
    44#from zope.testing import doctestunit 
    55#from zope.component import testing 
     6from zope.component import queryUtility 
     7from zope.component import getSiteManager 
    68from Testing import ZopeTestCase as ztc 
    79 
     
    1517 
    1618import quintagroup.gauth 
     19from quintagroup.gauth.interfaces import IGAuthUtility 
    1720 
    1821class GauthLayer(PloneSite): 
     
    4851 
    4952class TestInstall(TestCase): 
     53 
    5054    def afterSetUp(self): 
    5155        self.loginAsPortalOwner() 
     
    6367        self.assert_("quintagroup.gauth" in aifs, aifs) 
    6468 
     69    def testUtility(self): 
     70        lsm = getSiteManager(self.portal) 
     71        gauth = lsm.queryUtility(IGAuthUtility) 
     72        self.assert_(gauth is not None) 
     73        self.assert_(gauth.gconf is not None) 
    6574 
    6675class TestConfiglet(FunctionalTestCase): 
     
    8493    def test_update(self): 
    8594        temail, tpass = "tester@test.com", "secret" 
    86         from quintagroup.gauth.interfaces import IGAuthInterface 
    87         from zope.component import queryUtility 
    88         gauth_util = queryUtility(IGAuthInterface) 
    89         gauth_util.gconf_init(self.portal, self.portal.REQUEST) 
     95        gauth_util = queryUtility(IGAuthUtility) 
    9096        url = self.save_url + '&form.gauth_email='+temail + '&form.gauth_pass='+tpass 
    9197        self.publish(url, self.basic_auth) 
    9298        self.assert_(gauth_util.email == temail) 
    9399        self.assert_(gauth_util.password == tpass) 
    94          
     100 
    95101 
    96102def test_suite(): 
  • quintagroup.gauth/trunk/quintagroup/gauth/utility.py

    r2608 r2609  
    88from plone.memoize.view import memoize_contextless 
    99 
    10 from quintagroup.gauth.interfaces import IGAuthInterface 
     10from quintagroup.gauth.interfaces import IGAuthUtility 
    1111from quintagroup.gauth.browser.configlet import IGAuthConfigletSchema 
    1212 
     
    2020 
    2121class GAuthUtility(object): 
    22     implements(IGAuthInterface) 
     22    implements(IGAuthUtility) 
    2323 
    2424    gconf = None 
    25  
    26     def gconf_init(self, context, request): 
    27         pps = queryMultiAdapter((context, request), name="plone_portal_state") 
     25     
     26    def __init__(self, context): 
     27        # Bind utility to the context 
     28        pps = queryMultiAdapter((context, context.REQUEST), name="plone_portal_state") 
    2829        self.gconf = queryAdapter(pps.portal(), IGAuthConfigletSchema) 
    2930 
     
    3132    def email(self): 
    3233        """ Get the email.""" 
    33         if not self.gconf: 
    34             return None 
    35         return self.gconf.gauth_email 
     34        return getattr(self.gconf, 'gauth_email', '') 
    3635 
    3736    @property 
    3837    def password(self): 
    3938        """ Get the password.""" 
    40         if not self.gconf: 
    41             return None 
    42         return self.gconf.gauth_pass 
     39        return getattr(self.gconf, 'gauth_pass', '') 
    4340 
    4441 
     
    5552 
    5653            def __init__(self): 
    57                 gauth_util = queryUtility(IGAuthInterface) 
     54                gauth_util = queryUtility(IGAuthUtility) 
    5855                self.service = gdata.spreadsheet.service.SpreadsheetService( 
    5956                                   gauth_util.email, gauth_util.password) 
Note: See TracChangeset for help on using the changeset viewer.