示例#1
0
def test_error_5XX_status_code_message():
    response = Response()
    response.set_status_code(506)
    check = response.error_5XX('I\'m a variant!!!')
    assert check['statusCode'] == 506
    assert check['body'] == '{"message": "I\'m a variant!!!"}'
    assert check['headers']['Access-Control-Allow-Origin'] == '*'
示例#2
0
def test_build_response_error_1():
    response = Response()
    response.status_code = 0
    response.set_header('x-app', 'blargh!')
    response.set_body('{"hello": "world"}')

    with pytest.raises(Exception, match=r'Response not well formed'):
        response._build_response()
示例#3
0
def test_build_response():
    response = Response()
    response.set_status_code(404)
    response.set_header('x-app', 'blargh!')
    response.set_body('{"hello": "world"}')

    check = response._build_response()
    assert check['statusCode'] == 404
    assert check['body'] == '{"hello": "world"}'
    assert check['headers']['x-app'] == "blargh!"
示例#4
0
def test_build_response_error_2():
    response = Response()
    response.status_code = 200
    response.headers = None
    response.set_body('{"hello": "world"}')

    with pytest.raises(Exception, match=r'Response not well formed'):
        response._build_response()
示例#5
0
def test_init():
    response = Response()
    assert response.status_code == 0
    assert response.headers == {
        "Access-Control-Allow-Origin": "*",
        "Access-Control-Allow-Credentials": "true"
    }
    assert response.body is None
示例#6
0
def test_set_header():
    response = Response()
    response.set_header('x-api', 'some_random_stuff')
    assert response.headers['x-api'] == 'some_random_stuff'
示例#7
0
def test_set_status_code_exp():
    response = Response()
    with pytest.raises(Exception):
        response.set_status_code(700)
示例#8
0
def test_set_status_code():
    response = Response()
    response.set_status_code(500)
    assert response.status_code == 500
示例#9
0
def test_error_5XX_message():
    response = Response()
    check = response.error_5XX('this is a system error')
    assert check['statusCode'] == 500
    assert check['body'] == '{"message": "this is a system error"}'
    assert check['headers']['Access-Control-Allow-Origin'] == '*'
示例#10
0
def test_error_5XX():
    response = Response()
    check = response.error_5XX()
    assert check['statusCode'] == 500
    assert check['body'] is None
    assert check['headers']['Access-Control-Allow-Origin'] == '*'
示例#11
0
def test_ok_200_JSON():
    response = Response()
    check = response.ok_200('{"my_data": "big blob of JSON"}')
    assert check['statusCode'] == 200
    assert check['body'] == '{"my_data": "big blob of JSON"}'
示例#12
0
def test_ok_200_dict():
    response = Response()
    check = response.ok_200({'my_data': 'dict of data to return'})
    assert check['statusCode'] == 200
    assert check['body'] == '{"my_data": "dict of data to return"}'
示例#13
0
def test_ok_200():
    response = Response()
    check = response.ok_200()
    assert check['statusCode'] == 200
    assert check['headers']['Access-Control-Allow-Origin'] == '*'
    assert check['body'] is None
示例#14
0
def test_set_header_missing_key():
    response = Response()
    with pytest.raises(Exception, match=r"a header key"):
        response.set_header(None, 'some_random_stuff')