[sync schema hooks] pylint fixes have broken hasattr test
# copyright 2003-2011 LOGILAB S.A. (Paris, FRANCE), all rights reserved.# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr## This file is part of CubicWeb.## CubicWeb is free software: you can redistribute it and/or modify it under the# terms of the GNU Lesser General Public License as published by the Free# Software Foundation, either version 2.1 of the License, or (at your option)# any later version.## CubicWeb is distributed in the hope that it will be useful, but WITHOUT# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more# details.## You should have received a copy of the GNU Lesser General Public License along# with CubicWeb. If not, see <http://www.gnu.org/licenses/>."""Fake objects to ease testing of cubicweb without a fully working environment"""__docformat__="restructuredtext en"fromlogilab.databaseimportget_db_helperfromcubicweb.reqimportRequestSessionBasefromcubicweb.cwvregimportCubicWebVRegistryfromcubicweb.web.requestimportCubicWebRequestBasefromcubicweb.web.http_headersimportHeadersfromcubicweb.devtoolsimportBASE_URL,BaseApptestConfigurationclassFakeConfig(dict,BaseApptestConfiguration):translations={}uiprops={}apphome=Nonedef__init__(self,appid='data',apphome=None,cubes=()):self.appid=appidself.apphome=apphomeself._cubes=cubesself['auth-mode']='cookie'self['uid']=Noneself['base-url']=BASE_URLself['rql-cache-size']=100self.datadir_url=BASE_URL+'data/'defcubes(self,expand=False):returnself._cubesdefsources(self):return{'system':{'db-driver':'sqlite'}}classFakeRequest(CubicWebRequestBase):"""test implementation of an cubicweb request object"""def__init__(self,*args,**kwargs):ifnot(argsor'vreg'inkwargs):kwargs['vreg']=CubicWebVRegistry(FakeConfig(),initlog=False)kwargs['https']=Falseself._url=kwargs.pop('url',None)or'view?rql=Blop&vid=blop'super(FakeRequest,self).__init__(*args,**kwargs)self._session_data={}self._headers_in=Headers()defset_cookie(self,name,value,maxage=300,expires=None,secure=False):super(FakeRequest,self).set_cookie(name,value,maxage,expires,secure)cookie=self.get_response_header('Set-Cookie')self._headers_in.setHeader('Cookie',cookie)## Implement request abstract APIdefheader_accept_language(self):"""returns an ordered list of preferred languages"""return('en',)defheader_if_modified_since(self):returnNonedefrelative_path(self,includeparams=True):"""return the normalized path of the request (ie at least relative to the instance's root, but some other normalization may be needed so that the returned path may be used to compare to generated urls """ifself._url.startswith(BASE_URL):url=self._url[len(BASE_URL):]else:url=self._urlifincludeparams:returnurlreturnurl.split('?',1)[0]defget_header(self,header,default=None,raw=True):"""return the value associated with the given input header, raise KeyError if the header is not set """ifraw:returnself._headers_in.getRawHeaders(header,[default])[0]returnself._headers_in.getHeader(header,default)## extend request API to control headers in / out valuesdefset_request_header(self,header,value,raw=False):"""set an input HTTP header"""ifisinstance(value,basestring):value=[value]ifraw:self._headers_in.setRawHeaders(header,value)else:self._headers_in.setHeader(header,value)defget_response_header(self,header,default=None,raw=False):"""return the value associated with the given input header, raise KeyError if the header is not set """ifraw:returnself.headers_out.getRawHeaders(header,default)[0]else:returnself.headers_out.getHeader(header,default)defvalidate_cache(self):passdefbuild_url_params(self,**kwargs):# overriden to get predictable resulttsargs=[]forparam,valuesinsorted(kwargs.iteritems()):ifnotisinstance(values,(list,tuple)):values=(values,)forvalueinvalues:assertvalueisnotNoneargs.append(u'%s=%s'%(param,self.url_quote(value)))return'&'.join(args)classFakeUser(object):login='toto'eid=0defin_groups(self,groups):returnTrueclassFakeSession(RequestSessionBase):def__init__(self,repo=None,user=None,vreg=None):self.repo=repoifvregisNone:vreg=getattr(self.repo,'vreg',None)ifvregisNone:vreg=CubicWebVRegistry(FakeConfig(),initlog=False)self.vreg=vregself.cnxset=FakeConnectionsSet()self.user=userorFakeUser()self.is_internal_session=Falseself.transaction_data={}defexecute(self,*args,**kwargs):passdefcommit(self,*args):self.transaction_data.clear()defclose(self,*args):passdefsystem_sql(self,sql,args=None):passdefset_entity_cache(self,entity):pass# for use with enabled_security context managerread_security=write_security=Truedefinit_security(self,*args):returnNone,Nonedefreset_security(self,*args):returnclassFakeRepo(object):querier=Nonedef__init__(self,schema,vreg=None,config=None):self.extids={}self.eids={}self._count=0self.schema=schemaself.config=configorFakeConfig()self.vreg=vregorCubicWebVRegistry(self.config,initlog=False)self.vreg.schema=schemaself.sources=[]definternal_session(self):returnFakeSession(self)defextid2eid(self,source,extid,etype,session,insert=True):try:returnself.extids[extid]exceptKeyError:ifnotinsert:returnNoneself._count+=1eid=self._countentity=source.before_entity_insertion(session,extid,etype,eid)self.extids[extid]=eidself.eids[eid]=extidsource.after_entity_insertion(session,extid,entity)returneiddefeid2extid(self,source,eid,session=None):returnself.eids[eid]classFakeSource(object):dbhelper=get_db_helper('sqlite')def__init__(self,uri):self.uri=uriclassFakeConnectionsSet(object):defsource(self,uri):returnFakeSource(uri)