Beispiel #1
0
 def test_bad_request_no_content_length(self):
     resource = TestResource()
     environ = {'QUERY_STRING': '', 'REQUEST_METHOD': 'PUT',
                'wsgi.input': StringIO.StringIO('a'),
                'CONTENT_TYPE': 'application/json'}
     invoke = http_app.HTTPInvocationByMethodWithBody(resource, environ,
                                                      parameters)
     self.assertRaises(http_app.BadRequest, invoke)
Beispiel #2
0
 def test_get(self):
     resource = TestResource()
     environ = {'QUERY_STRING': 'a=1&b=2', 'REQUEST_METHOD': 'GET'}
     invoke = http_app.HTTPInvocationByMethodWithBody(
         resource, environ, parameters)
     res = invoke()
     self.assertEqual('Get', res)
     self.assertEqual({'a': '1', 'b': '2'}, resource.args)
Beispiel #3
0
 def test_bad_request_unsupported_method_put_like(self):
     resource = TestResource()
     environ = {'QUERY_STRING': '', 'REQUEST_METHOD': 'PUT',
                'wsgi.input': StringIO.StringIO('{}'),
                'CONTENT_LENGTH': '2',
                'CONTENT_TYPE': 'application/json'}
     invoke = http_app.HTTPInvocationByMethodWithBody(resource, environ,
                                                      parameters)
     self.assertRaises(http_app.BadRequest, invoke)
Beispiel #4
0
 def _put_sync_stream(self, body):
     resource = TestResource()
     environ = {'QUERY_STRING': 'a=1&b=2', 'REQUEST_METHOD': 'PUT',
                'wsgi.input': StringIO.StringIO(body),
                'CONTENT_LENGTH': str(len(body)),
                'CONTENT_TYPE': 'application/x-u1db-sync-stream'}
     invoke = http_app.HTTPInvocationByMethodWithBody(resource, environ,
                                                      parameters)
     invoke()
Beispiel #5
0
 def test_bad_request_unsupported_method_put_like_multi_json(self):
     resource = TestResource()
     body = '{}\r\n{}\r\n'
     environ = {'QUERY_STRING': '', 'REQUEST_METHOD': 'POST',
                'wsgi.input': StringIO.StringIO(body),
                'CONTENT_LENGTH': str(len(body)),
                'CONTENT_TYPE': 'application/x-u1db-multi-json'}
     invoke = http_app.HTTPInvocationByMethodWithBody(resource, environ,
                                                      parameters)
     self.assertRaises(http_app.BadRequest, invoke)
Beispiel #6
0
    def test_bad_request_content_length_too_large(self):
        resource = TestResource()
        environ = {'QUERY_STRING': '', 'REQUEST_METHOD': 'PUT',
                   'wsgi.input': StringIO.StringIO('{}'),
                   'CONTENT_LENGTH': '10000',
                   'CONTENT_TYPE': 'text/plain'}

        resource.max_request_size = 5000
        resource.max_entry_size = sys.maxint  # we don't get to use this

        invoke = http_app.HTTPInvocationByMethodWithBody(resource, environ,
                                                         parameters)
        self.assertRaises(http_app.BadRequest, invoke)
Beispiel #7
0
 def test_put_json(self):
     resource = TestResource()
     body = '{"body": true}'
     environ = {'QUERY_STRING': 'a=1', 'REQUEST_METHOD': 'PUT',
                'wsgi.input': StringIO.StringIO(body),
                'CONTENT_LENGTH': str(len(body)),
                'CONTENT_TYPE': 'application/json'}
     invoke = http_app.HTTPInvocationByMethodWithBody(resource, environ,
                                                      parameters)
     res = invoke()
     self.assertEqual('Put', res)
     self.assertEqual({'a': '1'}, resource.args)
     self.assertEqual('{"body": true}', resource.content)
Beispiel #8
0
 def test_put_json_charset_accepted_ignored(self):
     resource = TestResource()
     body = '{"body": true}'
     environ = {
         'QUERY_STRING': 'a=1',
         'REQUEST_METHOD': 'PUT',
         'wsgi.input': StringIO.StringIO(body),
         'CONTENT_LENGTH': str(len(body)),
         'CONTENT_TYPE': 'application/json ; charset="utf-8"'
     }
     invoke = http_app.HTTPInvocationByMethodWithBody(
         resource, environ, parameters)
     invoke()
     self.assertEqual('{"body": true}', resource.content)
Beispiel #9
0
 def test_put_sync_stream(self):
     resource = TestResource()
     body = (
         '[\r\n'
         '{"b": 2},\r\n'        # args
         '{"entry": "x"},\r\n'  # stream entry
         '{"entry": "y"}\r\n'   # stream entry
         ']'
     )
     environ = {'QUERY_STRING': 'a=1', 'REQUEST_METHOD': 'PUT',
                'wsgi.input': StringIO.StringIO(body),
                'CONTENT_LENGTH': str(len(body)),
                'CONTENT_TYPE': 'application/x-u1db-sync-stream'}
     invoke = http_app.HTTPInvocationByMethodWithBody(resource, environ,
                                                      parameters)
     res = invoke()
     self.assertEqual('Put/end', res)
     self.assertEqual({'a': '1', 'b': 2}, resource.args)
     self.assertEqual(
         ['{"entry": "x"}', '{"entry": "y"}'], resource.entries)
     self.assertEqual(['a', 's', 's', 'e'], resource.order)
Beispiel #10
0
 def test_bad_request_unsupported_method_get_like(self):
     resource = TestResource()
     environ = {'QUERY_STRING': '', 'REQUEST_METHOD': 'DELETE'}
     invoke = http_app.HTTPInvocationByMethodWithBody(
         resource, environ, parameters)
     self.assertRaises(http_app.BadRequest, invoke)