Fix the charset
[fwx] / src / test_fwx.py
index 6f5eada..0887039 100644 (file)
@@ -5,19 +5,15 @@ import fwx
 
 class RequestTests(unittest.TestCase):
     def test_GET(self):
-        request = fwx.Request({
-            'PATH_INFO': '/',
+        request = fwx.Request('GET', '/', {
             'QUERY_STRING': 'foo=bar&baz=qux',
-            'REQUEST_METHOD': 'GET',
         })
 
         self.assertEqual(request.GET['foo'], ['bar'])
         self.assertEqual(request.GET['baz'], ['qux'])
 
     def test_parameters(self):
-        request = fwx.Request({
-            'PATH_INFO': '/',
-            'REQUEST_METHOD': 'GET',
+        request = fwx.Request('GET', '/', {
             'QUERY_STRING': 'foo=bar&baz=qux',
         })
 
@@ -45,26 +41,27 @@ class ResponseTests(unittest.TestCase):
 
     def test_headers(self):
         response = fwx.Response(
-            content_type='text/plain',
+            content_type='text/plain; charset=utf-8',
             content='Hello, world\n',
         )
 
         self.assertEqual(
             response.headers,
             (
-                ('Content-Type', 'text/plain'),
+                ('Content-Type', 'text/plain; charset=utf-8'),
+                ('X-Content-Type-Options', 'nosniff'),
             ),
         )
 
 class HTMLResponseTests(unittest.TestCase):
     def test_sets_content_type(self):
         response = fwx.HTMLResponse('<html><body>Hello, world</body></html>')
-        self.assertEqual(response.content_type, 'text/html')
+        self.assertEqual(response.content_type, 'text/html; charset=utf-8')
 
 class JSONResponseTests(unittest.TestCase):
     def test_sets_content_type(self):
         response = fwx.JSONResponse({ 'foo': 'bar', 'baz': 42 })
-        self.assertEqual(response.content_type, 'application/json')
+        self.assertEqual(response.content_type, 'application/json; charset=utf-8')
 
     def test_sets_content(self):
         response = fwx.JSONResponse({ 'foo': 'bar', 'baz': 42 })
@@ -77,7 +74,7 @@ class JSONResponseTests(unittest.TestCase):
 class TextResponseTests(unittest.TestCase):
     def test_sets_content_type(self):
         response = fwx.TextResponse('Hello, world\n')
-        self.assertEqual(response.content_type, 'text/plain')
+        self.assertEqual(response.content_type, 'text/plain; charset=utf-8')
 
 class RedirectResponse(unittest.TestCase):
     def test_takes_location_as_positional_argument(self):
@@ -144,10 +141,7 @@ class route_on_subpath_Tests(unittest.TestCase):
         )
 
         self.assertEqual(
-            router(fwx.Request({
-                'PATH_INFO': '/bar/bara/anne/',
-                'REQUEST_METHOD': 'GET',
-            })).content,
+            router(fwx.Request('GET', '/bar/bara/anne/')).content,
             'bar',
         )
 
@@ -161,10 +155,7 @@ class route_on_subpath_Tests(unittest.TestCase):
         )
 
         self.assertEqual(
-            router(fwx.Request({
-                'PATH_INFO': '/bar/bara/anne/',
-                'REQUEST_METHOD': 'GET',
-            })).content,
+            router(fwx.Request('GET', '/bar/bara/anne/')).content,
             'bara/anne/',
         )
 
@@ -178,12 +169,17 @@ class route_on_subpath_Tests(unittest.TestCase):
         )
 
         self.assertEqual(
-            router(fwx.Request({
-                'PATH_INFO': '/bar/bara/anne/',
-                'REQUEST_METHOD': 'GET',
-            })).content,
+            router(fwx.Request('GET', '/bar/bara/anne/')).content,
             '/bar/bara/anne/',
         )
 
+class default_file_not_found_Tests(unittest.TestCase):
+    def test_responds(self):
+        response = fwx.default_file_not_found_handler(
+            fwx.Request('GET', '/bar/bara/anne/'),
+        )
+
+        self.assertNotEqual(response, None)
+
 if __name__ == '__main__':
     unittest.main()