X-Git-Url: https://code.kerkeslager.com/?p=fwx;a=blobdiff_plain;f=test_phial.py;fp=test_phial.py;h=6ff27d9335fa56fb1b43546ec994e3715dac3256;hp=df7e77112e222f8b26465377c925e843324f7206;hb=fd77e7cd13caaf823abf3bad2ebfdd6bab5f1bd1;hpb=f80262bbe18c56836e612e664d9824ff72d2ca1d diff --git a/test_phial.py b/test_phial.py index df7e771..6ff27d9 100644 --- a/test_phial.py +++ b/test_phial.py @@ -35,6 +35,29 @@ class ResponseTests(unittest.TestCase): ), ) +class HTMLResponseTests(unittest.TestCase): + def test_sets_content_type(self): + response = phial.HTMLResponse('Hello, world') + self.assertEqual(response.content_type, 'text/html') + +class JSONResponseTests(unittest.TestCase): + def test_sets_content_type(self): + response = phial.JSONResponse({ 'foo': 'bar', 'baz': 42 }) + self.assertEqual(response.content_type, 'application/json') + + def test_sets_content(self): + response = phial.JSONResponse({ 'foo': 'bar', 'baz': 42 }) + self.assertEqual(response.content, '{"foo": "bar", "baz": 42}') + + def test_sets_content_json(self): + response = phial.JSONResponse({ 'foo': 'bar', 'baz': 42 }) + self.assertEqual(response.content_json, {"foo": "bar", "baz": 42}) + +class TextResponseTests(unittest.TestCase): + def test_sets_content_type(self): + response = phial.TextResponse('Hello, world\n') + self.assertEqual(response.content_type, 'text/plain') + class _get_status_Tests(unittest.TestCase): def test_basic(self): self.assertEqual(phial._get_status(mock.MagicMock(status=200)), '200 OK')