Skip to content

Commit

Permalink
(feat) async tests
Browse files Browse the repository at this point in the history
  • Loading branch information
alexeevnick committed Apr 11, 2022
1 parent 5afd1a3 commit b434bd8
Show file tree
Hide file tree
Showing 12 changed files with 103 additions and 120 deletions.
8 changes: 1 addition & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,10 @@ python:
- "3.9"
- "3.8"
- "3.7"
- "3.6"
- "3.5"
matrix:
include:
- python: 3.4
- python: 3.8
dist: xenial
- python: 2.7
before_install:
- pip install -U mock
- pip install -U pytest
# command to install dependencies
install:
- pip install -r requirements.txt && pip install -e .
Expand Down
2 changes: 1 addition & 1 deletion README.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ This product is used for managing payments under [The YooKassa API](https://yook
For usage by those who implemented YooKassa using the API method.

## Requirements
1. Python 2.7 or Python 3.x
1. Python >=3.7
2. pip

## Installation
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Russian | [English](https://github.com/yoomoney/yookassa-sdk-python/blob/master/

## Требования

1. Python 3.x
1. Python >=3.7
2. pip

## Установка
Expand Down
11 changes: 4 additions & 7 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
For usage by those who implemented YooKassa using the API method.
## Requirements
1. Python 2.7 or Python 3.x
1. Python >=3.7
2. pip
## Installation
Expand Down Expand Up @@ -113,17 +113,14 @@
url="https://github.com/yoomoney/yookassa-sdk-python",
package_dir={"": "src"},
packages=find_packages('src'),
install_requires=["requests", "urllib3", "netaddr", "distro", "deprecated"],
install_requires=["httpx", "requests", "urllib3", "netaddr", "distro", "deprecated"],
zip_safe=False,
license="MIT",
classifiers=[
"License :: OSI Approved :: MIT License",
"Programming Language :: Python :: 2.7",
"Programming Language :: Python :: 3.4",
"Programming Language :: Python :: 3.5",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9"
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10"
]
)
10 changes: 5 additions & 5 deletions test/unit/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@
from yookassa.domain.common.request_object import RequestObject


class TestClient(unittest.TestCase):
class TestClient(unittest.IsolatedAsyncioTestCase):

def setUp(self):
Configuration.configure(account_id='test_account_id', secret_key='test_secret_key')
Configuration.agent_framework = Version('YooMoney.Framework', '0.0.1')
Configuration.agent_cms = Version('YooMoney.Cms', '0.0.2')
Configuration.agent_module = Version('YooMoney.Module', '0.0.3')

def test_request(self):
async def test_request(self):
client = ApiClient()
with patch('yookassa.client.ApiClient.request') as request_mock:
request_mock.return_value = {
Expand All @@ -39,14 +39,14 @@ def test_request(self):
'status': 'canceled'
}

client.request(HttpVerb.POST, '/path', RequestObject(), {'header': 'header'})
await client.request(HttpVerb.POST, '/path', RequestObject(), {'header': 'header'})

def test_execute(self):
async def test_execute(self):
client = ApiClient()
with patch('yookassa.client.ApiClient.execute') as request_mock:
res = Response()
res.status_code = 200
res._content = b"{}"
request_mock.return_value = res

client.request(HttpVerb.POST, '/path', RequestObject({"param": "param"}), {'header': 'header'})
await client.request(HttpVerb.POST, '/path', RequestObject({"param": "param"}), {'header': 'header'})
31 changes: 15 additions & 16 deletions test/unit/test_deal.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@
import sys
import unittest

if sys.version_info >= (3, 3):
from unittest.mock import patch
else:
from mock import patch
from unittest.mock import patch

from yookassa.configuration import Configuration
from yookassa.domain.models.amount import Amount
Expand All @@ -14,11 +11,11 @@
from yookassa.deal import Deal


class TestDealFacade(unittest.TestCase):
class TestDealFacade(unittest.IsolatedAsyncioTestCase):
def setUp(self):
Configuration.configure(account_id='test_account_id', secret_key='test_secret_key')

def test_create_deal_with_dict(self):
async def test_create_deal_with_dict(self):
self.maxDiff = None
deal_facade = Deal()
with patch('yookassa.client.ApiClient.request') as request_mock:
Expand All @@ -43,7 +40,7 @@ def test_create_deal_with_dict(self):
"description": "SAFE_DEAL 123554642-2432FF344R",
"test": False
}
deal = deal_facade.create({
deal = await deal_facade.create({
"type": "safe_deal",
"fee_moment": "deal_closed",
"metadata": {
Expand All @@ -56,7 +53,7 @@ def test_create_deal_with_dict(self):
self.assertIsInstance(deal.balance, Amount)
self.assertIsInstance(deal.payout_balance, Amount)

def test_create_deal_with_object(self):
async def test_create_deal_with_object(self):
self.maxDiff = None
deal_facade = Deal()
with patch('yookassa.client.ApiClient.request') as request_mock:
Expand All @@ -81,7 +78,7 @@ def test_create_deal_with_object(self):
"description": "SAFE_DEAL 123554642-2432FF344R",
"test": False
}
deal = deal_facade.create(DealRequest({
deal = await deal_facade.create(DealRequest({
"type": "safe_deal",
"fee_moment": "deal_closed",
"metadata": {
Expand All @@ -94,7 +91,7 @@ def test_create_deal_with_object(self):
self.assertIsInstance(deal.balance, Amount)
self.assertIsInstance(deal.payout_balance, Amount)

def test_deal_info(self):
async def test_deal_info(self):
deal_facade = Deal()
with patch('yookassa.client.ApiClient.request') as request_mock:
request_mock.return_value = {
Expand All @@ -118,13 +115,13 @@ def test_deal_info(self):
"description": "SAFE_DEAL 123554642-2432FF344R",
"test": False
}
deal = deal_facade.find_one('dl-285e5ee7-0022-5000-8000-01516a44b147')
deal = await deal_facade.find_one('dl-285e5ee7-0022-5000-8000-01516a44b147')

self.assertIsInstance(deal, DealResponse)
self.assertIsInstance(deal.balance, Amount)
self.assertIsInstance(deal.payout_balance, Amount)

def test_deal_list(self):
async def test_deal_list(self):
deal_facade = Deal()
with patch('yookassa.client.ApiClient.request') as request_mock:
request_mock.return_value = {
Expand Down Expand Up @@ -154,17 +151,19 @@ def test_deal_list(self):
"type": "list",
"next_cursor": "37a5c87d-3984-51e8-a7f3-8de646d39ec15"
}
deal = deal_facade.list({
deal = await deal_facade.list({
'status': 'closed',
'limit': 1
})

self.assertIsInstance(deal, DealListResponse)
self.assertIsInstance(deal.items, list)

def test_invalid_data(self):
async def test_invalid_data(self):
with self.assertRaises(ValueError):
Deal().find_one('')
deal = Deal()
await deal.find_one('')

with self.assertRaises(TypeError):
Deal().create('invalid params')
deal = Deal()
await deal.create('invalid params')
53 changes: 27 additions & 26 deletions test/unit/test_payment_facade.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@
import sys
import unittest

if sys.version_info >= (3, 3):
from unittest.mock import patch
else:
from mock import patch
from unittest.mock import patch

from yookassa.configuration import Configuration
from yookassa.domain.models.amount import Amount
Expand All @@ -17,11 +14,11 @@
from yookassa.payment import Payment


class TestPaymentFacade(unittest.TestCase):
class TestPaymentFacade(unittest.IsolatedAsyncioTestCase):
def setUp(self):
Configuration.configure(account_id='test_account_id', secret_key='test_secret_key')

def test_create_payment_with_dict(self):
async def test_create_payment_with_dict(self):
self.maxDiff = None
payment_facade = Payment()
with patch('yookassa.client.ApiClient.request') as request_mock:
Expand All @@ -35,7 +32,7 @@ def test_create_payment_with_dict(self):
'recipient': {'account_id': '156833', 'gateway_id': '468284'},
'status': 'waiting_for_capture'
}
payment = payment_facade.create({
payment = await payment_facade.create({
"amount": {
"value": "1.00",
"currency": "RUB"
Expand Down Expand Up @@ -74,7 +71,7 @@ def test_create_payment_with_dict(self):
self.assertIsInstance(payment.amount, Amount)
self.assertIsInstance(payment.payment_method, PaymentDataBankCard)

def test_create_payment_with_object(self):
async def test_create_payment_with_object(self):
self.maxDiff = None
payment_facade = Payment()
with patch('yookassa.client.ApiClient.request') as request_mock:
Expand All @@ -88,7 +85,7 @@ def test_create_payment_with_object(self):
'recipient': {'account_id': '156833', 'gateway_id': '468284'},
'status': 'waiting_for_capture'
}
payment = payment_facade.create(PaymentRequest({
payment = await payment_facade.create(PaymentRequest({
"amount": {
"value": "1.00",
"currency": "RUB"
Expand Down Expand Up @@ -127,7 +124,7 @@ def test_create_payment_with_object(self):
self.assertIsInstance(payment.amount, Amount)
self.assertIsInstance(payment.payment_method, PaymentDataBankCard)

def test_create_capture_with_dict(self):
async def test_create_capture_with_dict(self):
payment_facade = Payment()
with patch('yookassa.client.ApiClient.request') as request_mock:
request_mock.return_value = {
Expand All @@ -141,7 +138,7 @@ def test_create_capture_with_dict(self):
'status': 'waiting_for_capture'
}

payment = payment_facade.capture('21b23b5b-000f-5061-a000-0674e49a8c10', {
payment = await payment_facade.capture('21b23b5b-000f-5061-a000-0674e49a8c10', {
"amount": {
"value": "1.00",
"currency": "RUB"
Expand Down Expand Up @@ -180,7 +177,7 @@ def test_create_capture_with_dict(self):
self.assertIsInstance(payment.amount, Amount)
self.assertIsInstance(payment.payment_method, PaymentDataBankCard)

def test_create_capture_with_object(self):
async def test_create_capture_with_object(self):
payment_facade = Payment()
with patch('yookassa.client.ApiClient.request') as request_mock:
request_mock.return_value = {
Expand All @@ -194,7 +191,7 @@ def test_create_capture_with_object(self):
'status': 'waiting_for_capture'
}

payment = payment_facade.capture('21b23b5b-000f-5061-a000-0674e49a8c10', CapturePaymentRequest({
payment = await payment_facade.capture('21b23b5b-000f-5061-a000-0674e49a8c10', CapturePaymentRequest({
"amount": {
"value": "1.00",
"currency": "RUB"
Expand Down Expand Up @@ -233,7 +230,7 @@ def test_create_capture_with_object(self):
self.assertIsInstance(payment.amount, Amount)
self.assertIsInstance(payment.payment_method, PaymentDataBankCard)

def test_create_capture(self):
async def test_create_capture(self):
payment_facade = Payment()
with patch('yookassa.client.ApiClient.request') as request_mock:
request_mock.return_value = {
Expand All @@ -247,13 +244,13 @@ def test_create_capture(self):
'status': 'waiting_for_capture'
}

payment = payment_facade.capture('21b23b5b-000f-5061-a000-0674e49a8c10')
payment = await payment_facade.capture('21b23b5b-000f-5061-a000-0674e49a8c10')

self.assertIsInstance(payment, PaymentResponse)
self.assertIsInstance(payment.amount, Amount)
self.assertIsInstance(payment.payment_method, PaymentDataBankCard)

def test_payment_info(self):
async def test_payment_info(self):
payment_facade = Payment()
with patch('yookassa.client.ApiClient.request') as request_mock:
request_mock.return_value = {
Expand All @@ -266,13 +263,13 @@ def test_payment_info(self):
'recipient': {'account_id': '156833', 'gateway_id': '468284'},
'status': 'waiting_for_capture'
}
payment = payment_facade.find_one('21b23b5b-000f-5061-a000-0674e49a8c10')
payment = await payment_facade.find_one('21b23b5b-000f-5061-a000-0674e49a8c10')

self.assertIsInstance(payment, PaymentResponse)
self.assertIsInstance(payment.amount, Amount)
self.assertIsInstance(payment.payment_method, PaymentDataBankCard)

def test_payment_cancel(self):
async def test_payment_cancel(self):
payment_facade = Payment()
with patch('yookassa.client.ApiClient.request') as request_mock:
request_mock.return_value = {
Expand All @@ -285,13 +282,13 @@ def test_payment_cancel(self):
'recipient': {'account_id': '156833', 'gateway_id': '468284'},
'status': 'canceled'
}
payment = payment_facade.cancel('21b23b5b-000f-5061-a000-0674e49a8c10')
payment = await payment_facade.cancel('21b23b5b-000f-5061-a000-0674e49a8c10')

self.assertIsInstance(payment, PaymentResponse)
self.assertIsInstance(payment.amount, Amount)
self.assertIsInstance(payment.payment_method, PaymentDataBankCard)

def test_payment_list(self):
async def test_payment_list(self):
payment_facade = Payment()
with patch('yookassa.client.ApiClient.request') as request_mock:
request_mock.return_value = {
Expand Down Expand Up @@ -322,23 +319,27 @@ def test_payment_list(self):
],
'next_page': '2018-08-02 08:24:01.180;48539871',
'type': 'list'}
payment = payment_facade.list({
payment = await payment_facade.list({
'status': 'succeeded',
'limit': 1
})

self.assertIsInstance(payment, PaymentListResponse)
self.assertIsInstance(payment.items, list)

def test_invalid_data(self):
async def test_invalid_data(self):
with self.assertRaises(ValueError):
Payment().find_one('')
payment = Payment()
await payment.find_one('')

with self.assertRaises(TypeError):
Payment().create('invalid params')
payment = Payment()
await payment.create('invalid params')

with self.assertRaises(ValueError):
Payment().capture(111)
payment = Payment()
await payment.capture(111)

with self.assertRaises(ValueError):
Payment().cancel('')
payment = Payment()
await payment.cancel('')
Loading

0 comments on commit b434bd8

Please sign in to comment.