Skip to content

Commit

Permalink
Merge pull request #11 from leynier/main
Browse files Browse the repository at this point in the history
Proposal for version 0.2.0
  • Loading branch information
Carlos Lugones committed Sep 17, 2021
2 parents 4f4c9e4 + 266eda4 commit ec097c9
Show file tree
Hide file tree
Showing 9 changed files with 81 additions and 39 deletions.
7 changes: 6 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,10 @@
"markdownlint.config": {
"MD024": false,
"MD041": false
}
},
"python.testing.pytestArgs": [
"tests"
],
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true
}
25 changes: 20 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,33 @@
## 0.1.0 (2021-09-05)
## 0.2.0 (2021-09-15)

### Fix

- change UUID by str in remote_id of transaction model
- use python-dotenv for obtain authentication info from environment
- add aclose method for async with and use run_until_complete
- remove user_id and paid_by_user_id properties from Transaction
- add type hint in __enter__ method of QvaPayClient class

### Perf
### Feat

- remove pydantic dependency
- add cache to GitHub Actions
- add context manager; updated README

## v0.1.0 (2021-09-05)

### Feat

- add post init validation to QvaPayAuth
- add not required status message to QvaPayError
- improve implementation

### Fix

- change UUID by str in remote_id of transaction model
- use python-dotenv for obtain authentication info from environment

### Perf

- remove pydantic dependency

## v0.0.3 (2021-08-30)

### Perf
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,11 @@ You can also read the **QvaPay API** documentation: [qvapay.com/docs](https://qv

## Migration guide

### 0.1.0 -> 0.2.0

- `user_id` of `Transaction` model was removed
- `paid_by_user_id` of `Transaction` model was removed

### 0.0.3 -> 0.1.0

- `from qvapay.v1 import *` instead of `from qvapay import *`
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "qvapay"
version = "0.1.0"
version = "0.2.0"
description = "Python SDK for the QvaPay API"
authors = [
"Carlos Lugones <contact@lugodev.com>",
Expand Down
2 changes: 1 addition & 1 deletion qvapay/v1/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
from .models.transaction import Transaction # noqa: F401
from .models.transaction_detail import TransactionDetail # noqa: F401

__version__ = "0.1.0"
__version__ = "0.2.0"
__author__ = "Carlos Lugones <contact@lugodev.com>"
__all__ = []
29 changes: 14 additions & 15 deletions qvapay/v1/client.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import asyncio

from dataclasses import dataclass, field
from types import TracebackType
from typing import Optional, Type, Union
Expand Down Expand Up @@ -189,15 +188,19 @@ def close(self):
if self.sync_client:
self.sync_client.close()
if self.async_client:
try:
# Schedule close underline resources and
# wait
asyncio.create_task(self.async_client.aclose()).result()
except RuntimeError:
# Skip error when no use async loops
pass

def __enter__(self) -> None:
asyncio.get_event_loop().run_until_complete(self.async_client.aclose())

async def aclose(self):
if self.sync_client:
self.sync_client.close()
if self.async_client:
await self.async_client.aclose()

def __enter__(self) -> "QvaPayClient":
return self

async def __aenter__(self) -> "QvaPayClient":
# Just syntactic sugar ;)
return self

def __exit__(
Expand All @@ -208,14 +211,10 @@ def __exit__(
) -> None:
self.close()

async def __aenter__(self) -> "QvaPayClient":
# Just syntactic sugar ;)
return self

async def __aexit__(
self,
exc_type: Optional[Type[BaseException]],
exc_val: Optional[BaseException],
exc_tb: Optional[TracebackType],
) -> None:
self.close()
await self.aclose()
4 changes: 0 additions & 4 deletions qvapay/v1/models/transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,22 @@ class Transaction:
"""

id: UUID # alias: uuid
user_id: int
app_id: int
amount: float
description: str
remote_id: str
status: str
paid_by_user_id: int
created_at: datetime
updated_at: datetime
signed: Optional[int]

def __post_init__(self):
self.id = UUID(str(self.id))
self.user_id = int(str(self.user_id))
self.app_id = int(str(self.app_id))
self.amount = float(str(self.amount))
self.description = str(self.description)
self.remote_id = str(self.remote_id)
self.status = str(self.status)
self.paid_by_user_id = int(str(self.paid_by_user_id))
self.created_at = parse(str(self.created_at))
self.updated_at = parse(str(self.updated_at))
self.signed = int(str(self.signed)) if self.signed is not None else None
Expand Down
2 changes: 0 additions & 2 deletions qvapay/v1/models/transaction_detail.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,11 @@ def from_json(json: Any) -> "TransactionDetail":
base = Transaction.from_json(json)
return TransactionDetail(
id=base.id,
user_id=base.user_id,
app_id=base.app_id,
amount=base.amount,
description=base.description,
remote_id=base.remote_id,
status=base.status,
paid_by_user_id=base.paid_by_user_id,
created_at=base.created_at,
updated_at=base.updated_at,
signed=base.signed,
Expand Down
44 changes: 34 additions & 10 deletions tests/test_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,30 @@ def test_error():
assert True


def test_auth_error_without_app_id():
try:
QvaPayClient.from_auth(QvaPayAuth(qvapay_app_secret=""))
assert False
except QvaPayError:
assert True


def test_auth_error_without_app_secret():
try:
QvaPayClient.from_auth(QvaPayAuth(qvapay_app_id=""))
assert False
except QvaPayError:
assert True


def test_auth_erro_without_app_id_and_secret():
try:
QvaPayClient.from_auth(QvaPayAuth(qvapay_app_id="", qvapay_app_secret=""))
assert False
except QvaPayError:
assert True


def test_get_info():
client = QvaPayClient.from_auth(QvaPayAuth(), timeout=Timeout(TIMEOUT))
client.get_info()
Expand All @@ -33,11 +57,11 @@ def test_create_invoice():


def test_get_transactions():
client = QvaPayClient.from_auth(QvaPayAuth(), timeout=Timeout(TIMEOUT))
result = client.get_transactions()
if result.data:
item = result.data[0]
client.get_transaction(item.id)
with QvaPayClient.from_auth(QvaPayAuth(), timeout=Timeout(TIMEOUT)) as client:
result = client.get_transactions()
if result.data:
item = result.data[0]
client.get_transaction(item.id)


@pytest_mark.asyncio
Expand Down Expand Up @@ -70,8 +94,8 @@ async def test_create_invoice_async():

@pytest_mark.asyncio
async def test_get_transactions_async():
client = QvaPayClient.from_auth(QvaPayAuth(), timeout=Timeout(TIMEOUT))
result = await client.get_transactions_async()
if result.data:
item = result.data[0]
await client.get_transaction_async(item.id)
async with QvaPayClient.from_auth(QvaPayAuth(), timeout=Timeout(TIMEOUT)) as client:
result = await client.get_transactions_async()
if result.data:
item = result.data[0]
await client.get_transaction_async(item.id)

0 comments on commit ec097c9

Please sign in to comment.