コード例 #1
0
ファイル: test_card.py プロジェクト: sarkis89/stoq
    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))
コード例 #2
0
 def create_model(self, store):
     provider = CreditProvider.get_card_providers(self.store).order_by(
         CreditProvider.short_name).first()
     real_model = CardOperationCost(provider=provider,
                                    device=self.device,
                                    store=self.store)
     return _TemporaryOperationCost(real_model)
コード例 #3
0
 def create_operation_cost(self, device=None, provider=None, card_type=None,
                           start=1, end=1):
     from stoqlib.domain.payment.card import CardOperationCost
     return CardOperationCost(store=self.store,
                              device=device or self.create_card_device(),
                              provider=provider or self.create_credit_provider(),
                              card_type=card_type or 0,
                              installment_start=start,
                              installment_end=end)
コード例 #4
0
ファイル: test_card.py プロジェクト: stoq/stoq
    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))
コード例 #5
0
    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'))
コード例 #6
0
    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'))
コード例 #7
0
 def create_model(self, store):
     provider = CreditProvider.get_card_providers(store).any()
     real_model = CardOperationCost(provider=provider,
                                    device=self.device,
                                    store=self.store)
     return _TemporaryOperationCost(real_model)