Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
GLEF1X committed Apr 26, 2021
1 parent 700b66a commit bf86cf0
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 33 deletions.
5 changes: 3 additions & 2 deletions glQiwiApi/core/basic_requests_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
from itertools import repeat
from typing import (
Dict,
AsyncGenerator
AsyncGenerator,
NoReturn
)
from typing import Optional, List, Union

Expand Down Expand Up @@ -32,7 +33,7 @@ class HttpXParser(AbstractParser):

_sleep_time = 2

def __init__(self):
def __init__(self) -> NoReturn:
super(HttpXParser, self).__init__()
self.base_headers = {
'User-Agent': USER_AGENT,
Expand Down
2 changes: 1 addition & 1 deletion glQiwiApi/core/web_hooks/filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def or_(func1: CF, func2: CF, event: Any) -> bool:
class Filter:
"""
Base Filter object, callback container
Same approach used in https://github.com/uwinx/garnet
"""

__name__: str
Expand Down
2 changes: 1 addition & 1 deletion glQiwiApi/qiwi/qiwi_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from aiohttp import web, ClientSession
from aiohttp.abc import AbstractAccessLogger

import glQiwiApi.utils.basics as api_helper
from glQiwiApi.core import (
AbstractPaymentWrapper,
RequestManager,
Expand Down Expand Up @@ -42,6 +41,7 @@
)
from glQiwiApi.types.basics import DEFAULT_CACHE_TIME
from glQiwiApi.types.qiwi_types.bill import RefundBill
from glQiwiApi.utils import basics as api_helper
from glQiwiApi.utils.exceptions import (
InvalidData,
InvalidCardNumber,
Expand Down
20 changes: 14 additions & 6 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,35 @@
import pathlib

import setuptools

with open("README.md", "r") as fh:
long_description = fh.read()
PATH = pathlib.Path(__file__).parent

README = (PATH / "README.md").read_text()

setuptools.setup(
packages=setuptools.find_packages(),
include_package_data=True,
packages=setuptools.find_packages(exclude=(
'tests', 'examples', 'examples.*')
),
name="glQiwiApi", # Replace with your own username
version="0.2.18",
version="0.2.19",
author="GLEF1X",
author_email="[email protected]",
description="Light and fast wrapper for qiwi and yoomoney",
package_data={"glQiwiApi": ["py.typed", "*.pyi", "**/*.pyi"]},
# Длинное описание, которое будет отображаться на странице PyPi.
# Использует README.md репозитория для заполнения.
long_description=long_description,
long_description=README,
# Определяет тип контента, используемый в long_description.
long_description_content_type="text/markdown",
license="MIT",
url="https://github.com/GLEF1X/glQiwiApi",
classifiers=[
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
'Development Status :: 3 - Alpha',
'Intended Audience :: Developers',
'Topic :: Software Development :: Build Tools',
],
install_requires=[
"pytz==2021.1",
Expand Down
62 changes: 39 additions & 23 deletions tests/qiwi_test.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import datetime
import unittest

from glQiwiApi import QiwiWrapper, types, sync, RequestError, InvalidData
from glQiwiApi import QiwiWrapper, types, sync, RequestError, \
InvalidData, QiwiMaps
from glQiwiApi.core import AioTestCase

TOKEN = 'token'
WALLET = '+number'
QIWI_SECRET = 'p2p token'
TOKEN = 'TOKEN'
WALLET = '+NUMBER'
QIWI_SECRET = 'P2P TOKEN'


class SyncQiwiTestCase(unittest.TestCase):
Expand All @@ -20,11 +21,11 @@ def test_account_info(self):
self.assertTrue(isinstance(info, types.QiwiAccountInfo))

def test_commission(self) -> None:
commission = sync(self.wallet.commission, to_account='+number',
commission = sync(self.wallet.commission, to_account='+74957556983',
pay_sum=1)
self.assertTrue(isinstance(commission, types.Commission))
with self.assertRaises(RequestError):
sync(self.wallet.commission, to_account='+number',
sync(self.wallet.commission, to_account='+380985272064',
pay_sum=-1)

def test_fail(self):
Expand All @@ -36,10 +37,10 @@ def test_fail(self):
end_date=datetime.datetime.now()
)
with self.assertRaises(RequestError):
sync(self.wallet.to_wallet, to_number='+wrong_number',
sync(self.wallet.to_wallet, to_number='+38056546456454',
trans_sum=1)
with self.assertRaises(RequestError):
sync(self.wallet.to_wallet, to_number='+number',
sync(self.wallet.to_wallet, to_number='+74957556983',
trans_sum=-1)

def test_transactions_history(self):
Expand All @@ -64,11 +65,11 @@ def test_transaction_info(self):
self.wallet.transaction_info,
info[0].transaction_id,
info[0].type
), types.Transaction)
) , types.Transaction)
)

def test_to_wallet(self):
txn_id = sync(self.wallet.to_wallet, to_number='+number',
txn_id = sync(self.wallet.to_wallet, to_number='+74957556983',
trans_sum=1)
self.assertTrue(isinstance(txn_id, str))

Expand Down Expand Up @@ -104,11 +105,11 @@ def test_available_balances(self):
)

def test_to_card(self):
txn_id = sync(self.wallet.to_card, to_card='card_number',
txn_id = sync(self.wallet.to_card, to_card='4890494688391549',
trans_sum=1)
self.assertTrue(isinstance(txn_id, str))
with self.assertRaises(RequestError):
sync(self.wallet.to_card, to_card='+wrong_number', trans_sum=1)
sync(self.wallet.to_card, to_card='+74957556983', trans_sum=1)

def test_test_limits(self):
limits = sync(self.wallet.get_limits)
Expand All @@ -135,8 +136,15 @@ def test_webhook_delete_fail(self):


class AsyncQiwiTestCase(AioTestCase):
"""
Async qiwi unit test, which using async with context manager
Can raise many exceptions, because there aren't native async unit tests
in Python
"""

def setUp(self) -> None:
self.wallet = QiwiWrapper(TOKEN, WALLET, secret_p2p=QIWI_SECRET)
self.maps = QiwiMaps()

async def test_account_info(self):
async with self.wallet as w:
Expand All @@ -145,29 +153,31 @@ async def test_account_info(self):

async def test_commission(self) -> None:
async with self.wallet as w:
commission = await (w.commission(to_account='+number',
commission = await (w.commission(to_account='+74957556983',
pay_sum=1))
self.assertTrue(isinstance(commission, types.Commission))
with self.assertRaises(RequestError):
async with self.wallet as w:
await w.commission(to_account='+number',
await w.commission(to_account='+74957556983',
pay_sum=-1)

async def test_fail(self):
with self.assertRaises(InvalidData):
async with self.wallet as w:
await w.fetch_statistics(
start_date=datetime.datetime.now() - datetime.timedelta(
days=100),
end_date=datetime.datetime.now())
start_date = datetime.datetime.now() - datetime.timedelta(days=100)
with self.assertRaises(InvalidData):
await w.fetch_statistics(
start_date=start_date,
end_date=datetime.datetime.now()
)

with self.assertRaises(RequestError):
async with self.wallet as w:
await w.to_wallet(to_number='+3805654645645',
trans_sum=1)
with self.assertRaises(RequestError):
async with self.wallet as w:
await w.to_wallet(to_number='+number',
await w.to_wallet(to_number='+74957556983',
trans_sum=-1)

async def test_transactions_history(self):
Expand Down Expand Up @@ -200,7 +210,7 @@ async def test_transaction_info(self):

async def test_to_wallet(self):
async with self.wallet as w:
txn_id = await w.to_wallet(to_number='+number',
txn_id = await w.to_wallet(to_number='+74957556983',
trans_sum=1)
self.assertTrue(isinstance(txn_id, str))

Expand Down Expand Up @@ -244,11 +254,10 @@ async def test_available_balances(self):

async def test_to_card(self):
async with self.wallet as w:
txn_id = await w.to_card(to_card='card',
txn_id = await w.to_card(to_card='4890494688391549',
trans_sum=1)
with self.assertRaises(RequestError):
txn_id = await w.to_card(to_card='+380985272064',
trans_sum=1)
sync(w.to_card, to_card='+74957556983', trans_sum=1)
self.assertTrue(isinstance(txn_id, str))

async def test_test_limits(self):
Expand Down Expand Up @@ -278,6 +287,13 @@ async def test_webhook_delete_fail(self):
await self.wallet.bind_webhook(url=hook_url,
delete_old=True)

async def test_qiwi_maps(self):
async with self.maps as map_manager:
partners = await map_manager.partners()
self.assertTrue(
all(isinstance(partner, types.Partner) for partner in partners)
)


if __name__ == '__main__':
unittest.main()

0 comments on commit bf86cf0

Please sign in to comment.