Esempio n. 1
0
def test_storageroom_list_handles_bad_request():
    repo = mock.Mock()

    storageroom_list_use_case = uc.StorageRoomListUseCase(repo)
    request_object = req.StorageRoomListRequestObject.from_dict({'filters': 5})
    response_object = storageroom_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'
    }
Esempio n. 2
0
def test_storageroom_list_without_parameters(domain_storagerooms):
    repo = mock.Mock()
    repo.list.return_value = domain_storagerooms

    storageroom_list_use_case = uc.StorageRoomListUseCase(repo)
    request_object = req.StorageRoomListRequestObject.from_dict({})
    response_object = storageroom_list_use_case.execute(request_object)

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

    assert response_object.value == domain_storagerooms
Esempio n. 3
0
def test_storageroom_list_handles_generic_error():
    repo = mock.Mock()
    repo.list.side_effect = Exception('Just an error message')

    storageroom_list_use_case = uc.StorageRoomListUseCase(repo)
    request_object = req.StorageRoomListRequestObject.from_dict({})
    response_object = storageroom_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'
    }
Esempio n. 4
0
def storageroom():
    qrystr_params = {
        'filters': {},
    }

    for arg, values in request.args.items():
        if arg.startswith('filter_'):
            qrystr_params['filters'][arg.replace('filter_', '')] = values

    request_object = req.StorageRoomListRequestObject.from_dict(qrystr_params)

    repo = mr.MemRepo([storageroom1, storageroom2, storageroom3])
    use_case = uc.StorageRoomListUseCase(repo)

    response = use_case.execute(request_object)

    return Response(json.dumps(response.value, cls=ser.StorageRoomEncoder),
                    mimetype='application/json',
                    status=STATUS_CODES[response.type])
Esempio n. 5
0
    def on_get(self, request, response):
        qrystr_params = {
            'filters': {},
        }
        for arg, values in request.params.items():
            if arg.startswith('filter_'):
                qrystr_params['filters'][arg.replace('filter_', '')] = values

        request_object = req.StorageRoomListRequestObject.from_dict(
            qrystr_params)
        repo = mr.MemRepo([
            first_storageroom,
            second_storageroom,
            third_storageroom,
        ])
        use_case = uc.StorageRoomListUseCase(repo)
        response_result = use_case.execute(request_object)

        response.body = json.dumps(response_result.value,
                                   cls=ser.StorageRoomEncoder)
        response.set_header('mimetype', 'application/json')
        response.set_header('Powered-By', 'Falcon')
        response.status = STATUS_CODES[response_result.type]