Example #1
0
    def test_body_kwargs_bad_content_type(self):
        """make sure a form upload content type with json body fails correctly"""
        r = Request()
        r.body = "foo=bar&che=baz&foo=che"
        r.headers = {'content-type': 'application/json'}
        with self.assertRaises(ValueError):
            br = r.body_kwargs

        r.body = '{"foo": ["bar", "che"], "che": "baz"}'
        r.headers = {'content-type': "application/x-www-form-urlencoded"}

        with self.assertRaises(ValueError):
            br = r.body_kwargs
Example #2
0
    def test_body_kwargs_bad_content_type(self):
        """make sure a form upload content type with json body fails correctly"""
        r = Request()
        r.body = "foo=bar&che=baz&foo=che"
        r.headers = {'content-type': 'application/json'}
        with self.assertRaises(ValueError):
            br = r.body_kwargs

        r.body = '{"foo": ["bar", "che"], "che": "baz"}'
        r.headers = {'content-type': "application/x-www-form-urlencoded"}

        with self.assertRaises(ValueError):
            br = r.body_kwargs
Example #3
0
    def test_body(self):
        # simulate a problem I had with a request with curl
        r = Request()
        r.method = 'GET'
        r.body = ""
        r.set_headers({
            'PATTERN': "/",
            'x-forwarded-for': "127.0.0.1",
            'URI': "/",
            'accept': "*/*",
            'user-agent': "curl/7.24.0 (x86_64-apple-darwin12.0) libcurl/7.24.0 OpenSSL/0.9.8y zlib/1.2.5",
            'host': "localhost",
            'VERSION': "HTTP/1.1",
            'PATH': "/",
            'METHOD': "GET",
            'authorization': "Basic SOME_HASH_THAT_DOES_NOT_MATTER="
        })
        self.assertEqual("", r.body)

        r = Request()
        r.method = 'POST'

        r.set_header('content-type', "application/x-www-form-urlencoded")
        r.body = "foo=bar&che=baz&foo=che"
        body_r = {'foo': ['bar', 'che'], 'che': 'baz'}
        self.assertEqual(body_r, r.body_kwargs)


        r.body = None
        #del(r._body_kwargs)
        body_r = {}
        self.assertEqual(body_r, r.body_kwargs)

        r.set_header('content-type', "application/json")
        r.body = '{"person":{"name":"bob"}}'
        #del(r._body_kwargs)
        body_r = {'person': {"name":"bob"}}
        self.assertEqual(body_r, r.body_kwargs)

        r.body = ''
        #del(r._body_kwargs)
        body_r = ''
        self.assertEqual(body_r, r.body)

        r.headers = {}
        body = '{"person":{"name":"bob"}}'
        r.body = body
        self.assertEqual(body, r.body)

        r.method = 'GET'
        r.set_header('content-type', "application/json")
        r.body = None
        self.assertEqual(None, r.body)
Example #4
0
    def test_body(self):
        # simulate a problem I had with a request with curl
        r = Request()
        r.method = 'GET'
        r.body = ""
        r.set_headers({
            'PATTERN': "/",
            'x-forwarded-for': "127.0.0.1",
            'URI': "/",
            'accept': "*/*",
            'user-agent':
            "curl/7.24.0 (x86_64-apple-darwin12.0) libcurl/7.24.0 OpenSSL/0.9.8y zlib/1.2.5",
            'host': "localhost",
            'VERSION': "HTTP/1.1",
            'PATH': "/",
            'METHOD': "GET",
            'authorization': "Basic SOME_HASH_THAT_DOES_NOT_MATTER="
        })
        self.assertEqual("", r.body)

        r = Request()
        r.method = 'POST'

        r.set_header('content-type', "application/x-www-form-urlencoded")
        r.body = "foo=bar&che=baz&foo=che"
        body_r = {'foo': ['bar', 'che'], 'che': 'baz'}
        self.assertEqual(body_r, r.body_kwargs)

        r.body = None
        #del(r._body_kwargs)
        body_r = {}
        self.assertEqual(body_r, r.body_kwargs)

        r.set_header('content-type', "application/json")
        r.body = '{"person":{"name":"bob"}}'
        #del(r._body_kwargs)
        body_r = {'person': {"name": "bob"}}
        self.assertEqual(body_r, r.body_kwargs)

        r.body = ''
        #del(r._body_kwargs)
        body_r = ''
        self.assertEqual(body_r, r.body)

        r.headers = {}
        body = '{"person":{"name":"bob"}}'
        r.body = body
        self.assertEqual(body, r.body)

        r.method = 'GET'
        r.set_header('content-type', "application/json")
        r.body = None
        self.assertEqual(None, r.body)
    def test_get_version_default(self):
        """turns out, calls were failing if there was no accept header even if there were defaults set"""
        r = Request()
        r.headers = {}
        self.assertEqual("", r.version('application/json'))

        r = Request()
        r.set_header('accept', 'application/json;version=v1')
        self.assertEqual('v1', r.version())

        r = Request()
        r.set_header('accept', '*/*')
        self.assertEqual("", r.version('application/json'))

        r = Request()
        r.set_header('accept', '*/*;version=v8')
        self.assertEqual('v8', r.version('application/json'))
Example #6
0
    def test_get_version_default(self):
        """turns out, calls were failing if there was no accept header even if there were defaults set"""
        r = Request()
        r.headers = {}
        self.assertEqual("", r.version('application/json'))

        r = Request()
        r.set_header('accept', 'application/json;version=v1')
        self.assertEqual('v1', r.version())

        r = Request()
        r.set_header('accept', '*/*')
        self.assertEqual("", r.version('application/json'))

        r = Request()
        r.set_header('accept', '*/*;version=v8')
        self.assertEqual('v8', r.version('application/json'))