Exemplo n.º 1
0
def test_abs_use_case_invalid_request():
    invalid_request = Request()
    invalid_request.add_error(ErrorMessage('someParam', 'some message'))

    use_case = UseCaseAbsImpl()
    res = use_case.execute(invalid_request)

    assert bool(res) is False
Exemplo n.º 2
0
def test_request_multiple_errors():
    req = Request()

    req.add_errors([ErrorMessage('field.name', 'mandatory field')])

    assert bool(req) is False
    assert len(req.errors) == 1
    assert req.errors[0].type == 'field.name'
    assert req.errors[0].message == 'mandatory field'
Exemplo n.º 3
0
def test_log_error_in_invalid_request():
    logger = mock.Mock()

    class FooCase(UseCaseAbs):
        def process_request(self, req):
            return True

        def logger(self):
            return logger

    invalid_request = Request()
    invalid_request.add_error(ErrorMessage('someParam', 'some message'))

    use_case = FooCase()
    res = use_case.execute(invalid_request)

    assert bool(res) is False
    assert logger.debug.call_count == 1
Exemplo n.º 4
0
def test_response_builder_from_invalid_request():
    invalid_req = Request()
    invalid_req.add_error(
        ErrorMessage(type_='name', message='exceed max chars'))
    invalid_req.add_error(ErrorMessage(type_='age', message='is not integer'))

    response = ResponseFailureBuilder.build_from_invalid_request(invalid_req)

    assert bool(response) is False
    assert response.status == resp_status.PARAMETERS_ERROR
    assert len(response.errors) == 2
    assert response.errors[0].type == 'name'
    assert response.errors[0].message == 'exceed max chars'
    assert response.errors[1].type == 'age'
    assert response.errors[1].message == 'is not integer'
Exemplo n.º 5
0
 def custom_process(self, req: Request) -> Response:
     params = req.to_dict()
     oid = params.pop('oid')
     result = self.repo.update(oid=oid, attributes=params)
     return Response(result)
Exemplo n.º 6
0
 def create_error_response(cls, errors: List[ErrorMessage]):
     res = Request()
     res.add_errors(errors)
     return res
Exemplo n.º 7
0
def test_request_is_valid():
    req = Request()

    assert bool(req) is True
Exemplo n.º 8
0
def test_request_is_not_valid():
    req = Request()
    req.add_error(ErrorMessage('field.name', 'mandatory field'))

    assert bool(req) is False
Exemplo n.º 9
0
def test_request_must_implement_from_dict():
    req = Request()

    with pytest.raises(NotImplementedError):
        req.from_dict({})