예제 #1
0
 def test_get_cache_hit(self):
     views.force_cache_invalidation(self.request)
     views.cache.get(self.cache_key).AndReturn(
         self.mock_contrib_sitemap_response.content)
     self.mox.ReplayAll()
     response = views.sitemap(self.request)
     self.mox.VerifyAll()
     self.assertEqual(
         response.content, self.mock_contrib_sitemap_response.content)
예제 #2
0
 def test_get_cache_hit(self):
     views.force_cache_invalidation(self.request)
     views.cache.get(self.cache_key).AndReturn(
         self.mock_contrib_sitemap_response.content)
     self.mox.ReplayAll()
     response = views.sitemap(self.request)
     self.mox.VerifyAll()
     self.assertEqual(response.content,
                      self.mock_contrib_sitemap_response.content)
예제 #3
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)
예제 #4
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)
예제 #5
0
 def test_get_force_cache_invalidation(self):
     views.force_cache_invalidation(self.request).AndReturn(True)
     views.URLMap.objects.filter(
         site=self.site, status_code=200, on_sitemap=True).AndReturn(
             'mock queryset')
     views.GenericSitemap({'queryset': 'mock queryset'}).AndReturn(
         'mock GenericSitemap')
     views.contrib_sitemap(
         self.request, {'urlmap': 'mock GenericSitemap'}).AndReturn(
             self.mock_contrib_sitemap_response)
     self.mock_contrib_sitemap_response.render()
     views.cache.set(
         self.cache_key, self.mock_contrib_sitemap_response.content,
         settings.URLOGRAPHER_CACHE_TIMEOUT)
     self.mox.ReplayAll()
     response = views.sitemap(self.request)
     self.mox.VerifyAll()
     self.assertEqual(
         response.content, self.mock_contrib_sitemap_response.content)
예제 #6
0
 def test_get_force_cache_invalidation(self):
     views.force_cache_invalidation(self.request).AndReturn(True)
     views.URLMap.objects.filter(site=self.site,
                                 status_code=200,
                                 on_sitemap=True).AndReturn('mock queryset')
     views.GenericSitemap({
         'queryset': 'mock queryset'
     }).AndReturn('mock GenericSitemap')
     views.contrib_sitemap(self.request, {
         'urlmap': 'mock GenericSitemap'
     }).AndReturn(self.mock_contrib_sitemap_response)
     self.mock_contrib_sitemap_response.render()
     views.cache.set(self.cache_key,
                     self.mock_contrib_sitemap_response.content,
                     settings.URLOGRAPHER_CACHE_TIMEOUT)
     self.mox.ReplayAll()
     response = views.sitemap(self.request)
     self.mox.VerifyAll()
     self.assertEqual(response.content,
                      self.mock_contrib_sitemap_response.content)
예제 #7
0
    def test_get_cache_miss(self):
        qs = self.mock.CreateMockAnything()

        views.force_cache_invalidation(self.request)
        views.cache.get(self.cache_key)
        views.URLMap.objects.filter(
            site=self.site, status_code=200, on_sitemap=True).AndReturn(qs)
        qs.select_related('site').AndReturn('mock queryset')

        views.CustomSitemap({'queryset': 'mock queryset'}).AndReturn(
            'mock CustomSitemap')
        self.mock_contrib_sitemap_response.render()
        views.contrib_sitemap(
            self.request, {'urlmap': 'mock CustomSitemap'}).AndReturn(
                self.mock_contrib_sitemap_response)
        views.cache.set(
            self.cache_key, self.mock_contrib_sitemap_response.content,
            settings.URLOGRAPHER_CACHE_TIMEOUT)
        self.mock.ReplayAll()
        response = views.sitemap(self.request)
        self.mock.VerifyAll()
        self.assertEqual(
            response.content, self.mock_contrib_sitemap_response.content)