Skip to content

Commit

Permalink
Merge pull request #12 from lucasrcezimbra/develop
Browse files Browse the repository at this point in the history
0.0.6
  • Loading branch information
lucasrcezimbra authored Oct 25, 2022
2 parents b3a2b9f + 671d3e8 commit 1a7fe7b
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 23 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# Changelog


## 0.0.6 (2022-10-25)
- Improve `Inter.__init__`
- Fix tests


## 0.0.5 (2022-10-24)
- Add fake classes for testing

Expand Down
13 changes: 8 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,15 @@ pip install bancointer
from inter import Inter


inter = Inter.from_credentials(
"YOUR_CLIENT_ID",
"YOUR_CLIENT_SECRET"
'/path/to/certificado.crt',
'/path/to/chave.key',
inter = Inter(
client_id="YOUR_CLIENT_ID",
client_secret="YOUR_CLIENT_SECRET"
cert_path='/path/to/certificado.crt',
key_path='/path/to/chave.key',
)

# get September/2022 statements
inter.get_statements(date(2022, 9, 1), date(2022, 9, 30))
```

#### Testing
Expand Down
2 changes: 1 addition & 1 deletion inter/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@

__author__ = """Lucas Rangel Cezimbra"""
__email__ = '[email protected]'
__version__ = '0.0.5'
__version__ = '0.0.6'
36 changes: 30 additions & 6 deletions inter/_inter.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,36 @@


class Inter:
def __init__(self, client):
self._client = client

@classmethod
def from_credentials(cls, client_id, client_secret, cert_path, key_path):
return cls(client=Client(client_id, client_secret, cert_path, key_path))
"""
Inicializa utilizando as credenciais ou um :class:`Client`.
:param client_id: Client ID
:type client_id: str
:param client_secret: Client Secret
:type client_secret: str
:param cert_path: Caminho do arquivo de certificado
:type cert_path: str
:param key_path: Caminho do arquivo de chave
:type key_path: str
:param client: Ao invés de inicializar com as credenciais é possivel
passar um :class:`Client` já inicializado. Útil para testes.
:type client: Client
"""
def __init__(
self,
*,
client_id=None,
client_secret=None,
cert_path=None,
key_path=None,
client=None
):
assert client or (client_id and client_secret and cert_path and key_path)
self._client = client or Client(client_id, client_secret, cert_path, key_path)

def get_balance(self, date=None):
"""
Expand Down
4 changes: 2 additions & 2 deletions inter/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def get_statements(self, start_date, end_date):


class InterFake(Inter):
def __init__(self):
def __init__(self, *args, **kwargs):
self.balance = faker.pydecimal(right_digits=2)

def get_balance(self, date=None):
Expand Down Expand Up @@ -85,7 +85,7 @@ def get_statement(self, start_date, end_date):
>>> inter = InterFake()
>>>
>>> operation = Operation(
... date=date.today(),
... date=date(2022, 10, 24),
... description='Descrição da Operação',
... title='Pagamento efetuado',
... type=Operation.PIX,
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name="bancointer"
version = "0.0.5"
version = "0.0.6"
description = "Client to consume Banco Inter APIs"
readme = "README.md"
requires-python = ">=3.7"
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 0.0.5
current_version = 0.0.6
commit = True
tag = True

Expand Down
19 changes: 12 additions & 7 deletions tests/test_inter.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,22 @@
def test_init():
client = ClientFake()

inter = Inter(client)
inter = Inter(client=client)

assert inter._client == client


def test_from_credentials(faker, mocker):
def test_init_from_credentials(faker, mocker):
client_mock = mocker.patch('inter._inter.Client', autospec=True)
client_id, client_secret = faker.pystr(), faker.pystr()
cert_path, key_path = faker.file_path(), faker.file_path()

inter = Inter.from_credentials(client_id, client_secret, cert_path, key_path)
inter = Inter(
client_id=client_id,
client_secret=client_secret,
cert_path=cert_path,
key_path=key_path,
)

assert isinstance(inter._client, Client)
client_mock.assert_called_once_with(client_id, client_secret, cert_path, key_path)
Expand All @@ -30,7 +35,7 @@ def test_get_balance(faker, mocker):
client = ClientFake()
balance_data = client.balance

inter = Inter(client)
inter = Inter(client=client)

assert inter.get_balance() == Decimal(str(balance_data['disponivel']))

Expand All @@ -40,7 +45,7 @@ def test_get_balance_with_date(faker, mocker, balance_data):
get_balance_spy = mocker.spy(client, 'get_balance')
date = faker.past_date()

Inter(client).get_balance(date)
Inter(client=client).get_balance(date)

get_balance_spy.assert_called_once_with(date)

Expand All @@ -49,7 +54,7 @@ def test_get_statement(faker, mocker, statements_data):
client_mock = mocker.MagicMock(spec=Client)
start_date, end_date = faker.past_date(), faker.past_date()

Inter(client_mock).get_statement(start_date, end_date)
Inter(client=client_mock).get_statement(start_date, end_date)

client_mock.get_statements.assert_called_once_with(start_date, end_date)

Expand All @@ -59,7 +64,7 @@ def test_get_statement_result(faker, mocker):
client.statements['transacoes'][0]['tipoOperacao'] = 'C'
statements_data = client.statements

statement = Inter(client).get_statement(faker.past_date(), faker.past_date())
statement = Inter(client=client).get_statement(faker.past_date(), faker.past_date())

assert isinstance(statement, list)
operation, data = statement[0], statements_data['transacoes'][0]
Expand Down

0 comments on commit 1a7fe7b

Please sign in to comment.