Example #1
0
    def test_304_response_from_cpm(self):
        # test that we get a 304 response from the cpm via this template
        mod_time = DateTime()
        cpm = DummyCachingManagerWithPolicy()
        getSiteManager().registerUtility(cpm, ICachingPolicyManager)
        script = self._makeOne('testSTX', 'testSTX.stx')
        script = script.__of__(self.app)
        self.REQUEST.environ['IF_MODIFIED_SINCE'] = '%s;' % rfc1123_date(
            mod_time + 3600)
        data = script(self.REQUEST, self.RESPONSE)

        self.assertEqual(data, '')
        self.assertEqual(self.RESPONSE.getStatus(), 304)
Example #2
0
    def test_index_html_with_304_from_cpm(self):
        cpm = DummyCachingManagerWithPolicy()
        getSiteManager().registerUtility(cpm, ICachingPolicyManager)
        _path, ref = self._extractFile()
        file = self._makeOne('test_file', 'test_file.swf', file=ref)
        file = file.__of__(self.app)

        mod_time = file.modified().timeTime()

        self.REQUEST.environ['IF_MODIFIED_SINCE'] = '%s;' % rfc1123_date(
            mod_time)
        self.REQUEST.environ['IF_NONE_MATCH'] = '%s;' % FAKE_ETAG

        data = file.index_html(self.REQUEST, self.RESPONSE)
        self.assertEqual(len(data), 0)
        self.assertEqual(self.RESPONSE.getStatus(), 304)
Example #3
0
    def test_304_response_from_cpm(self):
        # test that we get a 304 response from the cpm via this template
        from DateTime import DateTime
        from webdav.common import rfc1123_date
        from Products.CMFCore.tests.base.dummy \
            import DummyCachingManagerWithPolicy

        mod_time = DateTime()
        self.root.caching_policy_manager = DummyCachingManagerWithPolicy()
        script = self._makeOne('testReST', 'testReST.rst')
        script = script.__of__(self.root)
        self.REQUEST.environ['IF_MODIFIED_SINCE'] = '%s;' % rfc1123_date(
            mod_time + 3600)
        data = script(self.REQUEST, self.RESPONSE)

        self.assertEqual(data, '')
        self.assertEqual(self.RESPONSE.getStatus(), 304)
Example #4
0
    def test_304_response_from_cpm(self):
        # test that we get a 304 response from the cpm via this template

        from webdav.common import rfc1123_date

        mod_time = DateTime()
        self._setupCachingPolicyManager(DummyCachingManagerWithPolicy())
        content = DummyContent(id='content')
        content.modified_date = mod_time
        content = content.__of__(self.root)
        script = self._makeOne('testDTML', 'testDTML.dtml')
        script = script.__of__(content)
        self.REQUEST.environ['IF_MODIFIED_SINCE'] = '%s;' % rfc1123_date(
            mod_time + 3600)
        data = script(content, self.REQUEST, self.RESPONSE)

        self.assertEqual(data, '')
        self.assertEqual(self.RESPONSE.getStatus(), 304)
Example #5
0
    def test_index_html_with_304_from_cpm(self):
        self._setupCachingPolicyManager(DummyCachingManagerWithPolicy())
        path, ref = self._extractFile()

        from webdav.common import rfc1123_date
        from Products.CMFCore.tests.base.dummy import FAKE_ETAG

        self.root.file = self._makeOne('test_file', 'test_image.jpg', file=ref)
        file = self.root.file

        mod_time = file.modified()

        self.REQUEST.environ['IF_MODIFIED_SINCE'] = '%s;' % rfc1123_date(
            mod_time)
        self.REQUEST.environ['IF_NONE_MATCH'] = '%s;' % FAKE_ETAG

        data = file.index_html(self.REQUEST, self.RESPONSE)
        self.assertEqual(len(data), 0)
        self.assertEqual(self.RESPONSE.getStatus(), 304)
Example #6
0
    def test_index_html_with_304_from_cpm(self):
        self.root.caching_policy_manager = DummyCachingManagerWithPolicy()
        path, ref = self._extractFile()

        import os
        from webdav.common import rfc1123_date
        from base.dummy import FAKE_ETAG

        file = self._makeOne('test_file', 'test_image.gif')
        file = file.__of__(self.root)

        mod_time = os.stat(path)[8]

        self.REQUEST.environ['IF_MODIFIED_SINCE'] = '%s;' % rfc1123_date(
            mod_time)
        self.REQUEST.environ['IF_NONE_MATCH'] = '%s;' % FAKE_ETAG

        data = file.index_html(self.REQUEST, self.RESPONSE)
        self.assertEqual(len(data), 0)
        self.assertEqual(self.RESPONSE.getStatus(), 304)
Example #7
0
    def test_index_html_200_with_cpm(self):
        # should behave the same as without cpm installed
        cpm = DummyCachingManagerWithPolicy()
        getSiteManager().registerUtility(cpm, ICachingPolicyManager)
        _path, ref = self._extractFile()
        file = self._makeOne('test_file', 'test_image.jpg', file=ref)
        file = file.__of__(self.app)

        mod_time = file.modified().timeTime()

        data = file.index_html(self.REQUEST, self.RESPONSE)

        self.assertEqual(len(data), len(ref))
        self.assertEqual(data, ref)
        # ICK!  'HTTPResponse.getHeader' doesn't case-flatten the key!
        self.assertEqual(self.RESPONSE.getHeader('Content-Length'.lower()),
                         str(len(ref)))
        self.assertEqual(self.RESPONSE.getHeader('Content-Type'.lower()),
                         'image/jpeg')
        self.assertEqual(self.RESPONSE.getHeader('Last-Modified'.lower()),
                         rfc1123_date(mod_time))
Example #8
0
    def test_index_html_200_with_cpm(self):
        self._setupCachingPolicyManager(DummyCachingManagerWithPolicy())
        path, ref = self._extractFile()

        from webdav.common import rfc1123_date

        file = self._makeOne('test_file', 'test_image.jpg', file=ref)
        file = file.__of__(self.root)

        mod_time = file.modified()

        data = file.index_html(self.REQUEST, self.RESPONSE)

        # should behave the same as without cpm
        self.assertEqual(len(data), len(ref))
        self.assertEqual(data, ref)
        # ICK!  'HTTPResponse.getHeader' doesn't case-flatten the key!
        self.assertEqual(self.RESPONSE.getHeader('Content-Length'.lower()),
                         str(len(ref)))
        self.assertEqual(self.RESPONSE.getHeader('Content-Type'.lower()),
                         'image/jpeg')
        self.assertEqual(self.RESPONSE.getHeader('Last-Modified'.lower()),
                         rfc1123_date(mod_time))