def test_valid_header_header(): request.headers['Content-Type'] = 'application/json' request.headers['Authorization'] = 'Bearer token' try: token = validate_request_header(request, content=True, authorization=True) except Exception: pytest.fail("Failed to pass content type header") assert token == 'token'
def test_valid_wrapper_null_token_authorization_header(): # request has Content-Type key but invalid value request.headers['Authorization'] = 'Bearer ' with pytest.raises(BadRequestError): validate_request_header(request, content=True, authorization=True)
def test_invalid_value_authorization_header(): # request has Content-Type key but invalid value request.headers['Authorization'] = 'blah' with pytest.raises(BadRequestError): validate_request_header(request, content=True, authorization=True)
def test_no_authorization_header(): with pytest.raises(BadRequestError): validate_request_header(request, content=True, authorization=True)
def test_valid_content_header(): request.headers['Content-Type'] = 'application/json' try: validate_request_header(request, content=True, authorization=False) except Exception: pytest.fail("Failed to pass content type header")
def test_null_value_content_header(): # request has Content-Type key but no value request.headers['Content-Type'] = '' with pytest.raises(BadRequestError): validate_request_header(request, content=True, authorization=True)