def _get_request(self, layerid, username=None): from c2cgeoportal.models import DBSession, User request = createDummyRequest() request.matchdict = {'layer_id': str(layerid)} if username is not None: request.user = DBSession.query(User).filter_by( username=username).one() return request
def _get_request(self, layerid, username=None): from c2cgeoportal.models import DBSession, User request = createDummyRequest() request.matchdict = {'layer_id': str(layerid)} if username is not None: request.user = DBSession.query(User).filter_by( username=username ).one() return request
def _create_dummy_request(self, username=None, params=None): from c2cgeoportal.models import DBSession, User request = createDummyRequest(params=params) request.responce = Response() request.user = None if username: request.user = DBSession.query(User) \ .filter_by(username=username).one() return request
def _create_entry_obj(self, username=None, params={}): from c2cgeoportal.views.entry import Entry request = createDummyRequest() request.static_url = lambda url: '/dummy/static/url' request.route_url = lambda url, **kwargs: \ request.registry.settings['mapserv_url'] request.params = params return Entry(request)
def test_web_client_functionalities(self): from c2cgeoportal.models import DBSession, User from c2cgeoportal.tests.functional import mapserv_url, createDummyRequest from c2cgeoportal.views.entry import Entry request = createDummyRequest() request.static_url = lambda url: 'http://example.com/dummy/static/url' request1 = createDummyRequest() request1.static_url = lambda url: 'http://example.com/dummy/static/url' request1.user = DBSession.query(User).filter(User.username == '__test_user1').one() request2 = createDummyRequest() request2.static_url = lambda url: 'http://example.com/dummy/static/url' request2.user = DBSession.query(User).filter(User.username == '__test_user2').one() settings = { 'functionalities': { 'anonymous': { "__test_s": "anonymous", "__test_a": ["a1", "a2"] }, 'registered': { "__test_s": "registered", "__test_a": ["r1", "r2"] }, 'available_in_templates': ['__test_s', '__test_a'], }, 'mapserv_url': mapserv_url, } request.registry.settings.update(settings) request1.registry.settings.update(settings) request2.registry.settings.update(settings) annon = Entry(request)._getVars() u1 = Entry(request1)._getVars() u2 = Entry(request2)._getVars() self.assertEquals(annon['functionality'], {"__test_s": ["anonymous"], "__test_a": ["a1", "a2"]}) self.assertEquals(u1['functionality'], {"__test_s": ["registered"], "__test_a": ["r1", "r2"]}) self.assertEquals(u2['functionality'], {"__test_s": ["db"], "__test_a": ["db1", "db2"]})
def _create_request_obj(self, username=None, params={}, **kwargs): from c2cgeoportal.models import DBSession, User request = createDummyRequest(**kwargs) request.static_url = lambda url: '/dummy/static/url' request.route_url = lambda url, **kwargs: \ request.registry.settings['mapserv_url'] request.params = params if username is not None: request.user = DBSession.query(User) \ .filter_by(username=username).one() return request
def _create_dummy_request(self, username=None): from c2cgeoportal.models import DBSession, User request = createDummyRequest({ 'mapserv_url': mapserv_url }) request.params = {"map": os.path.join( os.path.dirname(os.path.abspath(__file__)), 'c2cgeoportal_test.map' )} if username: request.user = DBSession.query(User) \ .filter_by(username=username).one() return request
def test_functionalities(self): from c2cgeoportal.tests.functional import createDummyRequest from c2cgeoportal.models import DBSession, User from c2cgeoportal.lib.functionality import get_functionality request = createDummyRequest() request.user = None request1 = createDummyRequest() request1.user = DBSession.query(User).filter(User.username == '__test_user1').one() request2 = createDummyRequest() request2.user = DBSession.query(User).filter(User.username == '__test_user2').one() settings = { 'functionalities': { 'anonymous': {}, 'registered': {}, } } self.assertEquals(get_functionality('__test_s', settings, request), []) self.assertEquals(get_functionality('__test_a', settings, request), []) self.assertEquals(get_functionality('__test_s', settings, request1), []) self.assertEquals(get_functionality('__test_a', settings, request1), []) self.assertEquals(get_functionality('__test_s', settings, request2), ['db']) self.assertEquals(get_functionality('__test_a', settings, request2), ['db1', 'db2']) settings = { 'functionalities': { 'anonymous': {}, 'registered': { "__test_s": "registered", "__test_a": ["r1", "r2"] } } } self.assertEquals(get_functionality('__test_s', settings, request), []) self.assertEquals(get_functionality('__test_a', settings, request), []) self.assertEquals(get_functionality('__test_s', settings, request1), ['registered']) self.assertEquals(get_functionality('__test_a', settings, request1), ['r1', 'r2']) self.assertEquals(get_functionality('__test_s', settings, request2), ['db']) self.assertEquals(get_functionality('__test_a', settings, request2), ['db1', 'db2']) settings = { 'functionalities': { 'anonymous': { "__test_s": "anonymous", "__test_a": ["a1", "a2"] }, 'registered': {} } } self.assertEquals(get_functionality('__test_s', settings, request), ['anonymous']) self.assertEquals(get_functionality('__test_a', settings, request), ['a1', 'a2']) self.assertEquals(get_functionality('__test_s', settings, request1), ['anonymous']) self.assertEquals(get_functionality('__test_a', settings, request1), ['a1', 'a2']) self.assertEquals(get_functionality('__test_s', settings, request2), ['db']) self.assertEquals(get_functionality('__test_a', settings, request2), ['db1', 'db2']) settings = { 'functionalities': { 'anonymous': { "__test_s": "anonymous", "__test_a": ["a1", "a2"] }, 'registered': { "__test_s": "registered", "__test_a": ["r1", "r2"] } } } self.assertEquals(get_functionality('__test_s', settings, request), ['anonymous']) self.assertEquals(get_functionality('__test_a', settings, request), ['a1', 'a2']) self.assertEquals(get_functionality('__test_s', settings, request1), ['registered']) self.assertEquals(get_functionality('__test_a', settings, request1), ['r1', 'r2']) self.assertEquals(get_functionality('__test_s', settings, request2), ['db']) self.assertEquals(get_functionality('__test_a', settings, request2), ['db1', 'db2'])