Exemplo n.º 1
0
def test_handle_http_request_no_string_content():
    request = mock_http_request()
    response = mock_http_response()
    action = MagicMock()
    action.return_value = '123'

    resp = handle_action(action, request, response)

    action.assert_called_once_with(request, response)
    assert '123' == resp.content
def test_handle_http_request_no_string_content():
    request = mock_http_request()
    response = mock_http_response()
    action = MagicMock()
    action.return_value = '123'

    resp = handle_action(action, request, response)

    action.assert_called_once_with(request, response)
    assert '123' == resp.content
Exemplo n.º 3
0
def test_handle_http_request_no_content():
    request = mock_http_request()
    response = mock_http_response()

    action = MagicMock()
    action.return_value = None

    resp = handle_action(action, request, response)

    action.assert_called_once_with(request, response)
    assert resp == response
    assert response.status == 204
    assert response.content_type == 'text/html'
    assert response.content == ''
def test_handle_http_request_no_content():
    request = mock_http_request()
    response = mock_http_response()

    action = MagicMock()
    action.return_value = None

    resp = handle_action(action, request, response)

    action.assert_called_once_with(request, response)
    assert resp == response
    assert response.status == 204
    assert response.content_type == 'text/html'
    assert response.content == ''
Exemplo n.º 5
0
def test_handle_http_request_with_string_content_not_set_status():
    request = mock_http_request()
    response = mock_http_response()
    response.status = None
    action = MagicMock()
    action.return_value = 'response'
    assert response.status != 200

    resp = handle_action(action, request, response)

    action.assert_called_once_with(request, response)
    assert resp == response
    assert response.status == 200
    assert resp.content_type == 'text/html'
    assert resp.content == 'response'
def test_handle_http_request_with_string_content_and_action_set_status_content_type():
    request = mock_http_request()
    response = Mock(HTTPResponse)
    action = MagicMock()
    action.return_value = content = '<book>resource created</book>'
    response.status = 201
    response.content_type = 'text/xml'

    resp = handle_action(action, request, response)

    action.assert_called_once_with(request, response)
    assert resp == response
    assert resp.status == 201
    assert resp.content_type == 'text/xml'
    assert resp.content == content
def test_handle_http_request_with_string_content_not_set_status():
    request = mock_http_request()
    response = mock_http_response()
    response.status = None
    action = MagicMock()
    action.return_value = 'response'
    assert response.status != 200

    resp = handle_action(action, request, response)

    action.assert_called_once_with(request, response)
    assert resp == response
    assert response.status == 200
    assert resp.content_type == 'text/html'
    assert resp.content == 'response'
Exemplo n.º 8
0
def test_handle_http_request_with_string_content_and_action_set_status_content_type(
):
    request = mock_http_request()
    response = Mock(HTTPResponse)
    action = MagicMock()
    action.return_value = content = '<book>resource created</book>'
    response.status = 201
    response.content_type = 'text/xml'

    resp = handle_action(action, request, response)

    action.assert_called_once_with(request, response)
    assert resp == response
    assert resp.status == 201
    assert resp.content_type == 'text/xml'
    assert resp.content == content