Example #1
0
class PersonWrapperTestCase(LocalImopayTestCase):
    def setUp(self):
        self.client = ImopayWrapper().person

    def test_model(self):
        self.assertEqual(self.client.model, Person)

    def test_action(self):
        self.assertEqual(self.client.action, "persons")

    def test_search(self):
        cpf = "foo"

        expected_data = {"cpf": cpf}

        expected_url = self.client._construct_url(action=self.client.action,
                                                  subaction="search")

        with patch("imopay_wrapper.wrapper.base.BaseImopayWrapper._post"
                   ) as mocked_post:
            self.client.search(cpf)

        mocked_post.assert_called_once_with(expected_url, expected_data)
Example #2
0
class CompanyWrapperTestCase(LocalImopayTestCase):
    def setUp(self):
        self.client = ImopayWrapper().company

    def test_model(self):
        self.assertEqual(self.client.model, Company)

    def test_action(self):
        self.assertEqual(self.client.action, "companies")

    def test_search(self):
        cnpj = "foo"

        expected_data = {"cnpj": cnpj}

        expected_url = self.client._construct_url(action=self.client.action,
                                                  subaction="search")

        with patch("imopay_wrapper.wrapper.base.BaseImopayWrapper._post"
                   ) as mocked_post:
            self.client.search(cnpj)

        mocked_post.assert_called_once_with(expected_url, expected_data)
Example #3
0
class AddressWrapperTestCase(LocalImopayTestCase):
    def setUp(self):
        self.client = ImopayWrapper().address

    def test_mixins(self):
        """
        Dado:
            - um client ImopayWrapper().address
        Quando:
            - N/A
        Então:
            - client deve ser uma instância de
                CreateMixin, RetrieveMixin, DestroyMixin, GetByDocumentMixin
        """
        mixins = (CreateMixin, RetrieveMixin, GetByDocumentMixin)
        for mixin in mixins:
            self.assertIsInstance(self.client, mixin)

    def test_model(self):
        self.assertEqual(self.client.model, Address)

    def test_action(self):
        self.assertEqual(self.client.action, "addresses")

    def test_create(self):
        with patch(
                "imopay_wrapper.wrapper.address.AddressWrapper.model",
                new_callable=PropertyMock,
        ) as mocked_model, patch(
                "imopay_wrapper.wrapper.address.AddressWrapper.action",
                new_callable=PropertyMock,
        ) as mocked_action, patch(
                "imopay_wrapper.wrapper.address.AddressWrapper._post"
        ) as mocked_post:
            self.client.create({})

        mocked_model.assert_called_once()

        mocked_action.assert_called_once()

        mocked_post.assert_called_once_with(
            self.client._construct_url(action=mocked_action.return_value,
                                       subaction="create_by_name_and_uf"),
            mocked_model.return_value.return_value.to_dict.return_value,
        )

    def test_update(self):
        with patch(
                "imopay_wrapper.wrapper.address.AddressWrapper.model",
                new_callable=PropertyMock,
        ) as mocked_model, patch(
                "imopay_wrapper.wrapper.address.AddressWrapper.action",
                new_callable=PropertyMock,
        ) as mocked_action, patch(
                "imopay_wrapper.wrapper.address.AddressWrapper._patch"
        ) as mocked_post:
            self.client.update("foo", {})

        mocked_model.assert_called_once()

        mocked_action.assert_called_once()

        mocked_post.assert_called_once_with(
            self.client._construct_url(
                action=mocked_action.return_value,
                subaction="update_by_name_and_uf",
                identifier="foo",
            ),
            mocked_model.return_value.return_value.to_dict.return_value,
        )

    def test_get_by_document(self):
        with patch(
                "imopay_wrapper.wrapper.address.AddressWrapper.action",
                new_callable=PropertyMock,
        ) as mocked_action, patch(
                "imopay_wrapper.wrapper.address.AddressWrapper._post"
        ) as mocked_post:
            self.client.get_by_document("foo")

        mocked_action.assert_called_once()

        expected_data = {"cpf_cnpj": "foo"}

        mocked_post.assert_called_once_with(
            self.client._construct_url(action=mocked_action.return_value,
                                       subaction="get_by_document"),
            expected_data,
        )
Example #4
0
class TransactionWrapperTestCase(LocalImopayTestCase):
    def setUp(self):
        self.client = ImopayWrapper().transaction

    def test_action(self):
        self.assertEqual(self.client.action, "transactions")

    def test_create_invoice(self):
        expected_data = {
            "payer": "1",
            "receiver": "2",
            "reference_id": "3",
            "amount": 4,
            "description": "5",
            "payment_method": {
                "expiration_date": today(),
                "limit_date": tomorrow(),
                "configurations": {
                    "fine": {
                        "value": 1,
                        "charge_type": BaseConfiguration.FIXED,
                    },
                    "interest": {
                        "value": 1,
                        "charge_type": BaseConfiguration.DAILY_FIXED,
                    },
                    "discounts": [{
                        "value": 1,
                        "charge_type": BaseConfiguration.FIXED,
                        "date": today(),
                    }],
                },
            },
        }

        expected_url = self.client._construct_url(
            action=self.client.action, subaction="create_invoice_transaction")

        with patch("imopay_wrapper.wrapper.base.BaseImopayWrapper._post"
                   ) as mocked_post:
            self.client.create_invoice({
                "payer": "1",
                "receiver": "2",
                "reference_id": "3",
                "amount": "4",
                "description": "5",
                "payment_method": {
                    "expiration_date": today(),
                    "limit_date": tomorrow(),
                    "configurations": {
                        "fine": {
                            "value": 1,
                            "charge_type": BaseConfiguration.FIXED,
                        },
                        "interest": {
                            "value": 1,
                            "charge_type": BaseConfiguration.DAILY_FIXED,
                        },
                        "discounts": [{
                            "value": 1,
                            "charge_type": BaseConfiguration.FIXED,
                            "date": today(),
                        }],
                    },
                },
            })

        mocked_post.assert_called_once_with(expected_url, expected_data)