Exemplo n.º 1
0
 def test_route_gone(self):
     models.URLMap.objects.create(site=self.site,
                                  status_code=410,
                                  path='/410')
     request = self.factory.get('/410')
     response = views.route(request)
     self.assertEqual(response.status_code, 410)
Exemplo n.º 2
0
 def test_redirect(self):
     target = models.URLMap.objects.create(
         site=self.site, path='/target', status_code=204)
     models.URLMap.objects.create(
         site=self.site, path='/source', redirect=target, status_code=302)
     response = views.route(self.factory.get('/source'))
     self.assertEqual(response.status_code, 302)
     self.assertEqual(response._headers['location'][1],
                      'http://example.com/target')
Exemplo n.º 3
0
 def test_handler_as_func_newrelic(self):
     self.mox.StubOutWithMock(views, 'newrelic')
     models.URLMap.objects.create(
         site=self.site, path='/page', status_code=206)
     views.newrelic.agent = self.mox.CreateMockAnything()
     views.newrelic.agent.set_transaction_name(
         'urlographer.sample_views:sample_handler.get',
         'Python/urlographer')
     self.mox.ReplayAll()
     response = views.route(self.factory.get('/page'))
     self.assertContains(response, 'modified content', status_code=206)
Exemplo n.º 4
0
 def test_content_map_class_based_view(self):
     content_map = models.ContentMap(
         view='urlographer.sample_views.SampleClassView')
     content_map.options['initkwargs'] = {
         'test_val': 'testing 1 2 3'}
     content_map.save()
     models.URLMap.objects.create(
         site=self.site, path='/test', content_map=content_map)
     response = views.route(self.factory.get('/test'))
     self.assertEqual(response.status_code, 200)
     self.assertEqual(response.content, 'test value=testing 1 2 3')
Exemplo n.º 5
0
 def test_content_map_class_based_view(self):
     content_map = models.ContentMap(
         view='urlographer.sample_views.SampleClassView')
     content_map.options['initkwargs'] = {'test_val': 'testing 1 2 3'}
     content_map.save()
     models.URLMap.objects.create(site=self.site,
                                  path='/test',
                                  content_map=content_map)
     response = views.route(self.factory.get('/test'))
     self.assertEqual(response.status_code, 200)
     self.assertEqual(response.content, 'test value=testing 1 2 3')
Exemplo n.º 6
0
 def test_handler_as_class_newrelic(self):
     self.mock.StubOutWithMock(views, 'newrelic')
     models.URLMap.objects.create(
         site=self.site, path='/page', status_code=402, force_secure=False)
     views.newrelic.agent = self.mock.CreateMockAnything()
     views.newrelic.agent.set_transaction_name(
         'urlographer.sample_views:SampleClassHandler.get',
         'Python/urlographer')
     self.mock.ReplayAll()
     response = views.route(self.factory.get('/page'))
     self.assertContains(response, 'payment required', status_code=402)
Exemplo n.º 7
0
 def test_content_map_view_function(self):
     content_map = models.ContentMap(
         view='urlographer.sample_views.sample_view')
     content_map.options['test_val'] = 'testing 1 2 3'
     content_map.save()
     urlmap = models.URLMap.objects.create(
         site=self.site, path='/test', content_map=content_map)
     request = self.factory.get('/test')
     response = views.route(request)
     self.assertEqual(response.status_code, 200)
     self.assertEqual(response.content, 'test value=testing 1 2 3')
     self.assertEqual(request.urlmap, urlmap)
Exemplo n.º 8
0
 def test_redirect(self):
     target = models.URLMap.objects.create(site=self.site,
                                           path='/target',
                                           status_code=204)
     models.URLMap.objects.create(site=self.site,
                                  path='/source',
                                  redirect=target,
                                  status_code=302)
     response = views.route(self.factory.get('/source'))
     self.assertEqual(response.status_code, 302)
     self.assertEqual(response._headers['location'][1],
                      'http://example.com/target')
Exemplo n.º 9
0
 def test_route_redirect_canonical(self):
     content_map = models.ContentMap(
         view='django.views.generic.base.TemplateView')
     content_map.options['initkwargs'] = {
         'template_name': 'admin/base.html'}
     content_map.save()
     models.URLMap.objects.create(site=self.site, path='/test',
                                  content_map=content_map)
     response = views.route(self.factory.get('/TEST'))
     self.assertEqual(response.status_code, 301)
     self.assertEqual(response._headers['location'][1],
                      'http://example.com/test')
Exemplo n.º 10
0
 def test_force_cache_invalidation(self):
     path = '/test'
     request = self.factory.get(path)
     site = get_current_site(request)
     url_map = models.URLMap(site=site, path=path, status_code=204)
     self.mox.StubOutWithMock(views, 'force_cache_invalidation')
     self.mox.StubOutWithMock(models.URLMapManager, 'cached_get')
     views.force_cache_invalidation(request).AndReturn(True)
     models.URLMapManager.cached_get(
         site, path, force_cache_invalidation=True).AndReturn(url_map)
     self.mox.ReplayAll()
     response = views.route(request)
     self.assertEqual(response.status_code, 204)
Exemplo n.º 11
0
 def test_content_map_view_function(self):
     content_map = models.ContentMap(
         view='urlographer.sample_views.sample_view')
     content_map.options['test_val'] = 'testing 1 2 3'
     content_map.save()
     urlmap = models.URLMap.objects.create(site=self.site,
                                           path='/test',
                                           content_map=content_map)
     request = self.factory.get('/test')
     response = views.route(request)
     self.assertEqual(response.status_code, 200)
     self.assertEqual(response.content, 'test value=testing 1 2 3')
     self.assertEqual(request.urlmap, urlmap)
Exemplo n.º 12
0
 def test_force_cache_invalidation(self):
     path = '/test'
     request = self.factory.get(path)
     site = get_current_site(request)
     url_map = models.URLMap(site=site, path=path, status_code=204)
     self.mox.StubOutWithMock(views, 'force_cache_invalidation')
     self.mox.StubOutWithMock(models.URLMapManager, 'cached_get')
     views.force_cache_invalidation(request).AndReturn(True)
     models.URLMapManager.cached_get(
         site, path, force_cache_invalidation=True).AndReturn(
             url_map)
     self.mox.ReplayAll()
     response = views.route(request)
     self.assertEqual(response.status_code, 204)
Exemplo n.º 13
0
 def test_route_redirect_canonical(self):
     content_map = models.ContentMap(
         view='django.views.generic.base.TemplateView')
     content_map.options['initkwargs'] = {
         'template_name': 'admin/base.html'
     }
     content_map.save()
     models.URLMap.objects.create(site=self.site,
                                  path='/test',
                                  content_map=content_map)
     response = views.route(self.factory.get('/TEST'))
     self.assertEqual(response.status_code, 301)
     self.assertEqual(response._headers['location'][1],
                      'http://example.com/test')
Exemplo n.º 14
0
 def test_content_map_class_based_view_newrelic(self):
     self.mox.StubOutWithMock(views, 'newrelic')
     content_map = models.ContentMap(
         view='urlographer.sample_views.SampleClassView')
     content_map.options['initkwargs'] = {
         'test_val': 'testing 1 2 3'}
     content_map.save()
     models.URLMap.objects.create(
         site=self.site, path='/test', content_map=content_map)
     views.newrelic.agent = self.mox.CreateMockAnything()
     views.newrelic.agent.set_transaction_name(
         'urlographer.sample_views:SampleClassView.get',
         'Python/urlographer')
     self.mox.ReplayAll()
     response = views.route(self.factory.get('/test'))
     self.assertEqual(response.status_code, 200)
     self.assertEqual(response.content, 'test value=testing 1 2 3')
Exemplo n.º 15
0
 def test_content_map_view_function_newrelic(self):
     self.mox.StubOutWithMock(views, 'newrelic')
     content_map = models.ContentMap(
         view='urlographer.sample_views.sample_view')
     content_map.options['test_val'] = 'testing 1 2 3'
     content_map.save()
     urlmap = models.URLMap.objects.create(
         site=self.site, path='/test', content_map=content_map)
     request = self.factory.get('/test')
     views.newrelic.agent = self.mox.CreateMockAnything()
     views.newrelic.agent.set_transaction_name(
         'urlographer.sample_views:sample_view.get',
         'Python/urlographer')
     self.mox.ReplayAll()
     response = views.route(request)
     self.assertEqual(response.status_code, 200)
     self.assertEqual(response.content, 'test value=testing 1 2 3')
     self.assertEqual(request.urlmap, urlmap)
Exemplo n.º 16
0
    def test_not_force_secure_wo_request_secure(self):
        content_map = models.ContentMap(
            view='urlographer.sample_views.sample_view')
        content_map.options['test_val'] = 'testing 1 2 3'
        content_map.save()
        urlmap = models.URLMap.objects.create(
            site=self.site, path='/test', content_map=content_map,
            force_secure=False)

        request = self.factory.get('/test')
        self.mock.StubOutWithMock(request, 'is_secure')
        self.mock.StubOutWithMock(views, 'get_redirect_url_with_query_string')

        self.mock.ReplayAll()
        response = views.route(request)
        self.mock.VerifyAll()

        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.content, 'test value=testing 1 2 3')
        self.assertEqual(request.urlmap, urlmap)
Exemplo n.º 17
0
    def test_signal_called_on_urlmap_bound_to_request(self):
        content_map = models.ContentMap(
            view='urlographer.sample_views.sample_view')
        content_map.options['test_val'] = 'testing 1 2 3'
        content_map.save()
        urlmap = models.URLMap.objects.create(
            site=self.site, path='/test', content_map=content_map,
            force_secure=False)
        request = self.factory.get('/test')

        # Mocks:
        self.mock.StubOutWithMock(
            views.urlmap_bound_to_request, 'send')

        # Expected calls:
        views.urlmap_bound_to_request.send(sender=None, request=request)

        self.mock.ReplayAll()
        response = views.route(request)
        self.mock.VerifyAll()
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.content, 'test value=testing 1 2 3')
        self.assertEqual(request.urlmap, urlmap)
Exemplo n.º 18
0
    def test_force_secure_wo_request_secure(self):
        content_map = models.ContentMap(
            view='urlographer.sample_views.sample_view')
        content_map.options['test_val'] = 'testing 1 2 3'
        content_map.save()
        urlmap = models.URLMap.objects.create(
            site=self.site, path='/test', content_map=content_map,
            force_secure=True)

        request = self.factory.get('/test')
        self.mock.StubOutWithMock(request, 'is_secure')
        self.mock.StubOutWithMock(views, 'get_redirect_url_with_query_string')
        # Calls
        request.is_secure().AndReturn(False)
        views.get_redirect_url_with_query_string(
            request, unicode(urlmap)).AndReturn(unicode(urlmap) + '?ok=true')

        self.mock.ReplayAll()
        response = views.route(request)
        self.mock.VerifyAll()

        self.assertEqual(response.status_code, 301)
        self.assertEqual(response['Location'], unicode(urlmap) + '?ok=true')
        self.assertEqual(request.urlmap, urlmap)
Exemplo n.º 19
0
 def test_handler_as_class(self):
     models.URLMap.objects.create(
         site=self.site, path='/page', status_code=402)
     response = views.route(self.factory.get('/page'))
     self.assertContains(response, 'payment required', status_code=402)
Exemplo n.º 20
0
 def test_handler_as_func(self):
     models.URLMap.objects.create(
         site=self.site, path='/page', status_code=206)
     response = views.route(self.factory.get('/page'))
     self.assertContains(response, 'modified content', status_code=206)
Exemplo n.º 21
0
 def test_handler_as_func(self):
     models.URLMap.objects.create(site=self.site,
                                  path='/page',
                                  status_code=206)
     response = views.route(self.factory.get('/page'))
     self.assertContains(response, 'modified content', status_code=206)
Exemplo n.º 22
0
 def test_handler_as_class(self):
     models.URLMap.objects.create(site=self.site,
                                  path='/page',
                                  status_code=402)
     response = views.route(self.factory.get('/page'))
     self.assertContains(response, 'payment required', status_code=402)
Exemplo n.º 23
0
 def test_handler_as_string(self):
     models.URLMap.objects.create(
         site=self.site, path='/page', status_code=403, force_secure=False)
     response = views.route(self.factory.get('/page'))
     self.assertContains(response, 'modified content', status_code=403)
Exemplo n.º 24
0
 def test_route_gone(self):
     models.URLMap.objects.create(
         site=self.site, status_code=410, path='/410')
     request = self.factory.get('/410')
     response = views.route(request)
     self.assertEqual(response.status_code, 410)