コード例 #1
0
ファイル: test_webapi.py プロジェクト: notoriousno/shiji
 def test_content_type_no_charset(self):
     "Request Content-Type does not have a character set specified"
     test_request = DummyRequest()
     test_request.setHeader("Content-Type", "application/json")
     outer_wrap = webapi.json_arguments([("arg1", unicode)])
     inner_wrap = outer_wrap(self.dummy_render_func)
     self.assertEqual(str(webapi.CharsetNotUTF8Error(test_request)),
                      inner_wrap(self, test_request))
コード例 #2
0
ファイル: test_webapi.py プロジェクト: notoriousno/shiji
 def test_content_type_charset_not_utf8(self):
     "Request Content-Type characters set is not UTF-8"
     test_request = DummyRequest()
     test_request.setHeader("Content-Type", "application/json; charset=iso-1022-jp")
     outer_wrap = webapi.json_arguments([("arg1", unicode)])
     inner_wrap = outer_wrap(self.dummy_render_func)
     self.assertEqual(str(webapi.CharsetNotUTF8Error(test_request)),
                      inner_wrap(self, test_request))
コード例 #3
0
 def test_content_type_no_charset(self):
     "Request Content-Type does not have a character set specified"
     test_request = DummyRequest()
     test_request.setHeader("Content-Type", "application/json")
     outer_wrap = webapi.json_arguments([("arg1", unicode)])
     inner_wrap = outer_wrap(self.dummy_render_func)
     self.assertEqual(str(webapi.CharsetNotUTF8Error(test_request)),
                      inner_wrap(self, test_request))
コード例 #4
0
ファイル: test_webapi.py プロジェクト: notoriousno/shiji
 def test_no_content_type_set(self):
     "Request does not have a Content-Type set"
     test_request = DummyRequest()
     
     outer_wrap = webapi.json_arguments([("arg1", unicode)])
     inner_wrap = outer_wrap(self.dummy_render_func)
     self.assertEqual(str(webapi.ContentTypeError(test_request)),
                      inner_wrap(self, test_request))
コード例 #5
0
    def test_no_content_type_set(self):
        "Request does not have a Content-Type set"
        test_request = DummyRequest()

        outer_wrap = webapi.json_arguments([("arg1", unicode)])
        inner_wrap = outer_wrap(self.dummy_render_func)
        self.assertEqual(str(webapi.ContentTypeError(test_request)),
                         inner_wrap(self, test_request))
コード例 #6
0
ファイル: test_webapi.py プロジェクト: notoriousno/shiji
 def test_content_type_content_type_mismatch(self):
     "Request Content-Type doesn't match expected type."
     test_request = DummyRequest()
     test_request.setHeader("Content-Type", "image/jpeg; charset=utf-8")
     outer_wrap = webapi.json_arguments([("arg1", unicode)],
                                        content_type="application/json")
     inner_wrap = outer_wrap(self.dummy_render_func)
     self.assertEqual(str(webapi.ContentTypeError(test_request)),
                      inner_wrap(self, test_request))
コード例 #7
0
ファイル: test_webapi.py プロジェクト: notoriousno/shiji
 def test_content_required_arg_missing_optional_flag_false(self):
     "Request JSON arguments missing required argument."
     test_request = DummyRequest()
     test_request.setHeader("Content-Type", "application/json; charset=utf-8")
     test_request.write(json.dumps({"arg2" : 1}))
     outer_wrap = webapi.json_arguments([("arg1", unicode, False)])
     inner_wrap = outer_wrap(self.dummy_render_func)
     self.assertEqual(str(webapi.ValueError(test_request, "arg1", "Argument is missing.")),
                      inner_wrap(self, test_request))
コード例 #8
0
ファイル: test_webapi.py プロジェクト: notoriousno/shiji
 def test_content_arg_type_mismatch_optional_arg(self):
     "Request JSON optional arguments contain data which doesn't match expected type."
     test_request = DummyRequest()
     test_request.setHeader("Content-Type", "application/json; charset=utf-8")
     test_request.write(json.dumps({"arg1" : 1}))
     outer_wrap = webapi.json_arguments([("arg1", unicode, True)])
     inner_wrap = outer_wrap(self.dummy_render_func)
     self.assertEqual(str(webapi.ValueError(test_request, "arg1", "Must be of type unicode")),
                      inner_wrap(self, test_request))
コード例 #9
0
ファイル: test_webapi.py プロジェクト: notoriousno/shiji
 def test_content_not_dict(self):
     "Request content contained in a dictionary/hash."
     test_request = DummyRequest()
     test_request.setHeader("Content-Type", "application/json; charset=utf-8")
     test_request.write(json.dumps("not a dict"))
     outer_wrap = webapi.json_arguments([("arg1", unicode)])
     inner_wrap = outer_wrap(self.dummy_render_func)
     self.assertEqual(str(webapi.RequestNotHashError(test_request)),
                      inner_wrap(self, test_request))
コード例 #10
0
ファイル: test_webapi.py プロジェクト: notoriousno/shiji
 def test_content_invalid_json(self):
     "Request content not valid JSON."
     test_request = DummyRequest()
     test_request.setHeader("Content-Type", "application/json; charset=utf-8")
     test_request.write("boingo! bad json!")
     outer_wrap = webapi.json_arguments([("arg1", unicode)])
     inner_wrap = outer_wrap(self.dummy_render_func)
     self.assertEqual(str(webapi.JSONDecodeError(test_request)),
                      inner_wrap(self, test_request))
コード例 #11
0
 def test_content_type_content_type_mismatch(self):
     "Request Content-Type doesn't match expected type."
     test_request = DummyRequest()
     test_request.setHeader("Content-Type", "image/jpeg; charset=utf-8")
     outer_wrap = webapi.json_arguments([("arg1", unicode)],
                                        content_type="application/json")
     inner_wrap = outer_wrap(self.dummy_render_func)
     self.assertEqual(str(webapi.ContentTypeError(test_request)),
                      inner_wrap(self, test_request))
コード例 #12
0
 def test_content_type_charset_not_utf8(self):
     "Request Content-Type characters set is not UTF-8"
     test_request = DummyRequest()
     test_request.setHeader("Content-Type",
                            "application/json; charset=iso-1022-jp")
     outer_wrap = webapi.json_arguments([("arg1", unicode)])
     inner_wrap = outer_wrap(self.dummy_render_func)
     self.assertEqual(str(webapi.CharsetNotUTF8Error(test_request)),
                      inner_wrap(self, test_request))
コード例 #13
0
 def test_content_invalid_json(self):
     "Request content not valid JSON."
     test_request = DummyRequest()
     test_request.setHeader("Content-Type",
                            "application/json; charset=utf-8")
     test_request.write("boingo! bad json!")
     outer_wrap = webapi.json_arguments([("arg1", unicode)])
     inner_wrap = outer_wrap(self.dummy_render_func)
     self.assertEqual(str(webapi.JSONDecodeError(test_request)),
                      inner_wrap(self, test_request))
コード例 #14
0
 def test_content_not_dict(self):
     "Request content contained in a dictionary/hash."
     test_request = DummyRequest()
     test_request.setHeader("Content-Type",
                            "application/json; charset=utf-8")
     test_request.write(json.dumps("not a dict"))
     outer_wrap = webapi.json_arguments([("arg1", unicode)])
     inner_wrap = outer_wrap(self.dummy_render_func)
     self.assertEqual(str(webapi.RequestNotHashError(test_request)),
                      inner_wrap(self, test_request))
コード例 #15
0
 def test_content_required_arg_missing_optional_flag_false(self):
     "Request JSON arguments missing required argument."
     test_request = DummyRequest()
     test_request.setHeader("Content-Type",
                            "application/json; charset=utf-8")
     test_request.write(json.dumps({"arg2": 1}))
     outer_wrap = webapi.json_arguments([("arg1", unicode, False)])
     inner_wrap = outer_wrap(self.dummy_render_func)
     self.assertEqual(
         str(webapi.ValueError(test_request, "arg1",
                               "Argument is missing.")),
         inner_wrap(self, test_request))
コード例 #16
0
 def test_content_arg_type_mismatch_optional_arg(self):
     "Request JSON optional arguments contain data which doesn't match expected type."
     test_request = DummyRequest()
     test_request.setHeader("Content-Type",
                            "application/json; charset=utf-8")
     test_request.write(json.dumps({"arg1": 1}))
     outer_wrap = webapi.json_arguments([("arg1", unicode, True)])
     inner_wrap = outer_wrap(self.dummy_render_func)
     self.assertEqual(
         str(
             webapi.ValueError(test_request, "arg1",
                               "Must be of type unicode")),
         inner_wrap(self, test_request))