Example #1
0
 def test_convert_currency_float_value_to_cents_none_input(self):
     """
     Dado:
         - um valor None
     Quando:
         - for chamado convert_currency_float_value_to_cents(value)
     Então:
         - deve ser lançado um FieldError
     """
     value = None
     with self.assertRaises(FieldError):
         convert_currency_float_value_to_cents(value)
Example #2
0
    def init_custom_fields(
        self,
        card=None,
        type="card",
        currency="BRL",
        **kwargs,
    ):
        setattr(self, "type", type)
        setattr(self, "currency", currency)

        kwargs["amount"] = convert_currency_float_value_to_cents(
            kwargs["amount"])
        """
        Ver documentação do :meth:`.from_dict_or_instance`.

        Precisamos pegar o atributo `id` para identificar o tipo.
        """

        token_for_card = Token.from_dict_or_instance(card, allow_empty=True)

        if token_for_card.id is not None:
            card_type = Source.CARD_NOT_PRESENT_TYPE
        else:
            try:
                token_for_card = Token.from_dict_or_instance(card)
                card_type = Source.CARD_PRESENT_TYPE
            except ValidationError as e:
                raise ValidationError(
                    self,
                    f"Tipo do source não identificado! "
                    f"Utilize um dos tipos {Source.SOURCE_TYPES}",
                ) from e

        setattr(self, "card", token_for_card)
        setattr(self, "card_type", card_type)
Example #3
0
 def test_convert_currency_float_value_to_cents_str_with_float_input(self):
     """
     Dado:
         - um valor "91.23"
     Quando:
         - for chamado convert_currency_float_value_to_cents(value)
     Então:
         - o resultado deve ser 9123
     """
     value = "91.23"
     expected = 9123
     result = convert_currency_float_value_to_cents(value)
     self.assertEqual(expected, result)
Example #4
0
 def test_convert_currency_float_value_to_cents_int_input(self):
     """
     Dado:
         - um valor 1234
     Quando:
         - for chamado convert_currency_float_value_to_cents(value)
     Então:
         - o resultado deve ser 1234
     """
     value = 1234
     expected = 1234
     result = convert_currency_float_value_to_cents(value)
     self.assertEqual(expected, result)
Example #5
0
 def test_convert_currency_float_value_to_cents_float_input_2(self):
     """
     Dado:
         - um valor 653.55
     Quando:
         - for chamado convert_currency_float_value_to_cents(value)
     Então:
         - o resultado deve ser 65355
     """
     value = 653.55
     expected = 65355
     result = convert_currency_float_value_to_cents(value)
     self.assertEqual(expected, result)
Example #6
0
 def test_convert_currency_float_value_to_cents_float_input_1(self):
     """
     Dado:
         - um valor 56.7
     Quando:
         - for chamado convert_currency_float_value_to_cents(value)
     Então:
         - o resultado deve ser 5670
     """
     value = 56.7
     expected = 5670
     result = convert_currency_float_value_to_cents(value)
     self.assertEqual(expected, result)
Example #7
0
    def init_custom_fields(
        self,
        amount=None,
        currency="BRL",
        history=None,
        id=None,
        payment_method=None,
        payment_type=None,
        point_of_sale=None,
        source=None,
        **kwargs,
    ):
        """
        Initialize :attr:`payment_method` as :class:`.Card` or :class:`.Invoice`
        based on data.

        Initialize :attr:`point_of_sale` as :class:`.PointOfSale`.

        Initialize :attr:`history` as list of :class:`.History`.

        Args:
            currency (str): default currency is 'BRL'.
                So users may not need to pass currency!
            history (dict or :class:`.History` or list of either): history data. May be a list of dict or list of :class:`.History`  # noqa
            payment_method (dict or :class:`.Card` or :class:`.Invoice`): payment method data  # noqa
            payment_type (str): value for payment type
            point_of_sale (dict or :class:`.PointOfSale`): point of sale data
            **kwargs: kwargs
        """
        setattr(self, "currency", currency)

        if payment_type not in Transaction.PAYMENT_TYPES:
            raise ValidationError(
                self,
                f"payment_type precisa ser um valor "
                f"do conjunto {Transaction.PAYMENT_TYPES}",
            )

        if amount is not None:
            amount = convert_currency_float_value_to_cents(amount)
            setattr(self, "amount", amount)

        if id is not None and payment_type == Transaction.CARD_TYPE:
            setattr(
                self,
                "payment_method",
                Card.from_dict_or_instance(payment_method,
                                           allow_empty=self._allow_empty),
            )
        elif id is None and payment_type == Transaction.CARD_TYPE:
            setattr(
                self,
                "source",
                Source.from_dict_or_instance(source,
                                             allow_empty=self._allow_empty),
            )
        elif payment_type == Transaction.BOLETO_TYPE:
            setattr(
                self,
                "payment_method",
                Invoice.from_dict_or_instance(payment_method,
                                              allow_empty=self._allow_empty),
            )
        else:
            raise ValidationError(self,
                                  "Alguma coisa muito errada aconteceu!!")

        setattr(self, "payment_type", payment_type)

        setattr(
            self,
            "point_of_sale",
            PointOfSale.from_dict_or_instance(point_of_sale, allow_empty=True),
        )

        if isinstance(history, list):
            setattr(
                self,
                "history",
                [
                    History.from_dict_or_instance(item, allow_empty=True)
                    for item in history
                ],
            )
        else:
            setattr(
                self,
                "history",
                [History.from_dict_or_instance(history, allow_empty=True)],
            )
Example #8
0
 def test_convert_currency_float_value_to_cents_int_input(self):
     value = 1234
     expected = 1234
     result = convert_currency_float_value_to_cents(value)
     self.assertEqual(expected, result)
Example #9
0
 def test_convert_currency_float_value_to_cents_str_with_float_input(self):
     value = "91.23"
     expected = 9123
     result = convert_currency_float_value_to_cents(value)
     self.assertEqual(expected, result)
Example #10
0
 def test_convert_currency_float_value_to_cents_float_input(self):
     value = 56.78123123123123123
     expected = 5678
     result = convert_currency_float_value_to_cents(value)
     self.assertEqual(expected, result)