Пример #1
0
 def find_code_value_by_type_and_code(
         cls,
         code_type: str,
         code: str
 ):
     """Find code values by code type and code."""
     current_app.logger.debug(f'<find_code_value_by_type_and_code : {code_type} - {code}')
     code_response = {}
     if cache.get(code_type):
         filtered_codes = [cd for cd in cache.get(code_type) if cd.get('type') == code or cd.get('code') == code]
         if filtered_codes:
             code_response = filtered_codes[0]
     else:
         if code_type == CodeValue.ERROR.value:
             codes_model = ErrorCode.find_by_code(code)
             error_schema = ErrorCodeSchema()
             code_response = error_schema.dump(codes_model, many=False)
         elif code_type == CodeValue.INVOICE_STATUS.value:
             codes_model = InvoiceStatusCode.find_by_code(code)
             schema = InvoiceStatusCodeSchema()
             code_response = schema.dump(codes_model, many=False)
         elif code_type == CodeValue.CORP_TYPE.value:
             codes_model = CorpType.find_by_code(code)
             schema = CorpTypeSchema()
             code_response = schema.dump(codes_model, many=False)
     current_app.logger.debug('>find_code_value_by_type_and_code')
     return code_response
Пример #2
0
    def find_code_values_by_type(
            cls,
            code_type: str
    ):
        """Find code values by code type."""
        current_app.logger.debug(f'<find_code_values_by_type : {code_type}')
        response = {}

        # Get from cache and if still none look up in database
        codes_response = cache.get(code_type)
        codes_models, schema = None, None
        if not codes_response:
            if code_type == CodeValue.ERROR.value:
                codes_models = ErrorCode.find_all()
                schema = ErrorCodeSchema()
            elif code_type == CodeValue.INVOICE_STATUS.value:
                codes_models = InvoiceStatusCode.find_all()
                schema = InvoiceStatusCodeSchema()
            elif code_type == CodeValue.CORP_TYPE.value:
                codes_models = CorpType.find_all()
                schema = CorpTypeSchema()
            elif code_type == CodeValue.FEE_CODE.value:
                codes_models = FeeCode.find_all()
                schema = FeeCodeSchema()
            if schema and codes_models:
                codes_response = schema.dump(codes_models, many=True)
                cache.set(code_type, codes_response)

        response['codes'] = codes_response
        current_app.logger.debug('>find_code_values_by_type')
        return response
Пример #3
0
    def find_code_values_by_type(cls, code_type: str):
        """Find code values by code type."""
        current_app.logger.debug(f'<find_code_values_by_type : {code_type}')
        response = {}

        # Get from cache and if still none look up in database
        codes_response = cache.get(code_type)
        if not codes_response:
            if code_type == CodeValue.ERROR.value:
                codes_models = ErrorCode.find_all()
                error_schema = ErrorCodeSchema()
                codes_response = error_schema.dump(codes_models, many=True)
            elif code_type == CodeValue.PAYMENT_STATUS.value:
                codes_models = PaymentStatusCode.find_all()
                code_schema = PaymentStatusCodeSchema()
                codes_response = code_schema.dump(codes_models, many=True)

            cache.set(code_type, codes_response)

        response['codes'] = codes_response
        current_app.logger.debug('>find_code_values_by_type')
        return response
Пример #4
0
def test_build_cache(session):
    """Assert that code cache is built."""
    CodeService.build_all_codes_cache()
    assert cache is not None
    assert cache.get(Code.ERROR.value) is not None