def test_build_room_list_request_accepted_filters(key): filters = {key: 1} request = build_room_list_request(filters=filters) assert request.filters == filters assert bool(request) is True
def test_build_room_list_request_rejected_filters(key): filters = {key: 1} request = build_room_list_request(filters=filters) assert request.has_errors() assert request.errors[0]["parameter"] == "filters" assert bool(request) is False
def test_room_list_without_parameters(domain_rooms): repo = mock.Mock() repo.list.return_value = domain_rooms request = build_room_list_request() response = room_list_use_case(repo, request) assert bool(response) is True repo.list.assert_called_with(filters=None) assert response.value == domain_rooms
def test_room_list_handles_bad_request(): repo = mock.Mock() request = build_room_list_request(filters=5) response = room_list_use_case(repo, request) assert bool(response) is False assert response.value == { "type": ResponseTypes.PARAMETERS_ERROR, "message": "filters: Is not iterable", }
def test_room_list_with_filters(domain_rooms): repo = mock.Mock() repo.list.return_value = domain_rooms qry_filters = {"code__eq": 5} request = build_room_list_request(filters=qry_filters) response = room_list_use_case(repo, request) assert bool(response) is True repo.list.assert_called_with(filters=qry_filters) assert response.value == domain_rooms
def test_room_list_handles_generic_error(): repo = mock.Mock() repo.list.side_effect = Exception("Just an error message") request = build_room_list_request(filters={}) response = room_list_use_case(repo, request) assert bool(response) is False assert response.value == { "type": ResponseTypes.SYSTEM_ERROR, "message": "Exception: Just an error message" }
"latitude": 51.75436293, }, { "code": "fe2c3195-aeff-487a-a08f-e0bdc0ec6e9a", "size": 405, "price": 66, "longitude": 0.18228006, "latitude": 51.74640997, }, { "code": "913694c6-435a-4366-ba0d-da5334a611b2", "size": 56, "price": 60, "longitude": 0.27891577, "latitude": 51.45994069, }, { "code": "eed76e77-55c1-41ce-985d-ca49bf6c0585", "size": 93, "price": 48, "longitude": 0.33894476, "latitude": 51.39916678, }, ] repo = MemRepo(rooms) request = build_room_list_request() response = room_list_use_case(repo, request) print([room.to_dict() for room in response.value])
def test_build_room_list_request_without_parameters(): request = build_room_list_request() assert request.filters is None assert bool(request) is True
def test_build_room_list_request_with_incorrect_filter_keys(): request = build_room_list_request({"a": 1}) assert request.has_errors() assert request.errors[0]["parameter"] == "filters" assert bool(request) is False
def test_build_room_list_request_with_invalid_filters_parameter(): request = build_room_list_request(filters=5) assert request.has_errors() assert request.errors[0]["parameter"] == "filters" assert bool(request) is False
def test_build_room_list_request_from_empty_dict(): request = build_room_list_request({}) assert request.filters == {} assert bool(request) is True