Example #1
0
def test_response_can_add_multiples_errors():
    res_type = 'Context Error'
    res_message = 'This is an error'
    response = Response()
    response.add_errors([ErrorMessage(res_type, res_message)])

    assert bool(response) is False
    assert len(response.errors) == 1
    assert response.errors[0].type == res_type
    assert response.errors[0].message == res_message
Example #2
0
def test_response_failure_has_errors():
    res_type = 'Context Error'
    res_message = 'This is an error'
    res_error_type = 'Error Type'
    response = Response(status=res_error_type)
    response.add_error(ErrorMessage(res_type, res_message))

    assert bool(response) is False
    assert len(response.errors) == 1
    assert response.status == res_error_type
    assert response.errors[0].type == res_type
    assert response.errors[0].message == res_message
Example #3
0
 def custom_process(self, req: ListRequest) -> Response:
     try:
         result = self.repo.execute(req.ft, req.filters, req.page, req.sort)
         return Response(result)
     except FilterDoesNotExist:
         return ResponseFailureBuilder.build_parameters_error(
             'Filter', 'filter="{}" does not exists'.format(req.ft))
Example #4
0
 def custom_process(self, req: DeleteRequest) -> Response:
     result = self.repo.delete(oid=req.oid)
     return Response(result)
Example #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)
Example #6
0
 def custom_process(self, req) -> Response:
     result = self.repo.get(oid=req.oid)
     return Response(result)
Example #7
0
 def custom_process(self, req: Request) -> Response:
     entity = self.create_entity(req)
     result = self.repo.save(entity=entity)
     return Response(result)
Example #8
0
def test_response_success_contains_result():
    res = 'OK'
    response = Response(res)

    assert response.result == res
Example #9
0
def test_success_response_is_true_with_context():
    res = Response(context='OK')

    assert bool(res) is True
Example #10
0
def test_response_is_success():
    res = Response()

    assert bool(res) is True