def test_context_lookup(self): from pyramid_layout.config import add_panel from pyramid_layout.layout import LayoutManager from pyramid.config import Configurator from pyramid.testing import DummyRequest request = DummyRequest() config = Configurator() request.config = config request.registry = config.registry def panel_int(context, request): return 'panel int %s' % context def panel_str(context, request): return 'panel str %s' % context def panel_str_noname(context, request): return 'panel str noname %s' % context add_panel(config, panel_int, name='howdy', context=int) add_panel(config, panel_str, name='howdy', context=str) add_panel(config, panel_str_noname) config.commit() self.assertEqual(LayoutManager(1, request).render_panel('howdy'), 'panel int 1') self.assertEqual(LayoutManager(1, request).render_panel('howdy', context='1'), 'panel str 1') self.assertEqual(LayoutManager('2', request).render_panel('howdy'), 'panel str 2') self.assertEqual(LayoutManager('2', request).render_panel('howdy', context=2), 'panel int 2') self.assertEqual(LayoutManager('2', request).render_panel(), 'panel str noname 2')
def setUp(self): self.request = testing.DummyRequest() self.context = testing.DummyResource() self.config = testing.setUp(request=self.request) self.config.include('pyramid_layout') self.request.layout_manager = LayoutManager(self.context, self.request) self.request.layout_manager.layout = AppLayout(self.context, self.request)
def setUp(self): self.config = testing.setUp(request=testing.DummyRequest()) configure(self.config) self.request = get_current_request() from pyramid_layout.layout import LayoutManager self.request.layout_manager = LayoutManager('context', 'requestr')
def setUp(self): from pyramid_bimt.tests.test_group_model import _make_group initTestingDB(groups=True, users=True, auditlog_types=True) self.config = testing.setUp(request=testing.DummyRequest()) configure(self.config) self.request = get_current_request() self.request.user = User.by_id(1) self.group1 = _make_group(name='group1', product_id='1') self.group2 = _make_group(name='group2', product_id='2') self.request.user.groups = [self.group1, ] from pyramid_layout.layout import LayoutManager self.request.layout_manager = LayoutManager('context', 'requestr')
def func( params=None, cookies=None, post=None, current_route_name=None, current_route_path=None, context=None, ): post = post or {} if params is not None: params.update(post) else: params = post cookies = cookies or {} def_csrf = 'default_csrf' if u'csrf_token' not in post.keys(): post.update({'csrf_token': def_csrf}) pyramid_request.params = params pyramid_request.POST = post pyramid_request.json_body = post pyramid_request.cookies = cookies pyramid_request.session = BeakerSessionFactoryConfig()(pyramid_request) pyramid_request.config = {} pyramid_request.registry = config.registry csrf_token = Mock() csrf_token.return_value = def_csrf pyramid_request.session.get_csrf_token = csrf_token pyramid_request.actionmenu = ActionMenu() pyramid_request.navigation = Navigation() pyramid_request.is_popup = False if current_route_path: if not current_route_name: current_route_name = current_route_path route = DummyRoute(name=current_route_name, result=current_route_path) mapper = DummyRouteContext(route=route) pyramid_request.matched_dict = {} pyramid_request.matched_route = route pyramid_request.registry.registerUtility(mapper, IRoutesMapper) if context: from pyramid_layout.layout import LayoutManager pyramid_request.context = context pyramid_request.layout_manager = LayoutManager( context, pyramid_request) return pyramid_request