def test_request_factory(self): factory = RequestFactory() request = factory.get('/somewhere/') response = get_view(request) self.assertEqual(response.status_code, 200) self.assertContains(response, 'This is a test')
def view_param_list(self, view, command): if not views.has_view(view): return [] vi = views.get_view(view) if command == "POST": return vi.postParams else: return vi.getParams
def view_bad(context): view = context.view # Unknown view: axiomatically bad. if not views.has_view(view): return True # Check to see if this view doesn't like this type of pages. # This handles file/directory disconnects. vi = views.get_view(view) if not vi.accepts_page(context.page): return True # History view requires history to be available. if view == 'history' and not context.page.hashistory(): return True # It's a good view. return False
def viewFactory(context): # We must handle virtualization before anything else, because # otherwise we will swan around dealing with a nonexistent # page. res = pageranges.virtualize_page(context) if res: # The result is a virtualized page that replaces the # real page (plus a number of bits and pieces changed # in the context). context.set_page(res) context.setvar("pagename", res.root.name) context.setvar("basepage", res.root.path) else: context.setvar("basepage", context.page.path) # Directories have a default view type that they may express # a desire for; we transparently honor that desire if there # has not been an explicit view set. # Not redirecting and just showing is more transparent and # nicer. if context.page.type == "dir": pv = context.pref_view(context.page) if pv and context.view != pv and \ not "view-format-set-explicitly" in context: context.setview(pv) elif context.page.type == "file" and \ 'view-format-set-explicitly' not in context and \ 'remap-normal-to-showcomments' in context: context.setview('showcomments') # Reject the bad and the ugly. if view_bad(context): return views.BadView(context) # Create the actual view from the factory given. vi = views.get_view(context.view) return vi.factory(context)
def view_cmd_allowed(self, view, command): if not views.has_view(view): return False vi = views.get_view(view) return vi.accepts_command(command)