コード例 #1
0
 def test_only_array_based_inputs(self):
     bag = InputBag()
     bag.load({"QUERY_STRING": "user[]=user1&user[]=user2"})
     self.assertEqual(bag.get("user[]"), ["user1", "user2"])
     bag = InputBag()
     bag.load({"QUERY_STRING": "user[user1]=value&user[user2]=value"})
     self.assertEqual(bag.get("user"), {"user1": "value", "user2": "value"})
コード例 #2
0
 def test_can_parse_post_params_from_url_encoded(self):
     bag = InputBag()
     bag.load({
         "wsgi.input": self.bytes_data,
         "CONTENT_TYPE": "application/x-www-form-urlencoded",
     })
     self.assertEqual(bag.get("jack"), "Daniels")
コード例 #3
0
 def test_can_parse_post_params(self):
     bag = InputBag()
     bag.load({
         "wsgi.input": self.post_data,
         "CONTENT_TYPE": "application/json"
     })
     self.assertEqual(bag.get("param"), "hey")
コード例 #4
0
 def test_can_parse_duplicate_values(self):
     bag = InputBag()
     bag.load({"QUERY_STRING": "filter[name]=Joe&filter[last]=Bill"})
     """
         {"filter": [{}]}
     """
     self.assertTrue("name" in bag.get("filter"))
     self.assertTrue("last" in bag.get("filter"))
コード例 #5
0
 def test_can_parse_post_data(self):
     bag = InputBag()
     bag.load({
         "CONTENT_LENGTH":
         len(str(json.dumps({"__token": 1}))),
         "wsgi.input":
         io.BytesIO(bytes(json.dumps({"__token": 1}), "utf-8")),
     })
     self.assertEqual(bag.get("__token"), 1)
コード例 #6
0
 def test_can_parse_query_string(self):
     bag = InputBag()
     bag.load({"QUERY_STRING": "hello=you&goodbye=me"})
     self.assertEqual(bag.get("hello"), "you")
     self.assertEqual(bag.get("goodbye"), "me")