def test_validate_installment_range(self): provider = self.create_credit_provider() device = self.create_card_device() # there is no other operation cost yet. Complete range should be valid self.assertTrue( CardOperationCost.validate_installment_range( device, provider, CreditCardData.TYPE_CREDIT_INSTALLMENTS_STORE, 1, 12, self.store)) # Create one cost cost = self.create_operation_cost( start=3, end=5, card_type=CreditCardData.TYPE_CREDIT_INSTALLMENTS_STORE, provider=provider, device=device) # Test a few valid ranges: valid_ranges = [(1, 1), (1, 2), (2, 2), (6, 6), (6, 10), (8, 10)] for start, end in valid_ranges: self.assertTrue( CardOperationCost.validate_installment_range( device, provider, CreditCardData.TYPE_CREDIT_INSTALLMENTS_STORE, start, end, self.store)) # now test a few invalid ranges: invalid_ranges = [(1, 3), (1, 4), (1, 12), (2, 3), (2, 6), (3, 3), (4, 4), (4, 6)] for start, end in invalid_ranges: self.assertFalse( CardOperationCost.validate_installment_range( device, provider, CreditCardData.TYPE_CREDIT_INSTALLMENTS_STORE, start, end, self.store)) # Also test the ignore parameter. All values above should be valid for start, end in invalid_ranges + valid_ranges: self.assertTrue( CardOperationCost.validate_installment_range( device, provider, CreditCardData.TYPE_CREDIT_INSTALLMENTS_STORE, start, end, self.store, ignore=cost.id))
def test_validate_installment_range(self): provider = self.create_credit_provider() device = self.create_card_device() # there is no other operation cost yet. Complete range should be valid self.assertTrue( CardOperationCost.validate_installment_range( device, provider, CreditCardData.TYPE_CREDIT_INSTALLMENTS_STORE, 1, 12, self.store)) # Create one cost cost = self.create_operation_cost(start=3, end=5, card_type=CreditCardData.TYPE_CREDIT_INSTALLMENTS_STORE, provider=provider, device=device) # Test a few valid ranges: valid_ranges = [(1, 1), (1, 2), (2, 2), (6, 6), (6, 10), (8, 10)] for start, end in valid_ranges: self.assertTrue( CardOperationCost.validate_installment_range( device, provider, CreditCardData.TYPE_CREDIT_INSTALLMENTS_STORE, start, end, self.store)) # now test a few invalid ranges: invalid_ranges = [(1, 3), (1, 4), (1, 12), (2, 3), (2, 6), (3, 3), (4, 4), (4, 6)] for start, end in invalid_ranges: self.assertFalse( CardOperationCost.validate_installment_range( device, provider, CreditCardData.TYPE_CREDIT_INSTALLMENTS_STORE, start, end, self.store)) # Also test the ignore parameter. All values above should be valid for start, end in invalid_ranges + valid_ranges: self.assertTrue( CardOperationCost.validate_installment_range( device, provider, CreditCardData.TYPE_CREDIT_INSTALLMENTS_STORE, start, end, self.store, ignore=cost.id))
def _validate_range(self, start, end): if ValueUnset in [start, end]: return if start > end: return ValidationError(_('Installments start should be lower ' 'or equal installments end')) if not CardOperationCost.validate_installment_range(device=self.model.device, provider=self.model.provider, card_type=self.model.card_type, start=start, end=end, ignore=self.model.real_model.id, store=self.store): return ValidationError(_('The installments range is conflicting ' 'with another configuration'))