Esempio n. 1
0
    def test_uses_auth_token_to_lookup_response(self):
        req_headers = {'Authorization': 'Bearer some-token'}
        resp_headers = {'Vary': 'Authorization'}

        request = type('Request', (object, ), {
            'headers': req_headers,
            'url': self.url
        })()
        expected_key = CacheController.cache_key(request)
        response = Mock(headers=resp_headers, status=301)

        # we set the status to 301 so that it is immediately returned without performing any etag/date checks to see if
        # cache eviction is required
        self.c.cache = DictCache({expected_key: response})

        assert self.req(headers=req_headers) == response
Esempio n. 2
0
    def test_cache_response_no_store(self):
        resp = Mock()
        cache = DictCache({self.url: resp})
        cc = CacheController(cache)

        request = type('Request', (object, ), {
            'headers': {},
            'url': self.url
        })()
        cache_key = cc.cache_key(request)

        resp = self.resp({'cache-control': 'no-store'})
        assert cc.cache.get(cache_key)

        cc.cache_response(self.req(), resp)
        assert not cc.cache.get(cache_key)