예제 #1
0
    def test_named_url_pattern(self):
        "Named pattern parameter should reverse to the matching pattern"
        self.config.add_route('artist_detail', 'detail/artist/{pk}', view=RedirectView.as_view())
        response = RedirectView.as_view(pattern_name='artist_detail')(
            DummyRequest(path='/foo/', method='GET'),
            pk=1
        )

        self.assertEqual(response.status_code, 301)
        self.assertEqual(response.headers['Location'], 'http://example.com/detail/artist/1')
예제 #2
0
 def test_direct_instantiation(self):
     """
     It should be possible to use the view without going through .as_view()
     (#21564).
     """
     view = RedirectView()
     response = view.dispatch(
         DummyRequest(path='/foo/', method='HEAD')
     )
     self.assertEqual(response.status_code, 410)
예제 #3
0
    def test_include_args(self):
        "GET arguments can be included in the redirected URL"
        response = RedirectView.as_view(url='/bar/')(
            DummyRequest(path='/foo/', method='GET')
        )
        self.assertEqual(response.status_code, 301)
        self.assertEqual(response.location, '/bar/')

        response = RedirectView.as_view(url='/bar/', query_string=True)(
            DummyRequest(path='/foo/', method='GET', query_string='pork=spam')
        )
        self.assertEqual(response.status_code, 301)
        self.assertEqual(response.location, '/bar/?pork=spam')
예제 #4
0
 def test_include_urlencoded_args(self):
     "GET arguments can be URL-encoded when included in the redirected URL"
     response = RedirectView.as_view(url='/bar/', query_string=True)(
         DummyRequest(path='/foo/', method='GET', query_string='unicode=%E2%9C%93')
     )
     self.assertEqual(response.status_code, 301)
     self.assertEqual(response.location, '/bar/?unicode=%E2%9C%93')
예제 #5
0
 def test_temporary_redirect(self):
     "Permanent redirects are an option"
     response = RedirectView.as_view(url='/bar/', permanent=False)(
         DummyRequest(path='/foo/', method='GET')
     )
     self.assertEqual(response.status_code, 302)
     self.assertEqual(response.location, '/bar/')
예제 #6
0
 def test_permanent_redirect(self):
     "Default is a permanent redirect"
     response = RedirectView.as_view(url='/bar/')(
         DummyRequest(path='/foo/', method='GET')
     )
     self.assertEqual(response.status_code, 301)
     self.assertEqual(response.location, '/bar/')
예제 #7
0
 def test_parameter_substitution(self):
     "Redirection URLs can be parameterized"
     response = RedirectView.as_view(url='/bar/%(object_id)d/')(
         DummyRequest(path='/foo/42/', method='GET'),
         object_id=42
     )
     self.assertEqual(response.status_code, 301)
     self.assertEqual(response.location, '/bar/42/')
예제 #8
0
def main(global_config, **settings):
    """ This function returns a Pyramid WSGI application.
    """
    engine = engine_from_config(settings, 'sqlalchemy.')
    Session.configure(bind=engine)
    Base.metadata.bind = engine
    configure_views(Session)
    config = Configurator(settings=settings)
    config.add_static_view('static', 'static', cache_max_age=3600)

    config.add_route('home', '/', views.HomeView.as_view())
    config.add_route('about', '/about', TemplateView.as_view(template_name='example_project:templates/about.pt'))
    config.add_route('book_list_redirect', '/book', RedirectView.as_view(url='/book/list', permanent=True))
    config.add_route('book_list', '/book/list', views.BookListView.as_view())
    config.add_route('book_update', '/book/update/{pk}', views.BookUpdateView.as_view())
    config.add_route('book_delete', '/book/delete/{pk}', views.BookDeleteView.as_view())
    config.add_route('book_create', '/book/create', views.BookCreateView.as_view())

    return config.make_wsgi_app()
예제 #9
0
 def test_wrong_named_url_pattern(self):
     "A wrong pattern name returns 410 GONE"
     response = RedirectView.as_view(pattern_name='wrong.pattern_name')(
         DummyRequest(path='/foo/', method='GET')
     )
     self.assertEqual(response.status_code, 410)
예제 #10
0
 def test_named_url_pattern_using_args(self):
     self.config.add_route('artist_detail', 'detail/artist/*traverse', view=RedirectView.as_view())
     response = RedirectView.as_view(pattern_name='artist_detail')(DummyRequest(path='/foo/', method='GET'), traverse=(1,2))
     self.assertEqual(response.status_code, 301)
     self.assertEqual(response.headers['Location'], 'http://example.com/detail/artist/1/2')
예제 #11
0
 def test_no_url(self):
     "Without any configuration, returns HTTP 410 GONE"
     response = RedirectView.as_view()(
         DummyRequest(path='/foo/', method='GET')
     )
     self.assertEqual(response.status_code, 410)