def test_list(self, request):
     self.logger.info('Running test: %s', get_function_name(__name__))
     service = StandardManagerService(logger=self.logger,
                                      config=self.CONFIG,
                                      connection=get_connection())
     data = service.list(request)
     self.assertIsNotNone(data)
コード例 #2
0
def standard_list():
    """
    get:
       summary: List all standards
       responses:
            200:
                description: Success response
                content:
                    application/json:
                        schema: StandardListResponseSchema
    """
    service = StandardManagerService(logger=logger)
    request = ApiRequest().parse_request(app)
    response = ApiResponse(request)
    status_code = 200

    try:
        data = service.list(request)
        total = service.count(request)

        response.set_data(data)
        response.set_total(total)

    except Exception as err:
        logger.error(err)

        if isinstance(err, ApiException):
            api_ex = err
            status_code = 404
        else:
            api_ex = ApiException(MessagesEnum.LIST_ERROR)
            status_code = 500

        response.set_exception(api_ex)
    return response.get_response(status_code)
コード例 #3
0
def standard_delete(uuid):
    """
    delete:
        summary: Delete Standard
        parameters:
            - in: path
              name: uuid
              description: "Standard uuid"
              required: true
              schema:
                type: string
                format: UUID
        responses:
            200:
                content:
                    application/json:
                        schema: StandardDeleteResponseSchema
    """
    service = StandardManagerService(logger=logger)
    request = ApiRequest().parse_request(app)
    response = ApiResponse(request)
    status_code = 200

    try:
        service.delete(request, uuid)
        data = {
            "success": True,
            "code": MessagesEnum.ENTITY_DELETION_SUCCESS.code,
            "label": MessagesEnum.ENTITY_DELETION_SUCCESS.label,
            "message": MessagesEnum.ENTITY_DELETION_SUCCESS.message,
            "params": [uuid]
        }
        response.set_data(data)

    except Exception as err:
        print(err)
        logger.error(err)

        if isinstance(err, ApiException):
            api_ex = err
            status_code = 404
        else:
            api_ex = ApiException(MessagesEnum.DELETE_ERROR)
            status_code = 500

        data = {
            "success": False,
            "code": api_ex.code,
            "label": api_ex.label,
            "message": api_ex.message,
            # por segurança não passar o param aqui
            "params": []
        }
        response.set_data(data)

        # response.set_exception(api_ex)
    return response.get_response(status_code)
    def test_count(self, request):
        """

        :param (ApiRequest) request:
        :return:
        """
        self.logger.info('Running test: %s', get_function_name(__name__))
        service = StandardManagerService(logger=self.logger,
                                         config=self.CONFIG,
                                         connection=get_connection())
        data = service.count(request)

        self.assertIsNotNone(data)
        self.assertTrue(data > 0)
コード例 #5
0
def standard_update(uuid):
    """
    put:
        summary: Update Standard
        parameters:
            - in: path
              name: uuid
              description: "Standard uuid"
              required: true
              schema:
                type: string
                format: UUID
        requestBody:
            description: 'Objeto a ser atualizado'
            required: true
            content:
                application/json:
                    schema: StandardUpdateRequest
        responses:
            200:
                content:
                    application/json:
                        schema: StandardUpdateResponseSchema
    """
    service = StandardManagerService(logger=logger)
    request = ApiRequest().parse_request(app)
    response = ApiResponse(request)
    status_code = 200

    try:
        data = service.update(request, uuid)

        response.set_data(data)

    except Exception as err:
        logger.error(err)

        if isinstance(err, ApiException):
            api_ex = err
            status_code = 404
        else:
            api_ex = ApiException(MessagesEnum.UPDATE_ERROR)
            status_code = 500

        response.set_exception(api_ex)
    return response.get_response(status_code)
コード例 #6
0
def standard_get(uuid):
    """
    get:
        summary: Get Standard
        parameters:
            - in: path
              name: uuid
              description: "Standard uuid"
              required: true
              schema:
                type: string
                format: UUID
        responses:
            200:
                description: Success response
                content:
                    application/json:
                        schema: StandardGetResponseSchema
    """
    service = StandardManagerService(logger=logger)
    request = ApiRequest().parse_request(app)
    response = ApiResponse(request)
    status_code = 200

    try:
        data = service.get(request, uuid)
        response.set_data(data)
    except Exception as err:
        logger.error(err)

        if isinstance(err, ApiException):
            api_ex = err
            status_code = 404
        else:
            api_ex = ApiException(MessagesEnum.FIND_ERROR)
            status_code = 500

        response.set_exception(api_ex)
    return response.get_response(status_code)
コード例 #7
0
def standard_create():
    """
    post:
        summary: Create Standard
        requestBody:
            description: 'Objeto a ser criado'
            required: true
            content:
                application/json:
                    schema: StandardCreateRequest
        responses:
            200:
                content:
                    application/json:
                        schema: StandardCreateResponseSchema
    """
    service = StandardManagerService(logger=logger)
    request = ApiRequest().parse_request(app)
    response = ApiResponse(request)
    status_code = 200

    try:
        data = service.create(request)

        response.set_data(data)

    except Exception as err:
        logger.error(err)

        if isinstance(err, ApiException):
            api_ex = err
            status_code = 404
        else:
            api_ex = ApiException(MessagesEnum.LIST_ERROR)
            status_code = 500

        response.set_exception(api_ex)
    return response.get_response(status_code)