devtools/fake.py
brancholdstable
changeset 6665 90f2f20367bc
parent 5768 1e73a466aa69
child 6427 c8a5ac2d1eaa
equal deleted inserted replaced
6018:f4d1d5d9ccbb 6665:90f2f20367bc
    14 # details.
    14 # details.
    15 #
    15 #
    16 # You should have received a copy of the GNU Lesser General Public License along
    16 # You should have received a copy of the GNU Lesser General Public License along
    17 # with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
    17 # with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
    18 """Fake objects to ease testing of cubicweb without a fully working environment
    18 """Fake objects to ease testing of cubicweb without a fully working environment
    19 
       
    20 """
    19 """
       
    20 
    21 __docformat__ = "restructuredtext en"
    21 __docformat__ = "restructuredtext en"
    22 
    22 
    23 from logilab.database import get_db_helper
    23 from logilab.database import get_db_helper
    24 
    24 
    25 from cubicweb.req import RequestSessionBase
    25 from cubicweb.req import RequestSessionBase
    28 from cubicweb.devtools import BASE_URL, BaseApptestConfiguration
    28 from cubicweb.devtools import BASE_URL, BaseApptestConfiguration
    29 
    29 
    30 
    30 
    31 class FakeConfig(dict, BaseApptestConfiguration):
    31 class FakeConfig(dict, BaseApptestConfiguration):
    32     translations = {}
    32     translations = {}
       
    33     uiprops = {}
    33     apphome = None
    34     apphome = None
    34     def __init__(self, appid='data', apphome=None, cubes=()):
    35     def __init__(self, appid='data', apphome=None, cubes=()):
    35         self.appid = appid
    36         self.appid = appid
    36         self.apphome = apphome
    37         self.apphome = apphome
    37         self._cubes = cubes
    38         self._cubes = cubes
    38         self['auth-mode'] = 'cookie'
    39         self['auth-mode'] = 'cookie'
    39         self['uid'] = None
    40         self['uid'] = None
    40         self['base-url'] = BASE_URL
    41         self['base-url'] = BASE_URL
    41         self['rql-cache-size'] = 100
    42         self['rql-cache-size'] = 100
       
    43         self.datadir_url = BASE_URL + 'data/'
    42 
    44 
    43     def cubes(self, expand=False):
    45     def cubes(self, expand=False):
    44         return self._cubes
    46         return self._cubes
    45 
    47 
    46     def sources(self):
    48     def sources(self):
    47         return {}
    49         return {'system': {'db-driver': 'sqlite'}}
    48 
    50 
    49 
    51 
    50 class FakeRequest(CubicWebRequestBase):
    52 class FakeRequest(CubicWebRequestBase):
    51     """test implementation of an cubicweb request object"""
    53     """test implementation of an cubicweb request object"""
    52 
    54 
    63         """returns an ordered list of preferred languages"""
    65         """returns an ordered list of preferred languages"""
    64         return ('en',)
    66         return ('en',)
    65 
    67 
    66     def header_if_modified_since(self):
    68     def header_if_modified_since(self):
    67         return None
    69         return None
    68 
       
    69     def base_url(self):
       
    70         """return the root url of the instance"""
       
    71         return BASE_URL
       
    72 
    70 
    73     def relative_path(self, includeparams=True):
    71     def relative_path(self, includeparams=True):
    74         """return the normalized path of the request (ie at least relative
    72         """return the normalized path of the request (ie at least relative
    75         to the instance's root, but some other normalization may be needed
    73         to the instance's root, but some other normalization may be needed
    76         so that the returned path may be used to compare to generated urls
    74         so that the returned path may be used to compare to generated urls