def stations():
    request_object = req.StationListRequestObject.from_dict({})

    repo = sql.SQLiteRepo()
    use_case = uc.StationListUseCase(repo)

    response = use_case.execute(request_object)

    return Response(json.dumps(response.value, cls=ser.StationEncoder),
                    mimetype='application/json',
                    status=200)
Exemplo n.º 2
0
def test_station_list_handles_bad_request():
    repo = mock.Mock()

    station_list_use_case = uc.StationListUseCase(repo)
    request_object = req.StationListRequestObject.from_dict({'filters': 5})

    response_object = station_list_use_case.execute(request_object)

    assert bool(response_object) is False
    assert response_object.value == {
        'type': res.ResponseFailure.PARAMETERS_ERROR,
        'message': "filters: Is not iterable"
    }
Exemplo n.º 3
0
def test_station_list_without_parameters(domain_station):
    repo = mock.Mock()
    repo.list.return_value = domain_station

    station_list_use_case = uc.StationListUseCase(repo)
    request_object = req.StationListRequestObject.from_dict({})

    response_object = station_list_use_case.execute(request_object)

    assert bool(response_object) is True
    repo.list.assert_called_with(filters=None)

    assert response_object.value == domain_station
Exemplo n.º 4
0
def test_station_list_handles_generic_error():
    repo = mock.Mock()
    repo.list.side_effect = Exception('Just an error message')

    station_list_use_case = uc.StationListUseCase(repo)
    request_object = req.StationListRequestObject.from_dict({})

    response_object = station_list_use_case.execute(request_object)

    assert bool(response_object) is False
    assert response_object.value == {
        'type': res.ResponseFailure.SYSTEM_ERROR,
        'message': "Exception: Just an error message"
    }
Exemplo n.º 5
0
def test_station_list_with_filters(domain_station):
    repo = mock.Mock()
    repo.list.return_value = domain_station

    station_list_use_case = uc.StationListUseCase(repo)
    qry_filters = {'a': 5}
    request_object = req.StationListRequestObject.from_dict(
        {'filters': qry_filters})

    response_object = station_list_use_case.execute(request_object)

    assert bool(response_object) is True
    repo.list.assert_called_with(filters=qry_filters)
    assert response_object.value == domain_station