本文整理汇总了Python中ratechecker.ratechecker_parameters.ParamsSerializer类的典型用法代码示例。如果您正苦于以下问题:Python ParamsSerializer类的具体用法?Python ParamsSerializer怎么用?Python ParamsSerializer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ParamsSerializer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_is_valid__maxfico_smaller
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)
示例2: rate_checker
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)
示例3: test_is_valid__ltv__without_ltv
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'))
示例4: test_is_valid__lock_non_default
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)
示例5: test_is_valid__ficos_negative
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)
示例6: test_is_valid__property_type_invalid
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.']
)
示例7: test_is_valid__state_invalid
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.']
)
示例8: validate_scenario
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)
示例9: test_is_valid__loan_amount_none
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.']
)
示例10: test_is_valid__loan_amount_empty
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.']
)
示例11: test_is_valid__loan_purpose_invalid
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.']
)
示例12: test_is_valid_no_price_or_ltv
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']
)
示例13: test_is_valid__valid_args
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)
示例14: test_is_valid__no_args
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.'])
示例15: rate_checker_fees
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)