devtools/fake.py
branchtls-sprint
changeset 1482 93c613913912
parent 1481 8ea54e7be3e2
child 1802 d628defebc17
equal deleted inserted replaced
1481:8ea54e7be3e2 1482:93c613913912
    22     def __init__(self, appid='data', apphome=None, cubes=()):
    22     def __init__(self, appid='data', apphome=None, cubes=()):
    23         self.appid = appid
    23         self.appid = appid
    24         self.apphome = apphome
    24         self.apphome = apphome
    25         self._cubes = cubes
    25         self._cubes = cubes
    26         self['auth-mode'] = 'cookie'
    26         self['auth-mode'] = 'cookie'
    27         self['uid'] = None 
    27         self['uid'] = None
    28         self['base-url'] = BASE_URL
    28         self['base-url'] = BASE_URL
    29         self['rql-cache-size'] = 100
    29         self['rql-cache-size'] = 100
    30        
    30 
    31     def cubes(self, expand=False):
    31     def cubes(self, expand=False):
    32         return self._cubes
    32         return self._cubes
    33     
    33 
    34     def sources(self):
    34     def sources(self):
    35         return {}
    35         return {}
    36 
    36 
    37 class FakeVReg(object):
    37 class FakeVReg(object):
    38     def __init__(self, schema=None, config=None):
    38     def __init__(self, schema=None, config=None):
    39         self.schema = schema
    39         self.schema = schema
    40         self.config = config or FakeConfig()
    40         self.config = config or FakeConfig()
    41         self.properties = {'ui.encoding': 'UTF8',
    41         self.properties = {'ui.encoding': 'UTF8',
    42                            'ui.language': 'en',
    42                            'ui.language': 'en',
    43                            }
    43                            }
    44         
    44 
    45     def property_value(self, key):
    45     def property_value(self, key):
    46         return self.properties[key]
    46         return self.properties[key]
    47 
    47 
    48     _registries = {
    48     _registries = {
    49         'controllers' : [Mock(id='view'), Mock(id='login'),
    49         'controllers' : [Mock(id='view'), Mock(id='login'),
    50                          Mock(id='logout'), Mock(id='edit')],
    50                          Mock(id='logout'), Mock(id='edit')],
    51         'views' : [Mock(id='primary'), Mock(id='secondary'),
    51         'views' : [Mock(id='primary'), Mock(id='secondary'),
    52                          Mock(id='oneline'), Mock(id='list')],
    52                          Mock(id='oneline'), Mock(id='list')],
    53         }
    53         }
    54     
    54 
    55     def registry_objects(self, name, oid=None):
    55     def registry_objects(self, name, oid=None):
    56         return self._registries[name]
    56         return self._registries[name]
    57     
    57 
    58     def etype_class(self, etype):
    58     def etype_class(self, etype):
    59         class Entity(dict):
    59         class Entity(dict):
    60             e_schema = self.schema[etype]
    60             e_schema = self.schema[etype]
    61             def __init__(self, session, eid, row=0, col=0):
    61             def __init__(self, session, eid, row=0, col=0):
    62                 self.req = session
    62                 self.req = session
   110         pass
   110         pass
   111 
   111 
   112     def set_header(self, header, value):
   112     def set_header(self, header, value):
   113         """set an output HTTP header"""
   113         """set an output HTTP header"""
   114         pass
   114         pass
   115     
   115 
   116     def add_header(self, header, value):
   116     def add_header(self, header, value):
   117         """set an output HTTP header"""
   117         """set an output HTTP header"""
   118         pass
   118         pass
   119     
   119 
   120     def remove_header(self, header):
   120     def remove_header(self, header):
   121         """remove an output HTTP header"""
   121         """remove an output HTTP header"""
   122         pass
   122         pass
   123     
   123 
   124     def get_header(self, header, default=None):
   124     def get_header(self, header, default=None):
   125         """return the value associated with the given input header,
   125         """return the value associated with the given input header,
   126         raise KeyError if the header is not set
   126         raise KeyError if the header is not set
   127         """
   127         """
   128         return self._headers.get(header, default)
   128         return self._headers.get(header, default)
   167         self.pool = FakePool()
   167         self.pool = FakePool()
   168         self.user = user or FakeUser()
   168         self.user = user or FakeUser()
   169         self.is_internal_session = False
   169         self.is_internal_session = False
   170         self.is_super_session = self.user.eid == -1
   170         self.is_super_session = self.user.eid == -1
   171         self._query_data = {}
   171         self._query_data = {}
   172         
   172 
   173     def execute(self, *args):
   173     def execute(self, *args):
   174         pass
   174         pass
   175     def commit(self, *args):
   175     def commit(self, *args):
   176         self._query_data.clear()
   176         self._query_data.clear()
   177     def close(self, *args):
   177     def close(self, *args):
   184         rset.req = self
   184         rset.req = self
   185         return rset
   185         return rset
   186 
   186 
   187     def set_entity_cache(self, entity):
   187     def set_entity_cache(self, entity):
   188         pass
   188         pass
   189     
   189 
   190 class FakeRepo(object):
   190 class FakeRepo(object):
   191     querier = None
   191     querier = None
   192     def __init__(self, schema, vreg=None, config=None):
   192     def __init__(self, schema, vreg=None, config=None):
   193         self.extids = {}
   193         self.extids = {}
   194         self.eids = {}
   194         self.eids = {}
   212             entity = source.before_entity_insertion(session, extid, etype, eid)
   212             entity = source.before_entity_insertion(session, extid, etype, eid)
   213             self.extids[extid] = eid
   213             self.extids[extid] = eid
   214             self.eids[eid] = extid
   214             self.eids[eid] = extid
   215             source.after_entity_insertion(session, extid, entity)
   215             source.after_entity_insertion(session, extid, entity)
   216             return eid
   216             return eid
   217         
   217 
   218     def eid2extid(self, source, eid, session=None):
   218     def eid2extid(self, source, eid, session=None):
   219         return self.eids[eid]
   219         return self.eids[eid]
   220 
   220 
   221 
   221 
   222 class FakeSource(object):
   222 class FakeSource(object):
   227     dbhelper.fti_restriction_sql = indexer.restriction_sql
   227     dbhelper.fti_restriction_sql = indexer.restriction_sql
   228     dbhelper.fti_need_distinct_query = indexer.need_distinct
   228     dbhelper.fti_need_distinct_query = indexer.need_distinct
   229     def __init__(self, uri):
   229     def __init__(self, uri):
   230         self.uri = uri
   230         self.uri = uri
   231 
   231 
   232         
   232 
   233 class FakePool(object):
   233 class FakePool(object):
   234     def source(self, uri):
   234     def source(self, uri):
   235         return FakeSource(uri)
   235         return FakeSource(uri)
   236 
   236 
   237 # commented until proven to be useful
   237 # commented until proven to be useful