Exemple #1
0
 def test_set_cookie_with_secret(self):
     response = BaseResponse()
     response.set_cookie('foo', 'bar', secret='secretkey', path=None)
     expected_set_cookie = (
         'Set-Cookie', 'foo="!VzhGFLGcW+5OMs1s4beLXaqFxAUwgHdWkH5fgapghoI='
         '?gASVDwAAAAAAAACMA2Zvb5SMA2JhcpSGlC4="')
     self.assertIn(expected_set_cookie, response.headerlist)
Exemple #2
0
 def test_set_cookie_with_secret_in_config(self, mock_current_config):
     mock_current_config.return_value = "secretkey"
     response = BaseResponse()
     response.set_cookie('foo', 'bar', path=None)
     expected_set_cookie = (
         'Set-Cookie', 'foo="!VzhGFLGcW+5OMs1s4beLXaqFxAUwgHdWkH5fgapghoI='
         '?gASVDwAAAAAAAACMA2Zvb5SMA2JhcpSGlC4="')
     self.assertIn(expected_set_cookie, response.headerlist)
Exemple #3
0
 def test_delete_cookie(self):
     response = BaseResponse()
     response.delete_cookie('foo')
     expected_set_cookie = (
         'Set-Cookie',
         'foo=""; expires=Sun, 01 Jan 2017 00:00:00 GMT; Max-Age=-1; Path=/'
     )
     self.assertIn(expected_set_cookie, response.headerlist)
Exemple #4
0
 def test_set_cookie_with_max_age(self):
     response = BaseResponse()
     response.set_cookie('foo',
                         'bar',
                         max_age=timedelta(seconds=10),
                         path=None)
     expected_set_cookie = ('Set-Cookie', 'foo=bar; Max-Age=10')
     self.assertIn(expected_set_cookie, response.headerlist)
Exemple #5
0
 def test_set_cookie_with_expires(self):
     response = BaseResponse()
     response.set_cookie('foo',
                         'bar',
                         expires=datetime(2017, 1, 1, 0, 0, 0),
                         path=None)
     expected_set_cookie = (
         'Set-Cookie', 'foo=bar; expires=Sun, 01 Jan 2017 00:00:00 GMT')
     self.assertIn(expected_set_cookie, response.headerlist)
Exemple #6
0
 def test_constructor_headerlist_has_already_content_type(self):
     response = BaseResponse()
     response.headers.add_header('Content-Type', 'application/json')
     expected_content_type = ('Content-Type', 'application/json')
     self.assertIn(expected_content_type, response.headerlist)
     expected_content_type = ('Content-Type', 'text/html; charset=UTF-8')
     self.assertNotIn(expected_content_type, response.headerlist)
Exemple #7
0
    def test_set_invalid_status(self):
        response = BaseResponse()

        def set_status(status):
            response.status = status

        self.assertRaises(ValueError, set_status, -1)
Exemple #8
0
 def test_constructor_headerlist_with_add_header(self):
     response = BaseResponse(headers={'key1': 'value1'})
     expected_content_type = ('key1', 'value1')
     self.assertIn(expected_content_type, response.headerlist)
Exemple #9
0
 def test_add_header(self):
     response = BaseResponse()
     response.headers.add_header('key', 'value')
     self.assertIn(('key', 'value'), response.headerlist)
Exemple #10
0
 def test_constructor_headerlist(self):
     response = BaseResponse()
     expected_content_type = ('Content-Type', 'text/plain;')
     self.assertIn(expected_content_type, response.headerlist)
Exemple #11
0
 def test_set_status(self):
     response = BaseResponse()
     response.status = 200
     self.assertEqual(response.status, '200 OK')
Exemple #12
0
 def test_constructor_status(self):
     response = BaseResponse([b'Body'], 200)
     self.assertEqual(response.status_code, 200)
Exemple #13
0
 def test_constructor_body(self):
     response = BaseResponse([b'Body'])
     self.assertEqual([b'Body'], response.body)
Exemple #14
0
 def test_set_cookie_with_path(self):
     response = BaseResponse()
     response.set_cookie('foo', 'bar', path='/foo')
     expected_set_cookie = ('Set-Cookie', 'foo=bar; Path=/foo')
     self.assertIn(expected_set_cookie, response.headerlist)