Skip to content

Commit

Permalink
Drop 3.4 asyncio support & Drop 3.3 support
Browse files Browse the repository at this point in the history
  • Loading branch information
youknowone committed Feb 22, 2018
1 parent 5457862 commit 5856f72
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 39 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ language: python
cache: pip
sudo: false
python:
- "pypy2.7-5.9.0"
- "pypy3.5-5.9.0"
- "pypy2.7-5.10.0"
- "pypy3.5-5.10.1"
- "2.7"
- "3.6"
- "3.4"
Expand Down
2 changes: 2 additions & 0 deletions itunesiap/shortcut.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ def aioverify(
receipt_data, password=None, exclude_old_transactions=False, **kwargs):
"""Shortcut API for :class:`itunesiap.request.Request`.
Note that python3.4 support is only available at itunesiap==2.5.1
For params and returns, see :func:`itunesiap.verify`.
"""
proxy_url = kwargs.pop('proxy_url', None)
Expand Down
20 changes: 10 additions & 10 deletions itunesiap/verify_aiohttp.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,28 @@

class AiohttpVerify:

@asyncio.coroutine
def aioverify_from(self, url, timeout):
async def aioverify_from(self, url, timeout):
body = json.dumps(self.request_content).encode()
with aiohttp.ClientSession() as session:
async with aiohttp.ClientSession() as session:
try:
http_response = yield from session.post(url, data=body, timeout=timeout)
http_response = await session.post(url, data=body, timeout=timeout)
except asyncio.TimeoutError as e:
raise exceptions.ItunesServerNotReachable(exc=e)
if http_response.status != 200:
response_text = yield from http_response.text()
response_text = await http_response.text()
raise exceptions.ItunesServerNotAvailable(http_response.status, response_text)
response_body = yield from http_response.text()
response_body = await http_response.text()
response_data = json.loads(response_body)
response = receipt.Response(response_data)
if response.status != 0:
raise exceptions.InvalidReceipt(response_data)
return response

@asyncio.coroutine
def aioverify(self, **options):
async def aioverify(self, **options):
"""Try to verify the given receipt with current environment.
Note that python3.4 support is only available at itunesiap==2.5.1
See also:
- Receipt_Validation_Programming_Guide_.
Expand Down Expand Up @@ -60,13 +60,13 @@ def aioverify(self, **options):
response = None
if use_production:
try:
response = yield from self.aioverify_from(self.PRODUCTION_VALIDATION_URL, timeout=timeout)
response = await self.aioverify_from(self.PRODUCTION_VALIDATION_URL, timeout=timeout)
except exceptions.InvalidReceipt as e:
if not use_sandbox or e.status != self.STATUS_SANDBOX_RECEIPT_ERROR:
raise
if not response and use_sandbox:
try:
response = yield from self.aioverify_from(self.SANDBOX_VALIDATION_URL, timeout=timeout)
response = await self.aioverify_from(self.SANDBOX_VALIDATION_URL, timeout=timeout)
except exceptions.InvalidReceipt as e:
raise
return response
2 changes: 1 addition & 1 deletion itunesiap/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.5.1
2.5.2
16 changes: 5 additions & 11 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,13 @@ def get_readme():
'pytest>=3.0.0', 'pytest-cov', 'tox', 'mock', 'patch',
]

if sys.version_info[:2] >= (3, 4):
if sys.version_info[:2] >= (3, 5):
install_requires.extend([
'aiohttp>=2.3.2,<3.0', 'aiodns>=1.1.1',
'aiohttp>=3.0.1', 'aiodns>=1.1.1',
])
tests_require.extend([
'pytest-asyncio'
])
if sys.version_info[:2] == (3, 4):
tests_require.extend([
'pytest-asyncio==0.5.0'
])
else:
tests_require.extend([
'pytest-asyncio'
])

setup(
name='itunes-iap',
Expand Down Expand Up @@ -67,7 +62,6 @@ def get_readme():
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
Expand Down
4 changes: 2 additions & 2 deletions tests/aiohttp_test.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import sys

if sys.version_info[:2] >= (3, 4):
from .aiohttp_test_py34 import * # noqa
if sys.version_info[:2] >= (3, 5):
from .aiohttp_test_py35 import * # noqa
else:
import pytest

Expand Down
21 changes: 8 additions & 13 deletions tests/aiohttp_test_py34.py → tests/aiohttp_test_py35.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,47 +4,42 @@
.. [#document] https://developer.apple.com/library/ios/#documentation/NetworkingInternet/Conceptual/StoreKitGuide/VerifyingStoreReceipts/VerifyingStoreReceipts.html#//apple_ref/doc/uid/TP40008267-CH104-SW1
"""

import asyncio

import pytest
import itunesiap


@pytest.mark.asyncio
@asyncio.coroutine
def test_sandbox_aiorequest(raw_receipt_legacy):
async def test_sandbox_aiorequest(raw_receipt_legacy):
"""Test sandbox receipt"""
raw_receipt = raw_receipt_legacy
request = itunesiap.Request(raw_receipt)
try:
response = yield from request.aioverify()
response = await request.aioverify()
except itunesiap.exc.InvalidReceipt as e:
assert e.status == 21007
assert e.description == e._descriptions[21007]
else:
assert False, response
response = yield from request.aioverify(env=itunesiap.env.sandbox)
response = await request.aioverify(env=itunesiap.env.sandbox)
assert response.status == 0


@pytest.mark.asyncio
@asyncio.coroutine
def test_invalid_receipt():
async def test_invalid_receipt():
request = itunesiap.Request('wrong receipt')

with pytest.raises(itunesiap.exc.InvalidReceipt):
yield from request.aioverify(env=itunesiap.env.production)
await request.aioverify(env=itunesiap.env.production)

with pytest.raises(itunesiap.exc.InvalidReceipt):
yield from request.aioverify(env=itunesiap.env.sandbox)
await request.aioverify(env=itunesiap.env.sandbox)


@pytest.mark.skip
@pytest.mark.asyncio
@asyncio.coroutine
def test_timeout():
async def test_timeout():
with pytest.raises(itunesiap.exceptions.ItunesServerNotReachable):
yield from itunesiap.aioverify(
await itunesiap.aioverify(
'DummyReceipt', timeout=0.000001, env=itunesiap.env.review)


Expand Down

0 comments on commit 5856f72

Please sign in to comment.