예제 #1
0
    def test_encode_json_data_none(self):
        data = {"param1": "value 1", "param2": None}

        r = JSONRenderer()
        body, content_type = r.encode_params(data)
        self.assertEqual(content_type, "application/json")
        self.assertIn('"param2": null', body)
        self.assertIn('"param1": "value 1"', body)
예제 #2
0
    def test_encode_json_data_including_array(self):
        data = {"param1": "value 1", "param2": ["value2", "value3"]}

        r = JSONRenderer()
        body, content_type = r.encode_params(data)
        self.assertEqual(content_type, "application/json")
        self.assertIn('"param2": ["value2", "value3"]', body)
        self.assertIn('"param1": "value 1"', body)
예제 #3
0
    def test_encode_json_data_none(self):
        data = {"param1": "value 1", "param2": None}

        r = JSONRenderer()
        body, content_type = r.encode_params(data)
        self.assertEqual(content_type, "application/json")
        self.assertIn(b'"param2": null', body)
        self.assertIn(b'"param1": "value 1"', body)
예제 #4
0
    def test_encode_json_data_as_2tuple_parameter(self):
        data = [("param1", "value 1"), ("param2", "value2"), ("param2", "value3")]

        r = JSONRenderer()
        body, content_type = r.encode_params(data)
        self.assertEqual(content_type, "application/json")
        self.assertIn('"param2": ["value2", "value3"]', body)
        self.assertIn('"param1": "value 1"', body)
예제 #5
0
    def test_encode_json_data_including_array(self):
        data = {"param1": "value 1", "param2": ["value2", "value3"]}

        r = JSONRenderer()
        body, content_type = r.encode_params(data)
        self.assertEqual(content_type, "application/json")
        self.assertIn(b'"param2": ["value2", "value3"]', body)
        self.assertIn(b'"param1": "value 1"', body)
예제 #6
0
    def test_encode_json_data_unicode(self):
        data = {"param1": u"العَرَبِ", "param2": [u"válue", "value3"]}

        r = JSONRenderer()
        body, content_type = r.encode_params(data)
        self.assertEqual(content_type, "application/json")
        self.assertIn(b'"param2": ["v\\u00e1lue", "value3"]', body)
        self.assertIn(b'"param1": "\\u0627\\u0644\\u0639\\u064e\\u0631\\u064e\\u0628\\u0650"', body)
예제 #7
0
    def test_encode_json_data_as_2tuple_parameter(self):
        data = [("param1", "value 1"), ("param2", "value2"), ("param2", "value3")]

        r = JSONRenderer()
        body, content_type = r.encode_params(data)
        self.assertEqual(content_type, "application/json")
        self.assertIn(b'"param2": ["value2", "value3"]', body)
        self.assertIn(b'"param1": "value 1"', body)
예제 #8
0
    def test_encode_json_data_unicode(self):
        data = {"param1": u"العَرَبِ", "param2": [u"válue", "value3"]}

        r = JSONRenderer()
        body, content_type = r.encode_params(data)
        self.assertEqual(content_type, "application/json")
        self.assertIn('"param2": ["v\\u00e1lue", "value3"]', body)
        self.assertIn('"param1": "\\u0627\\u0644\\u0639\\u064e\\u0631\\u064e\\u0628\\u0650"', body)
예제 #9
0
    def test_encode_json_data_files(self):
        files = {"file_upload": "resources/file.pdf", "file_upload2": "resources/file.png"}
        data = {"param1": "value1", "param2": "value2"}

        r = JSONRenderer()
        body, content_type = r.encode_params(data, files=files)
        self.assertEqual(content_type, "application/json")
        self.assertIn(b'"param2": "value2"', body)
        self.assertIn(b'"param1": "value1"', body)
        self.assertNotIn(b"file_upload", body)
예제 #10
0
    def test_encode_json_data_files(self):
        files = {"file_upload": "resources/file.pdf", "file_upload2": "resources/file.png"}
        data = {"param1": "value1", "param2": "value2"}

        r = JSONRenderer()
        body, content_type = r.encode_params(data, files=files)
        self.assertEqual(content_type, "application/json")
        self.assertIn('"param2": "value2"', body)
        self.assertIn('"param1": "value1"', body)
        self.assertNotIn("file_upload", body)
예제 #11
0
    def test_encode_json_data_array_of_dictionaries(self):
        data = [
            {"param1": "value 1", "param2": "value 2", "param3": "value 3"},
            {"param1": "value 1"}
        ]

        r = JSONRenderer()
        body, content_type = r.encode_params(data)
        self.assertEqual(content_type, "application/json")
        self.assertIn(b'[{"', body)
        self.assertIn(b'"param1": "value 1"', body)
        self.assertIn(b'"param2": "value 2"', body)
        self.assertIn(b'"param3": "value 3"', body)
        self.assertIn(b', {"param1": "value 1"}]', body)
예제 #12
0
 def test_11paths_authentication_with_json_body(self):
     context = HttpRequestContext(
         method="POST",
         url_path="/path/",
         headers={"Content-Type": "application/json"},
         body_params={"param": "value"},
         renderer=JSONRenderer())
     header_value = x_11paths_authorization(app_id="123456",
                                            secret="654321",
                                            context=context,
                                            utc="2016-01-01 00:00:00")
     self.assertEqual("11PATHS 123456 VXVXfFsBVfCIwheS/27C8DqqpfQ=",
                      header_value)
예제 #13
0
 def test_11paths_authentication_post_empty_body_params(self):
     auth = X11PathsAuthentication(
         app_id="2kNhWLEETQ46KWLnAg48",
         secret="lBc4BSeqCGkidJZXictc3yiHbKBS87hjE05YrswJ",
         utc="2017-01-27 08:27:44")
     context = HttpRequestContext(method="POST",
                                  url_path="/ExternalApi/CleanFile",
                                  renderer=JSONRenderer())
     res_context = auth.apply_authentication(context=context)
     self.assertEqual(
         "11PATHS 2kNhWLEETQ46KWLnAg48 atYkLRYJ3b+CXU+GdklyALAr9NE=",
         res_context.headers["Authorization"])
     self.assertNotIn(X_11PATHS_BODY_HASH_HEADER_NAME, res_context.headers)
     self.assertEqual("application/x-www-form-urlencoded",
                      res_context.headers["Content-Type"])
예제 #14
0
 def test_11paths_authentication_class_json_ignorecase_header_name(self):
     auth = X11PathsAuthentication(app_id="123456",
                                   secret="654321",
                                   utc="2016-01-01 00:00:00")
     context = HttpRequestContext(
         method="POST",
         url_path="/path/",
         headers={"Content-type": "application/json"},
         body_params={"param": "value"},
         renderer=JSONRenderer())
     res_context = auth.apply_authentication(context=context)
     self.assertEqual("11PATHS 123456 6CFsVmrRxEz3Icz6U8SSHZ4RukE=",
                      res_context.headers[AUTHORIZATION_HEADER_NAME])
     self.assertEqual("f247c7579b452d08f38eec23c2d1a4a23daee0d2",
                      res_context.headers[X_11PATHS_BODY_HASH_HEADER_NAME])
예제 #15
0
def send_http_request_with_json(context, method):
    """
    Parameters:

        .. code-block:: json

            {
                "param1": "value1",
                "param2": "value2",
                "param3": {
                    "param31": "value31"
                }
            }
    """
    safe_add_http_request_context_to_behave_context(context)
    context.http_request_context.body_params = json.loads(context.text)
    context.http_request_context.renderer = JSONRenderer()
    send_http_request(context, method)
예제 #16
0
 def test_encode_json_no_data(self):
     r = JSONRenderer()
     body, content_type = r.encode_params()
     self.assertEqual(content_type, "application/json")
     self.assertEqual(b"", body)
예제 #17
0
 def test_encode_json_no_data(self):
     r = JSONRenderer()
     body, content_type = r.encode_params()
     self.assertEqual(content_type, "application/json")
     self.assertEqual("", body)