예제 #1
0
    def test_raw_post_data_partial_read(self):
        if django.VERSION[:2] < (1, 3):
            return
        v = '{"foo": "bar"}'
        request = WSGIRequest(
            environ={
                "wsgi.input": StringIO(v + "\r\n\r\n"),
                "REQUEST_METHOD": "POST",
                "SERVER_NAME": "testserver",
                "SERVER_PORT": "80",
                "CONTENT_TYPE": "application/octet-stream",
                "CONTENT_LENGTH": len(v),
                "ACCEPT": "application/json",
            }
        )
        request.read(1)

        self.raven.capture("Message", message="foo", request=request)

        self.assertEquals(len(self.raven.events), 1)
        event = self.raven.events.pop(0)

        self.assertTrue("sentry.interfaces.Http" in event)
        http = event["sentry.interfaces.Http"]
        self.assertEquals(http["method"], "POST")
        self.assertEquals(http["data"], "<unavailable>")
예제 #2
0
파일: tests.py 프로젝트: mfrasca/raven
    def test_request_capture(self):
        if django.VERSION[:2] < (1, 3):
            return
        request = WSGIRequest(
            environ={
                'wsgi.input': StringIO(),
                'REQUEST_METHOD': 'POST',
                'SERVER_NAME': 'testserver',
                'SERVER_PORT': '80',
                'CONTENT_TYPE': 'text/html',
                'ACCEPT': 'text/html',
            })
        request.read(1)

        self.raven.capture('Message', message='foo', request=request)

        self.assertEquals(len(self.raven.events), 1)
        event = self.raven.events.pop(0)

        self.assertTrue('sentry.interfaces.Http' in event)
        http = event['sentry.interfaces.Http']
        self.assertEquals(http['method'], 'POST')
        self.assertEquals(http['data'], '<unavailable>')
        self.assertTrue('headers' in http)
        headers = http['headers']
        self.assertTrue('Content-Type' in headers, headers.keys())
        self.assertEquals(headers['Content-Type'], 'text/html')
        env = http['env']
        self.assertTrue('SERVER_NAME' in env, env.keys())
        self.assertEquals(env['SERVER_NAME'], 'testserver')
        self.assertTrue('SERVER_PORT' in env, env.keys())
        self.assertEquals(env['SERVER_PORT'], '80')
예제 #3
0
    def test_request_capture(self):
        request = WSGIRequest(
            environ={
                'wsgi.input': StringIO(),
                'REQUEST_METHOD': 'POST',
                'SERVER_NAME': 'testserver',
                'SERVER_PORT': '80',
                'CONTENT_TYPE': 'text/html',
                'ACCEPT': 'text/html',
            })
        request.read(1)

        self.raven.capture('Message', message='foo', request=request)

        self.assertEquals(len(self.raven.events), 1)
        event = self.raven.events.pop(0)

        self.assertTrue('sentry.interfaces.Http' in event)
        http = event['sentry.interfaces.Http']
        self.assertEquals(http['method'], 'POST')
        self.assertEquals(http['data'], '<unavailable>')
        self.assertTrue('headers' in http)
        headers = http['headers']
        self.assertTrue('Content-Type' in headers, headers.keys())
        self.assertEquals(headers['Content-Type'], 'text/html')
        env = http['env']
        self.assertTrue('SERVER_NAME' in env, env.keys())
        self.assertEquals(env['SERVER_NAME'], 'testserver')
        self.assertTrue('SERVER_PORT' in env, env.keys())
        self.assertEquals(env['SERVER_PORT'], '80')
예제 #4
0
    def test_request_capture(self):
        if django.VERSION[:2] < (1, 3):
            return
        request = WSGIRequest(
            environ={
                "wsgi.input": StringIO(),
                "REQUEST_METHOD": "POST",
                "SERVER_NAME": "testserver",
                "SERVER_PORT": "80",
                "CONTENT_TYPE": "text/html",
                "ACCEPT": "text/html",
            }
        )
        request.read(1)

        self.raven.capture("Message", message="foo", request=request)

        self.assertEquals(len(self.raven.events), 1)
        event = self.raven.events.pop(0)

        self.assertTrue("sentry.interfaces.Http" in event)
        http = event["sentry.interfaces.Http"]
        self.assertEquals(http["method"], "POST")
        self.assertEquals(http["data"], "<unavailable>")
        self.assertTrue("headers" in http)
        headers = http["headers"]
        self.assertTrue("Content-Type" in headers, headers.keys())
        self.assertEquals(headers["Content-Type"], "text/html")
        env = http["env"]
        self.assertTrue("SERVER_NAME" in env, env.keys())
        self.assertEquals(env["SERVER_NAME"], "testserver")
        self.assertTrue("SERVER_PORT" in env, env.keys())
        self.assertEquals(env["SERVER_PORT"], "80")
예제 #5
0
파일: tests.py 프로젝트: mfrasca/raven
    def test_raw_post_data_partial_read(self):
        if django.VERSION[:2] < (1, 3):
            return
        v = '{"foo": "bar"}'
        request = WSGIRequest(
            environ={
                'wsgi.input': StringIO(v + '\r\n\r\n'),
                'REQUEST_METHOD': 'POST',
                'SERVER_NAME': 'testserver',
                'SERVER_PORT': '80',
                'CONTENT_TYPE': 'application/octet-stream',
                'CONTENT_LENGTH': len(v),
                'ACCEPT': 'application/json',
            })
        request.read(1)

        self.raven.capture('Message', message='foo', request=request)

        self.assertEquals(len(self.raven.events), 1)
        event = self.raven.events.pop(0)

        self.assertTrue('sentry.interfaces.Http' in event)
        http = event['sentry.interfaces.Http']
        self.assertEquals(http['method'], 'POST')
        self.assertEquals(http['data'], '<unavailable>')
예제 #6
0
def test_request_capture(django_elasticapm_client):
    request = WSGIRequest(environ={
        'wsgi.input': compat.BytesIO(),
        'REQUEST_METHOD': 'POST',
        'SERVER_NAME': 'testserver',
        'SERVER_PORT': '80',
        'CONTENT_TYPE': 'text/html',
        'ACCEPT': 'text/html',
    })
    request.read(1)

    django_elasticapm_client.capture('Message', message='foo', request=request)

    assert len(django_elasticapm_client.events) == 1
    event = django_elasticapm_client.events.pop(0)['errors'][0]

    assert 'request' in event['context']
    request = event['context']['request']
    assert request['method'] == 'POST'
    assert request['body'] == '<unavailable>'
    assert 'headers' in request
    headers = request['headers']
    assert 'content-type' in headers, headers.keys()
    assert headers['content-type'] == 'text/html'
    env = request['env']
    assert 'SERVER_NAME' in env, env.keys()
    assert env['SERVER_NAME'] == 'testserver'
    assert 'SERVER_PORT' in env, env.keys()
    assert env['SERVER_PORT'] == '80'
예제 #7
0
    def test_raw_post_data_partial_read(self):
        if django.VERSION[:2] < (1, 3):
            return
        v = '{"foo": "bar"}'
        request = WSGIRequest(
            environ={
                'wsgi.input': StringIO(v + '\r\n\r\n'),
                'REQUEST_METHOD': 'POST',
                'SERVER_NAME': 'testserver',
                'SERVER_PORT': '80',
                'CONTENT_TYPE': 'application/octet-stream',
                'CONTENT_LENGTH': len(v),
                'ACCEPT': 'application/json',
            })
        request.read(1)

        self.raven.capture('Message', message='foo', request=request)

        self.assertEquals(len(self.raven.events), 1)
        event = self.raven.events.pop(0)

        self.assertTrue('sentry.interfaces.Http' in event)
        http = event['sentry.interfaces.Http']
        self.assertEquals(http['method'], 'POST')
        self.assertEquals(http['data'], '<unavailable>')
예제 #8
0
 def test_stream(self):
     payload = FakePayload('name=value')
     request = WSGIRequest({'REQUEST_METHOD': 'POST',
                            'CONTENT_TYPE': 'application/x-www-form-urlencoded',
                            'CONTENT_LENGTH': len(payload),
                            'wsgi.input': payload})
     self.assertEqual(request.read(), b'name=value')
예제 #9
0
파일: tests.py 프로젝트: 10sr/hue
 def test_stream(self):
     payload = FakePayload('name=value')
     request = WSGIRequest({'REQUEST_METHOD': 'POST',
                            'CONTENT_TYPE': 'application/x-www-form-urlencoded',
                            'CONTENT_LENGTH': len(payload),
                            'wsgi.input': payload})
     self.assertEqual(request.read(), b'name=value')
예제 #10
0
 def test_stream(self):
     payload = 'name=value'
     request = WSGIRequest({
         'REQUEST_METHOD': 'POST',
         'CONTENT_LENGTH': len(payload),
         'wsgi.input': StringIO(payload)
     })
     self.assertEqual(request.read(), 'name=value')
예제 #11
0
 def test_POST_after_raw_post_data_read_and_stream_read(self):
     """
     POST should be populated even if raw_post_data is read first, and then
     the stream is read second.
     """
     request = WSGIRequest({'REQUEST_METHOD': 'POST', 'wsgi.input': StringIO('name=value')})
     raw_data = request.raw_post_data
     self.assertEqual(request.read(1), u'n')
     self.assertEqual(request.POST, {u'name': [u'value']})
예제 #12
0
 def test_read_after_value(self):
     """
     Reading from request is allowed after accessing request contents as
     POST or raw_post_data.
     """
     request = WSGIRequest({'REQUEST_METHOD': 'POST', 'wsgi.input': StringIO('name=value')})
     self.assertEqual(request.POST, {u'name': [u'value']})
     self.assertEqual(request.raw_post_data, 'name=value')
     self.assertEqual(request.read(), 'name=value')
예제 #13
0
 def test_value_after_read(self):
     """
     Construction of POST or raw_post_data is not allowed after reading
     from request.
     """
     request = WSGIRequest({'REQUEST_METHOD': 'POST', 'wsgi.input': StringIO('name=value')})
     self.assertEqual(request.read(2), 'na')
     self.assertRaises(Exception, lambda: request.raw_post_data)
     self.assertEqual(request.POST, {})
예제 #14
0
파일: tests.py 프로젝트: Anoopsmohan/django
 def test_value_after_read(self):
     """
     Construction of POST or raw_post_data is not allowed after reading
     from request.
     """
     request = WSGIRequest({'REQUEST_METHOD': 'POST', 'wsgi.input': StringIO('name=value')})
     self.assertEqual(request.read(2), 'na')
     self.assertRaises(Exception, lambda: request.raw_post_data)
     self.assertEqual(request.POST, {})
예제 #15
0
파일: tests.py 프로젝트: B-Rich/django
 def test_POST_after_raw_post_data_read_and_stream_read(self):
     """
     POST should be populated even if raw_post_data is read first, and then
     the stream is read second.
     """
     request = WSGIRequest({'REQUEST_METHOD': 'POST', 'wsgi.input': StringIO('name=value')})
     raw_data = request.raw_post_data
     self.assertEqual(request.read(1), u'n')
     self.assertEqual(request.POST, {u'name': [u'value']})
예제 #16
0
파일: tests.py 프로젝트: Anoopsmohan/django
 def test_read_after_value(self):
     """
     Reading from request is allowed after accessing request contents as
     POST or raw_post_data.
     """
     request = WSGIRequest({'REQUEST_METHOD': 'POST', 'wsgi.input': StringIO('name=value')})
     self.assertEqual(request.POST, {u'name': [u'value']})
     self.assertEqual(request.raw_post_data, 'name=value')
     self.assertEqual(request.read(), 'name=value')
예제 #17
0
 def test_stream(self):
     payload = FakePayload("name=value")
     request = WSGIRequest(
         {
             "REQUEST_METHOD": "POST",
             "CONTENT_TYPE": "application/x-www-form-urlencoded",
             "CONTENT_LENGTH": len(payload),
             "wsgi.input": payload,
         }, )
     self.assertEqual(request.read(), b"name=value")
예제 #18
0
파일: tests.py 프로젝트: hellhovnd/django
 def test_stream(self):
     payload = FakePayload("name=value")
     request = WSGIRequest(
         {
             "REQUEST_METHOD": "POST",
             "CONTENT_TYPE": "application/x-www-form-urlencoded",
             "CONTENT_LENGTH": len(payload),
             "wsgi.input": payload,
         }
     )
     self.assertEqual(request.read(), b"name=value")
예제 #19
0
    def test_raw_post_data_partial_read(self):
        # This test only applies to Django 1.3+
        v = '{"foo": "bar"}'
        request = WSGIRequest(environ={
            'wsgi.input': StringIO(v + '\r\n\r\n'),
            'REQUEST_METHOD': 'POST',
            'SERVER_NAME': 'testserver',
            'SERVER_PORT': '80',
            'CONTENT_TYPE': 'application/octet-stream',
            'CONTENT_LENGTH': len(v),
            'ACCEPT': 'application/json',
        })
        request.read(1)

        self.raven.process(request=request)

        self.assertEquals(len(self.raven.events), 1)
        event = self.raven.events.pop(0)

        self.assertEquals(event['data']['POST'], '<unavailable>')
예제 #20
0
파일: tests.py 프로젝트: Aliced3645/django
 def test_value_after_read(self):
     """
     Construction of POST or body is not allowed after reading
     from request.
     """
     payload = b'name=value'
     request = WSGIRequest({'REQUEST_METHOD': 'POST',
                            'CONTENT_LENGTH': len(payload),
                            'wsgi.input': BytesIO(payload)})
     self.assertEqual(request.read(2), b'na')
     self.assertRaises(Exception, lambda: request.body)
     self.assertEqual(request.POST, {})
예제 #21
0
 def test_value_after_read(self):
     """
     Construction of POST or body is not allowed after reading
     from request.
     """
     payload = 'name=value'
     request = WSGIRequest({'REQUEST_METHOD': 'POST',
                            'CONTENT_LENGTH': len(payload),
                            'wsgi.input': StringIO(payload)})
     self.assertEqual(request.read(2), 'na')
     self.assertRaises(Exception, lambda: request.body)
     self.assertEqual(request.POST, {})
예제 #22
0
 def test_POST_after_body_read_and_stream_read(self):
     """
     POST should be populated even if body is read first, and then
     the stream is read second.
     """
     payload = 'name=value'
     request = WSGIRequest({'REQUEST_METHOD': 'POST',
                            'CONTENT_LENGTH': len(payload),
                            'wsgi.input': StringIO(payload)})
     raw_data = request.body
     self.assertEqual(request.read(1), u'n')
     self.assertEqual(request.POST, {u'name': [u'value']})
예제 #23
0
 def test_read_after_value(self):
     """
     Reading from request is allowed after accessing request contents as
     POST or body.
     """
     payload = 'name=value'
     request = WSGIRequest({'REQUEST_METHOD': 'POST',
                            'CONTENT_LENGTH': len(payload),
                            'wsgi.input': StringIO(payload)})
     self.assertEqual(request.POST, {u'name': [u'value']})
     self.assertEqual(request.body, 'name=value')
     self.assertEqual(request.read(), 'name=value')
예제 #24
0
파일: tests.py 프로젝트: Aliced3645/django
 def test_POST_after_body_read_and_stream_read(self):
     """
     POST should be populated even if body is read first, and then
     the stream is read second.
     """
     payload = b'name=value'
     request = WSGIRequest({'REQUEST_METHOD': 'POST',
                            'CONTENT_LENGTH': len(payload),
                            'wsgi.input': BytesIO(payload)})
     raw_data = request.body
     self.assertEqual(request.read(1), b'n')
     self.assertEqual(request.POST, {'name': ['value']})
예제 #25
0
파일: tests.py 프로젝트: Aliced3645/django
 def test_read_after_value(self):
     """
     Reading from request is allowed after accessing request contents as
     POST or body.
     """
     payload = b'name=value'
     request = WSGIRequest({'REQUEST_METHOD': 'POST',
                            'CONTENT_LENGTH': len(payload),
                            'wsgi.input': BytesIO(payload)})
     self.assertEqual(request.POST, {'name': ['value']})
     self.assertEqual(request.body, b'name=value')
     self.assertEqual(request.read(), b'name=value')
예제 #26
0
파일: tests.py 프로젝트: 10sr/hue
 def test_value_after_read(self):
     """
     Construction of POST or body is not allowed after reading
     from request.
     """
     payload = FakePayload('name=value')
     request = WSGIRequest({'REQUEST_METHOD': 'POST',
                            'CONTENT_TYPE': 'application/x-www-form-urlencoded',
                            'CONTENT_LENGTH': len(payload),
                            'wsgi.input': payload})
     self.assertEqual(request.read(2), b'na')
     self.assertRaises(Exception, lambda: request.body)
     self.assertEqual(request.POST, {})
예제 #27
0
파일: tests.py 프로젝트: 10sr/hue
 def test_POST_after_body_read_and_stream_read(self):
     """
     POST should be populated even if body is read first, and then
     the stream is read second.
     """
     payload = FakePayload('name=value')
     request = WSGIRequest({'REQUEST_METHOD': 'POST',
                            'CONTENT_TYPE': 'application/x-www-form-urlencoded',
                            'CONTENT_LENGTH': len(payload),
                            'wsgi.input': payload})
     raw_data = request.body
     self.assertEqual(request.read(1), b'n')
     self.assertEqual(request.POST, {'name': ['value']})
예제 #28
0
파일: tests.py 프로젝트: 10sr/hue
 def test_read_after_value(self):
     """
     Reading from request is allowed after accessing request contents as
     POST or body.
     """
     payload = FakePayload('name=value')
     request = WSGIRequest({'REQUEST_METHOD': 'POST',
                            'CONTENT_TYPE': 'application/x-www-form-urlencoded',
                            'CONTENT_LENGTH': len(payload),
                            'wsgi.input': payload})
     self.assertEqual(request.POST, {'name': ['value']})
     self.assertEqual(request.body, b'name=value')
     self.assertEqual(request.read(), b'name=value')
예제 #29
0
 def test_POST_after_body_read_and_stream_read(self):
     """
     POST should be populated even if body is read first, and then
     the stream is read second.
     """
     payload = FakePayload('name=value')
     request = WSGIRequest({'REQUEST_METHOD': 'POST',
                            'CONTENT_TYPE': 'application/x-www-form-urlencoded',
                            'CONTENT_LENGTH': len(payload),
                            'wsgi.input': payload})
     request.body  # evaluate
     self.assertEqual(request.read(1), b'n')
     self.assertEqual(request.POST, {'name': ['value']})
예제 #30
0
 def test_read_after_value(self):
     """
     Reading from request is allowed after accessing request contents as
     POST or body.
     """
     payload = FakePayload('name=value')
     request = WSGIRequest({'REQUEST_METHOD': 'POST',
                            'CONTENT_TYPE': 'application/x-www-form-urlencoded',
                            'CONTENT_LENGTH': len(payload),
                            'wsgi.input': payload})
     self.assertEqual(request.POST, {'name': ['value']})
     self.assertEqual(request.body, b'name=value')
     self.assertEqual(request.read(), b'name=value')
예제 #31
0
 def test_value_after_read(self):
     """
     Construction of POST or body is not allowed after reading
     from request.
     """
     payload = FakePayload('name=value')
     request = WSGIRequest({'REQUEST_METHOD': 'POST',
                            'CONTENT_TYPE': 'application/x-www-form-urlencoded',
                            'CONTENT_LENGTH': len(payload),
                            'wsgi.input': payload})
     self.assertEqual(request.read(2), b'na')
     self.assertRaises(RawPostDataException, lambda: request.body)
     self.assertEqual(request.POST, {})
예제 #32
0
def test_raw_post_data_partial_read(django_elasticapm_client):
    v = compat.b('{"foo": "bar"}')
    request = WSGIRequest(environ={
        'wsgi.input': compat.BytesIO(v + compat.b('\r\n\r\n')),
        'REQUEST_METHOD': 'POST',
        'SERVER_NAME': 'testserver',
        'SERVER_PORT': '80',
        'CONTENT_TYPE': 'application/json',
        'CONTENT_LENGTH': len(v),
        'ACCEPT': 'application/json',
    })
    request.read(1)

    django_elasticapm_client.capture('Message', message='foo', request=request)

    assert len(django_elasticapm_client.events) == 1
    event = django_elasticapm_client.events.pop(0)['errors'][0]

    assert 'request' in event['context']
    request = event['context']['request']
    assert request['method'] == 'POST'
    assert request['body'] == '<unavailable>'
예제 #33
0
 def test_POST_after_body_read_and_stream_read(self):
     """
     POST should be populated even if body is read first, and then
     the stream is read second.
     """
     payload = FakePayload("name=value")
     request = WSGIRequest({
         "REQUEST_METHOD": "POST",
         "CONTENT_TYPE": "application/x-www-form-urlencoded",
         "CONTENT_LENGTH": len(payload),
         "wsgi.input": payload,
     })
     request.body  # evaluate
     self.assertEqual(request.read(1), b"n")
     self.assertEqual(request.POST, {"name": ["value"]})
예제 #34
0
 def test_read_after_value(self):
     """
     Reading from request is allowed after accessing request contents as
     POST or body.
     """
     payload = FakePayload("name=value")
     request = WSGIRequest({
         "REQUEST_METHOD": "POST",
         "CONTENT_TYPE": "application/x-www-form-urlencoded",
         "CONTENT_LENGTH": len(payload),
         "wsgi.input": payload,
     })
     self.assertEqual(request.POST, {"name": ["value"]})
     self.assertEqual(request.body, b"name=value")
     self.assertEqual(request.read(), b"name=value")
예제 #35
0
 def test_value_after_read(self):
     """
     Construction of POST or body is not allowed after reading
     from request.
     """
     payload = FakePayload("name=value")
     request = WSGIRequest({
         "REQUEST_METHOD": "POST",
         "CONTENT_TYPE": "application/x-www-form-urlencoded",
         "CONTENT_LENGTH": len(payload),
         "wsgi.input": payload,
     })
     self.assertEqual(request.read(2), b"na")
     with self.assertRaises(RawPostDataException):
         request.body
     self.assertEqual(request.POST, {})
예제 #36
0
파일: tests.py 프로젝트: hellhovnd/django
 def test_read_after_value(self):
     """
     Reading from request is allowed after accessing request contents as
     POST or body.
     """
     payload = FakePayload("name=value")
     request = WSGIRequest(
         {
             "REQUEST_METHOD": "POST",
             "CONTENT_TYPE": "application/x-www-form-urlencoded",
             "CONTENT_LENGTH": len(payload),
             "wsgi.input": payload,
         }
     )
     self.assertEqual(request.POST, {"name": ["value"]})
     self.assertEqual(request.body, b"name=value")
     self.assertEqual(request.read(), b"name=value")
예제 #37
0
파일: tests.py 프로젝트: hellhovnd/django
 def test_value_after_read(self):
     """
     Construction of POST or body is not allowed after reading
     from request.
     """
     payload = FakePayload("name=value")
     request = WSGIRequest(
         {
             "REQUEST_METHOD": "POST",
             "CONTENT_TYPE": "application/x-www-form-urlencoded",
             "CONTENT_LENGTH": len(payload),
             "wsgi.input": payload,
         }
     )
     self.assertEqual(request.read(2), b"na")
     self.assertRaises(Exception, lambda: request.body)
     self.assertEqual(request.POST, {})
예제 #38
0
파일: tests.py 프로젝트: hellhovnd/django
 def test_POST_after_body_read_and_stream_read(self):
     """
     POST should be populated even if body is read first, and then
     the stream is read second.
     """
     payload = FakePayload("name=value")
     request = WSGIRequest(
         {
             "REQUEST_METHOD": "POST",
             "CONTENT_TYPE": "application/x-www-form-urlencoded",
             "CONTENT_LENGTH": len(payload),
             "wsgi.input": payload,
         }
     )
     raw_data = request.body
     self.assertEqual(request.read(1), b"n")
     self.assertEqual(request.POST, {"name": ["value"]})
예제 #39
0
파일: tests.py 프로젝트: hellhovnd/django
 def test_POST_after_body_read_and_stream_read_multipart(self):
     """
     POST should be populated even if body is read first, and then
     the stream is read second. Using multipart/form-data instead of urlencoded.
     """
     payload = FakePayload(
         "\r\n".join(["--boundary", 'Content-Disposition: form-data; name="name"', "", "value", "--boundary--" ""])
     )
     request = WSGIRequest(
         {
             "REQUEST_METHOD": "POST",
             "CONTENT_TYPE": "multipart/form-data; boundary=boundary",
             "CONTENT_LENGTH": len(payload),
             "wsgi.input": payload,
         }
     )
     raw_data = request.body
     # Consume enough data to mess up the parsing:
     self.assertEqual(request.read(13), b"--boundary\r\nC")
     self.assertEqual(request.POST, {"name": ["value"]})
예제 #40
0
파일: tests.py 프로젝트: 10sr/hue
 def test_POST_after_body_read_and_stream_read_multipart(self):
     """
     POST should be populated even if body is read first, and then
     the stream is read second. Using multipart/form-data instead of urlencoded.
     """
     payload = FakePayload("\r\n".join([
             '--boundary',
             'Content-Disposition: form-data; name="name"',
             '',
             'value',
             '--boundary--'
             '']))
     request = WSGIRequest({'REQUEST_METHOD': 'POST',
                            'CONTENT_TYPE': 'multipart/form-data; boundary=boundary',
                            'CONTENT_LENGTH': len(payload),
                            'wsgi.input': payload})
     raw_data = request.body
     # Consume enough data to mess up the parsing:
     self.assertEqual(request.read(13), b'--boundary\r\nC')
     self.assertEqual(request.POST, {'name': ['value']})
예제 #41
0
 def test_POST_after_raw_post_data_read_and_stream_read_multipart(self):
     """
     POST should be populated even if raw_post_data is read first, and then
     the stream is read second. Using multipart/form-data instead of urlencoded.
     """
     payload = "\r\n".join([
         '--boundary', 'Content-Disposition: form-data; name="name"', '',
         'value', '--boundary--'
         ''
     ])
     request = WSGIRequest({
         'REQUEST_METHOD': 'POST',
         'CONTENT_TYPE': 'multipart/form-data; boundary=boundary',
         'CONTENT_LENGTH': len(payload),
         'wsgi.input': StringIO(payload)
     })
     raw_data = request.raw_post_data
     # Consume enough data to mess up the parsing:
     self.assertEqual(request.read(13), u'--boundary\r\nC')
     self.assertEqual(request.POST, {u'name': [u'value']})
예제 #42
0
 def test_POST_after_body_read_and_stream_read_multipart(self):
     """
     POST should be populated even if body is read first, and then
     the stream is read second. Using multipart/form-data instead of urlencoded.
     """
     payload = FakePayload("\r\n".join([
         "--boundary",
         'Content-Disposition: form-data; name="name"',
         "",
         "value",
         "--boundary--"
         "",
     ]))
     request = WSGIRequest({
         "REQUEST_METHOD": "POST",
         "CONTENT_TYPE": "multipart/form-data; boundary=boundary",
         "CONTENT_LENGTH": len(payload),
         "wsgi.input": payload,
     })
     request.body  # evaluate
     # Consume enough data to mess up the parsing:
     self.assertEqual(request.read(13), b"--boundary\r\nC")
     self.assertEqual(request.POST, {"name": ["value"]})
예제 #43
0
파일: tests.py 프로젝트: Aliced3645/django
 def test_stream(self):
     payload = b'name=value'
     request = WSGIRequest({'REQUEST_METHOD': 'POST',
                            'CONTENT_LENGTH': len(payload),
                            'wsgi.input': BytesIO(payload)})
     self.assertEqual(request.read(), b'name=value')
예제 #44
0
파일: tests.py 프로젝트: Anoopsmohan/django
 def test_stream(self):
     request = WSGIRequest({'REQUEST_METHOD': 'POST', 'wsgi.input': StringIO('name=value')})
     self.assertEqual(request.read(), 'name=value')
예제 #45
0
 def test_stream(self):
     request = WSGIRequest({
         'REQUEST_METHOD': 'POST',
         'wsgi.input': StringIO('name=value')
     })
     self.assertEqual(request.read(), 'name=value')