def test_find_user_controller_server_error():
    """ Should return 500 """

    sut_variables = make_sut()

    sut = sut_variables["sut"]

    response = sut.handle(HttpRequest(query={"valid_field": 1}))

    assert response.status_code == 500
    assert response.body["error"] is not None
def test_register_user_controller_server_error():
    """ Should return 500 """

    sut_variables = make_sut()

    sut = sut_variables["sut"]

    response = sut.handle(HttpRequest(body=None))

    assert response.status_code == 500
    assert response.body["error"] is not None
def test_find_user_controller_bad_request():
    """ Should return status 400 + required field error """

    sut_variables = make_sut()

    sut = sut_variables["sut"]

    response = sut.handle(HttpRequest(query={}))

    assert response.status_code == 400
    assert response.body["error"] == required_param_error("valid_field")
def test_register_user_controller_unprocessable_entity():
    """ Should return 422 """

    sut_variables = make_sut()

    sut = sut_variables["sut"]

    attributes = mock_http_request(pass_unp_entity=False)
    response = sut.handle(HttpRequest(body=attributes))

    assert response.status_code == 422
    assert response.body["error"] == "Unprocessable Entity"
def test_register_user_controller_bad_request():
    """ Should return status 400 """

    sut_variables = make_sut()

    sut = sut_variables["sut"]

    attributes = mock_http_request(pass_validation=False)
    response = sut.handle(HttpRequest(body=attributes))

    assert response.status_code == 400
    assert response.body["error"] == required_param_error("valid_field")
示例#6
0
def test_fetch_users_success():
    """ Should return status 200 """

    sut_variables = make_sut()

    sut = sut_variables["sut"]

    response = sut.handle(HttpRequest())

    assert response.status_code == 200
    assert response.body is not None
    assert len(response.body) > 0
def test_find_user_success():
    """ Should return status 200 """

    sut_variables = make_sut()

    sut = sut_variables["sut"]

    params = mock_http_request()
    response = sut.handle(HttpRequest(query=params))

    assert response.status_code == 200
    assert response.body is not None
def test_register_user_controller_success():
    """ Should return status 200 """

    sut_variables = make_sut()

    sut, register_stub = sut_variables["sut"], sut_variables["register_stub"]

    attributes = mock_http_request()
    response = sut.handle(HttpRequest(body=attributes))

    assert register_stub.register_param["username"] == attributes["username"]
    assert register_stub.register_param["password"] == attributes["password"]

    assert response.status_code == 200
    assert response.body is not None
示例#9
0
def test_find_user_controller_server_error(mocker: MockerFixture):
    """ Should return 500 """

    sut_variables = make_sut()

    sut, fetch_users_uc = sut_variables["sut"], sut_variables[
        "fetch_users_stub"]

    mocker.patch.context_manager(fetch_users_uc,
                                 "execute",
                                 side_effect=Exception())

    response = sut.handle(HttpRequest())

    assert response.status_code == 500
    assert response.body["error"] is not None