示例#1
0
    def test_set_default_cookie_cache(self, mock_request):
        response = Response()
        response.headers = {
            'Set-Cookie': 'name=value',
        }
        response.url = 'http://www.test.com/path'
        mock_request.return_value = response

        C0 = self.cookie_cache
        C1 = Cache()
        C2 = Cache()

        get('http://www.test.com/path')
        mock_request.assert_called_with('GET', 'http://www.test.com/path', allow_redirects=True)
        get('http://www.test.com/path')
        mock_request.assert_called_with('GET', 'http://www.test.com/path', cookies={'name': 'value'}, allow_redirects=True)

        set_default_cookie_cache(C1)

        get('http://www.test.com/path')
        mock_request.assert_called_with('GET', 'http://www.test.com/path', allow_redirects=True)
        get('http://www.test.com/path')
        mock_request.assert_called_with('GET', 'http://www.test.com/path', cookies={'name': 'value'}, allow_redirects=True)

        set_default_cookie_cache(C2)

        get('http://www.test.com/path')
        mock_request.assert_called_with('GET', 'http://www.test.com/path', allow_redirects=True)
        get('http://www.test.com/path')
        mock_request.assert_called_with('GET', 'http://www.test.com/path', cookies={'name': 'value'}, allow_redirects=True)

        set_default_cookie_cache(C0)

        get('http://www.test.com/path')
        mock_request.assert_called_with('GET', 'http://www.test.com/path', cookies={'name': 'value'}, allow_redirects=True)
示例#2
0
    def test_disable_default_cookie_cache(self, mock_request):
        """
        Test disable default cookie cache (by setting default cookie cache to None)
        """
        response = Response()
        response.headers = {
            'Set-Cookie': 'name=value',
        }
        response.url = 'http://www.test.com/path'
        mock_request.return_value = response

        get('http://www.test.com/path')
        mock_request.assert_called_with('GET', 'http://www.test.com/path', allow_redirects=True)
        get('http://www.test.com/path')
        mock_request.assert_called_with('GET', 'http://www.test.com/path', cookies={'name': 'value'}, allow_redirects=True)

        set_default_cookie_cache(None)

        get('http://www.test.com/path')
        mock_request.assert_called_with('GET', 'http://www.test.com/path', allow_redirects=True)
        get('http://www.test.com/path')
        mock_request.assert_called_with('GET', 'http://www.test.com/path', allow_redirects=True)
示例#3
0
 def tearDown(self):
     set_default_redirect_cache(self._orig_default_redirect_cache)
     set_default_cookie_cache(self._orig_default_cookie_cache)
     set_default_cache(self._orig_default_cache)
     super(TestDefaults, self).tearDown()