import phial
+class RequestTests(unittest.TestCase):
+ def test_GET(self):
+ request = phial.Request({
+ 'REQUEST_METHOD': 'GET',
+ 'QUERY_STRING': 'foo=bar&baz=qux',
+ })
+
+ self.assertEqual(request.GET['foo'], ['bar'])
+ self.assertEqual(request.GET['baz'], ['qux'])
+
+ def test_parameters(self):
+ request = phial.Request({
+ 'REQUEST_METHOD': 'GET',
+ 'QUERY_STRING': 'foo=bar&baz=qux',
+ })
+
+ self.assertEqual(request.parameters['foo'], ['bar'])
+ self.assertEqual(request.parameters['baz'], ['qux'])
+
class ResponseTests(unittest.TestCase):
def test_content_can_be_positional_argument(self):
response = phial.Response('Hello, world\n', content_type='text/plain')
response = phial.TextResponse('Hello, world\n')
self.assertEqual(response.content_type, 'text/plain')
+class RedirectResponse(unittest.TestCase):
+ def test_takes_location_as_positional_argument(self):
+ response = phial.RedirectResponse('/location')
+ self.assertEqual(response.location, '/location')
+
+ def test_takes_location_as_keyword_argument(self):
+ response = phial.RedirectResponse(location='/location')
+ self.assertEqual(response.location, '/location')
+
+ def test_permanent_defaults_to_true(self):
+ response = phial.RedirectResponse('/location')
+ self.assertEqual(response.permanent, True)
+
+ def test_status(self):
+ self.assertEqual(
+ phial.RedirectResponse('/location', permanent=True).status,
+ 308,
+ )
+ self.assertEqual(
+ phial.RedirectResponse('/location', permanent=False).status,
+ 307,
+ )
+
+ def test_headers(self):
+ self.assertEqual(
+ phial.RedirectResponse('/location').headers,
+ (('Location','/location'),),
+ )
+
+ def test_content(self):
+ self.assertEqual(
+ phial.RedirectResponse('/location').content,
+ (b'',),
+ )
+
class _get_status_Tests(unittest.TestCase):
def test_basic(self):
self.assertEqual(phial._get_status(mock.MagicMock(status=200)), '200 OK')
+ self.assertEqual(phial._get_status(mock.MagicMock(status=307)), '307 Temporary Redirect')
+ self.assertEqual(phial._get_status(mock.MagicMock(status=308)), '308 Permanent Redirect')
class _get_content_Tests(unittest.TestCase):
def test_bytes(self):