Example #1
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")
Example #2
0
 def test_only(self):
     bag = InputBag()
     bag.load({"QUERY_STRING": "hello=you&goodbye=me&name=Joe"})
     self.assertEqual(bag.only("hello", "name"), {
         "hello": "you",
         "name": "Joe"
     })
Example #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")
Example #4
0
 def test_all_with_values(self):
     bag = InputBag()
     bag.load({"QUERY_STRING": "hello=you"})
     """
         {"filter": [{}]}
     """
     self.assertEqual(bag.all_as_values(), {"hello": "you"})
Example #5
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"})
Example #6
0
 def test_all_without_internal_values(self):
     bag = InputBag()
     bag.load({"QUERY_STRING": "hello=you&__token=tok"})
     """
         {"filter": [{}]}
     """
     self.assertEqual(bag.all_as_values(internal_variables=False),
                      {"hello": "you"})
Example #7
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"))
Example #8
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)
Example #9
0
 def test_has(self):
     bag = InputBag()
     bag.load({"QUERY_STRING": "hello=you&goodbye=me"})
     self.assertTrue(bag.has("hello", "goodbye"))
Example #10
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")