当前位置: 首页>>代码示例>>Python>>正文


Python ParamsSerializer.is_valid方法代码示例

本文整理汇总了Python中ratechecker.ratechecker_parameters.ParamsSerializer.is_valid方法的典型用法代码示例。如果您正苦于以下问题:Python ParamsSerializer.is_valid方法的具体用法?Python ParamsSerializer.is_valid怎么用?Python ParamsSerializer.is_valid使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ratechecker.ratechecker_parameters.ParamsSerializer的用法示例。


在下文中一共展示了ParamsSerializer.is_valid方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: validate_scenario

# 需要导入模块: from ratechecker.ratechecker_parameters import ParamsSerializer [as 别名]
# 或者: from ratechecker.ratechecker_parameters.ParamsSerializer import is_valid [as 别名]
    def validate_scenario(self, scenario, expected_result):
        serializer = ParamsSerializer(data=scenario)
        serializer.is_valid(raise_exception=True)

        rates = get_rates(serializer.validated_data, data_load_testing=True)
        computed_rates = rates.get('data')

        return self.compare_result(computed_rates, expected_result)
开发者ID:cfpb,项目名称:owning-a-home-api,代码行数:10,代码来源:validation.py

示例2: test_is_valid__maxfico_smaller

# 需要导入模块: from ratechecker.ratechecker_parameters import ParamsSerializer [as 别名]
# 或者: from ratechecker.ratechecker_parameters.ParamsSerializer import is_valid [as 别名]
 def test_is_valid__maxfico_smaller(self):
     self.data['maxfico'] = 600
     self.data['minfico'] = 700
     serializer = ParamsSerializer(data=self.data)
     self.assertTrue(serializer.is_valid())
     self.assertEqual(serializer.data.get('maxfico'), 700)
     self.assertEqual(serializer.data.get('minfico'), 600)
开发者ID:fna,项目名称:owning-a-home-api,代码行数:9,代码来源:test_views_ratecheckerparameters.py

示例3: rate_checker

# 需要导入模块: from ratechecker.ratechecker_parameters import ParamsSerializer [as 别名]
# 或者: from ratechecker.ratechecker_parameters.ParamsSerializer import is_valid [as 别名]
def rate_checker(request):
    """
    Return available rates in percentage and number of institutions
    with the corresponding rate
    (i.e. "4.75": 2 means there are 2 institutions with the rate of 4.75%)
    """

    if request.method == 'GET':

        # Clean the parameters, make sure no leading or trailing spaces,
        # transform them to upper cases
        fixed_data = {
            k: v.strip().upper()
            for k, v in request.query_params.items()
        }
        fixed_data = set_lock_max_min(fixed_data)
        serializer = ParamsSerializer(data=fixed_data)

        if serializer.is_valid():
            rate_results = get_rates(serializer.validated_data)
            rate_results['request'] = serializer.validated_data
            return Response(rate_results)
        else:
            return Response(serializer.errors,
                            status=status.HTTP_400_BAD_REQUEST)
开发者ID:cfpb,项目名称:owning-a-home-api,代码行数:27,代码来源:views.py

示例4: test_is_valid__ltv__without_ltv

# 需要导入模块: from ratechecker.ratechecker_parameters import ParamsSerializer [as 别名]
# 或者: from ratechecker.ratechecker_parameters.ParamsSerializer import is_valid [as 别名]
 def test_is_valid__ltv__without_ltv(self):
     self.data['price'] = 200000
     self.data['loan_amount'] = 180000
     serializer = ParamsSerializer(data=self.data)
     self.assertTrue(serializer.is_valid())
     self.assertEqual(serializer.data.get('min_ltv'), 90)
     self.assertTrue(serializer.data.get('min_ltv'), serializer.data.get('max_ltv'))
开发者ID:fna,项目名称:owning-a-home-api,代码行数:9,代码来源:test_views_ratecheckerparameters.py

示例5: test_is_valid__lock_non_default

# 需要导入模块: from ratechecker.ratechecker_parameters import ParamsSerializer [as 别名]
# 或者: from ratechecker.ratechecker_parameters.ParamsSerializer import is_valid [as 别名]
 def test_is_valid__lock_non_default(self):
     self.data['lock'] = 30
     serializer = ParamsSerializer(data=self.data)
     self.assertTrue(serializer.is_valid())
     self.assertEqual(serializer.data.get('lock'), 30)
     self.assertEqual(serializer.data.get('min_lock'), 0)
     self.assertEqual(serializer.data.get('max_lock'), 30)
开发者ID:fna,项目名称:owning-a-home-api,代码行数:9,代码来源:test_views_ratecheckerparameters.py

示例6: test_is_valid__ficos_negative

# 需要导入模块: from ratechecker.ratechecker_parameters import ParamsSerializer [as 别名]
# 或者: from ratechecker.ratechecker_parameters.ParamsSerializer import is_valid [as 别名]
 def test_is_valid__ficos_negative(self):
     self.data['maxfico'] = -100
     self.data['minfico'] = -200
     serializer = ParamsSerializer(data=self.data)
     self.assertTrue(serializer.is_valid())
     self.assertEqual(serializer.data.get('maxfico'), 200)
     self.assertEqual(serializer.data.get('minfico'), 100)
开发者ID:fna,项目名称:owning-a-home-api,代码行数:9,代码来源:test_views_ratecheckerparameters.py

示例7: test_is_valid__property_type_invalid

# 需要导入模块: from ratechecker.ratechecker_parameters import ParamsSerializer [as 别名]
# 或者: from ratechecker.ratechecker_parameters.ParamsSerializer import is_valid [as 别名]
 def test_is_valid__property_type_invalid(self):
     self.data['property_type'] = 'A'
     serializer = ParamsSerializer(data=self.data)
     self.assertFalse(serializer.is_valid())
     self.assertEqual(
         serializer.errors.get('property_type'),
         [u'"A" is not a valid choice.']
         )
开发者ID:cfpb,项目名称:owning-a-home-api,代码行数:10,代码来源:test_views_ratecheckerparameters.py

示例8: test_is_valid__loan_amount_none

# 需要导入模块: from ratechecker.ratechecker_parameters import ParamsSerializer [as 别名]
# 或者: from ratechecker.ratechecker_parameters.ParamsSerializer import is_valid [as 别名]
 def test_is_valid__loan_amount_none(self):
     self.data['loan_amount'] = None
     serializer = ParamsSerializer(data=self.data)
     self.assertFalse(serializer.is_valid())
     self.assertEqual(
         serializer.errors.get('loan_amount'),
         [u'This field may not be null.']
         )
开发者ID:cfpb,项目名称:owning-a-home-api,代码行数:10,代码来源:test_views_ratecheckerparameters.py

示例9: test_is_valid__loan_amount_empty

# 需要导入模块: from ratechecker.ratechecker_parameters import ParamsSerializer [as 别名]
# 或者: from ratechecker.ratechecker_parameters.ParamsSerializer import is_valid [as 别名]
 def test_is_valid__loan_amount_empty(self):
     self.data['loan_amount'] = ''
     serializer = ParamsSerializer(data=self.data)
     self.assertFalse(serializer.is_valid())
     self.assertEqual(
         serializer.errors.get('loan_amount'),
         [u'A valid number is required.']
         )
开发者ID:cfpb,项目名称:owning-a-home-api,代码行数:10,代码来源:test_views_ratecheckerparameters.py

示例10: test_is_valid__state_invalid

# 需要导入模块: from ratechecker.ratechecker_parameters import ParamsSerializer [as 别名]
# 或者: from ratechecker.ratechecker_parameters.ParamsSerializer import is_valid [as 别名]
 def test_is_valid__state_invalid(self):
     self.data['state'] = 123
     serializer = ParamsSerializer(data=self.data)
     self.assertFalse(serializer.is_valid())
     self.assertEqual(
         serializer.errors.get('state'),
         [u'"123" is not a valid choice.']
         )
开发者ID:cfpb,项目名称:owning-a-home-api,代码行数:10,代码来源:test_views_ratecheckerparameters.py

示例11: test_is_valid__loan_purpose_invalid

# 需要导入模块: from ratechecker.ratechecker_parameters import ParamsSerializer [as 别名]
# 或者: from ratechecker.ratechecker_parameters.ParamsSerializer import is_valid [as 别名]
 def test_is_valid__loan_purpose_invalid(self):
     self.data['loan_purpose'] = 'A'
     serializer = ParamsSerializer(data=self.data)
     self.assertFalse(serializer.is_valid())
     self.assertEqual(
         serializer.errors.get('loan_purpose'),
         [u'"A" is not a valid choice.']
         )
开发者ID:cfpb,项目名称:owning-a-home-api,代码行数:10,代码来源:test_views_ratecheckerparameters.py

示例12: test_is_valid_no_price_or_ltv

# 需要导入模块: from ratechecker.ratechecker_parameters import ParamsSerializer [as 别名]
# 或者: from ratechecker.ratechecker_parameters.ParamsSerializer import is_valid [as 别名]
 def test_is_valid_no_price_or_ltv(self):
     data = dict(self.data)
     data.pop('price', None)
     data.pop('ltv', None)
     serializer = ParamsSerializer(data=data)
     self.assertFalse(serializer.is_valid())
     self.assertIn(
         'one of price or ltv is required',
         serializer.errors['non_field_errors']
     )
开发者ID:cfpb,项目名称:owning-a-home-api,代码行数:12,代码来源:test_views_ratecheckerparameters.py

示例13: test_is_valid__valid_args

# 需要导入模块: from ratechecker.ratechecker_parameters import ParamsSerializer [as 别名]
# 或者: from ratechecker.ratechecker_parameters.ParamsSerializer import is_valid [as 别名]
 def test_is_valid__valid_args(self):
     serializer = ParamsSerializer(data=self.data)
     self.assertTrue(serializer.is_valid())
     self.assertEqual(serializer.data.get('price'), Decimal('240000'))
     self.assertEqual(serializer.data.get('loan_amount'), Decimal('200000'))
     self.assertEqual(serializer.data.get('state'), 'GA')
     self.assertEqual(serializer.data.get('loan_type'), 'JUMBO')
     self.assertEqual(serializer.data.get('minfico'), 700)
     self.assertEqual(serializer.data.get('maxfico'), 800)
     self.assertEqual(serializer.data.get('rate_structure'), 'FIXED')
     self.assertEqual(serializer.data.get('loan_term'), 30)
开发者ID:fna,项目名称:owning-a-home-api,代码行数:13,代码来源:test_views_ratecheckerparameters.py

示例14: test_is_valid__no_args

# 需要导入模块: from ratechecker.ratechecker_parameters import ParamsSerializer [as 别名]
# 或者: from ratechecker.ratechecker_parameters.ParamsSerializer import is_valid [as 别名]
 def test_is_valid__no_args(self):
     serializer = ParamsSerializer(data={})
     self.assertFalse(serializer.is_valid())
     self.assertEqual(len(serializer.errors), 7)
     self.assertEqual(serializer.errors.get('loan_amount'), [u'This field is required.'])
     self.assertEqual(serializer.errors.get('state'), [u'This field is required.'])
     self.assertEqual(serializer.errors.get('loan_type'), [u'This field is required.'])
     self.assertEqual(serializer.errors.get('minfico'), [u'This field is required.'])
     self.assertEqual(serializer.errors.get('maxfico'), [u'This field is required.'])
     self.assertEqual(serializer.errors.get('rate_structure'), [u'This field is required.'])
     self.assertEqual(serializer.errors.get('loan_term'), [u'This field is required.'])
开发者ID:cfpb,项目名称:owning-a-home-api,代码行数:13,代码来源:test_views_ratecheckerparameters.py

示例15: rate_checker_fees

# 需要导入模块: from ratechecker.ratechecker_parameters import ParamsSerializer [as 别名]
# 或者: from ratechecker.ratechecker_parameters.ParamsSerializer import is_valid [as 别名]
def rate_checker_fees(request):
    """ Return available rates in percentage and number of institutions with the corresponding
    rate along with fees data """

    if request.method == 'GET':
        # Clean the parameters, make sure no leading or trailing spaces, transform them to upper cases
        fixed_data = dict(map(lambda (k, v): (k, v.strip().upper()), request.QUERY_PARAMS.iteritems()))
        serializer = ParamsSerializer(data=fixed_data)

        if serializer.is_valid():
            rate_results = get_rates(serializer.data, return_fees=True)
            rate_results['request'] = serializer.data
            return Response(rate_results)
        else:
            return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
开发者ID:fna,项目名称:owning-a-home-api,代码行数:17,代码来源:views.py


注:本文中的ratechecker.ratechecker_parameters.ParamsSerializer.is_valid方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。