1
0
mirror of https://github.com/bigchaindb/bigchaindb.git synced 2024-06-23 01:36:42 +02:00
bigchaindb/tests/web/test_content_type_middleware.py
David Dashyan 9e99c024d3
Replace headers (#2683)
Signed-off-by: David Dashyan <mail@davie.li>
2020-04-06 11:52:18 +02:00

46 lines
1.6 KiB
Python

# Copyright © 2020 Interplanetary Database Association e.V.,
# BigchainDB and IPDB software contributors.
# SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
# Code is Apache-2.0 and docs are CC-BY-4.0
from unittest.mock import Mock
OUTPUTS_ENDPOINT = '/api/v1/outputs/'
def test_middleware_does_nothing_when_no_content_type_is_provided():
from bigchaindb.web.strip_content_type_middleware import StripContentTypeMiddleware
mock = Mock()
middleware = StripContentTypeMiddleware(mock)
middleware({'REQUEST_METHOD': 'GET'}, None)
assert 'CONTENT_TYPE' not in mock.call_args[0][0]
def test_middleware_strips_content_type_from_gets():
from bigchaindb.web.strip_content_type_middleware import StripContentTypeMiddleware
mock = Mock()
middleware = StripContentTypeMiddleware(mock)
middleware({'REQUEST_METHOD': 'GET',
'CONTENT_TYPE': 'application/json'},
None)
assert 'CONTENT_TYPE' not in mock.call_args[0][0]
def test_middleware_does_notstrip_content_type_from_other_methods():
from bigchaindb.web.strip_content_type_middleware import StripContentTypeMiddleware
mock = Mock()
middleware = StripContentTypeMiddleware(mock)
middleware({'REQUEST_METHOD': 'POST',
'CONTENT_TYPE': 'application/json'},
None)
assert 'CONTENT_TYPE' in mock.call_args[0][0]
def test_get_outputs_endpoint_with_content_type(client, user_pk):
res = client.get(OUTPUTS_ENDPOINT + '?public_key={}'.format(user_pk),
headers=[('Content-Type', 'application/json')])
assert res.status_code == 200