Skip to content

Commit c0924ec

Browse files
authored
Merge pull request #43 from lgrahl/maintenance-update
Maintenance Update
2 parents c905b99 + c9fc994 commit c0924ec

12 files changed

Lines changed: 57 additions & 49 deletions

File tree

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,9 @@ gen
6969

7070
# Vim
7171
*.swp
72+
73+
# VS Code
74+
.vscode/
75+
76+
# MyPy Cache
77+
.mypy_cache/

.travis.yml

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,15 @@ before_cache:
1515
language: python
1616
matrix:
1717
include:
18-
- python: "3.4"
19-
env: EVENT_LOOP=asyncio
2018
- python: "3.5"
2119
env: EVENT_LOOP=asyncio
22-
- python: "3.5"
23-
env: EVENT_LOOP=uvloop
24-
before_script: "pip install .[uvloop]"
2520
- python: "3.6"
2621
env: EVENT_LOOP=asyncio
27-
- python: "3.6"
22+
- python: "3.7"
23+
env: EVENT_LOOP=asyncio
24+
- python: "3.8"
25+
env: EVENT_LOOP=asyncio
26+
- python: "3.8"
2827
env: EVENT_LOOP=uvloop
2928
before_script: "pip install .[uvloop]"
3029

@@ -39,11 +38,8 @@ install:
3938

4039
# Run flake8, isort, check docs & tests
4140
script:
42-
- >
43-
if [[ "$TRAVIS_PYTHON_VERSION" != "pypy3" ]]; then
44-
flake8 . || travis_terminate 1;
45-
isort -rc -c . || (isort -rc -df . && return 1) || travis_terminate 1;
46-
fi
41+
- flake8 .
42+
- isort -rc -c . || (isort -rc -df . && return 1)
4743
- python setup.py checkdocs
4844
- py.test --cov-config .coveragerc --cov=threema.gateway --loop=$EVENT_LOOP
4945
- mypy .

setup.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,14 @@ def read(file):
3838
# Note: These are just tools that aren't required, so a version range
3939
# is not necessary here.
4040
tests_require = [
41-
'pytest>=3.1.3',
42-
'pytest-asyncio>=0.6.0',
43-
'pytest-cov>=2.5.1',
44-
'flake8>=3.3.0',
45-
'isort>=4.2.15',
41+
'pytest>=3.1.3,<4',
42+
'pytest-asyncio>=0.6.0,<0.10',
43+
'pytest-cov>=2.5.1,<3',
44+
'flake8==3.7.9',
45+
'isort==4.3.21',
4646
'collective.checkdocs>=0.2',
4747
'Pygments>=2.2.0', # required by checkdocs
48-
'mypy>=0.521',
48+
'mypy==0.770',
4949
]
5050

5151
setup(
@@ -58,7 +58,7 @@ def read(file):
5858
'logbook>=1.1.0,<2',
5959
'libnacl>=1.5.2,<2',
6060
'click>=6.7,<7', # doesn't seem to follow semantic versioning
61-
'aiohttp>=2.2.5,<3',
61+
'aiohttp>=2.3.10,<3',
6262
'wrapt>=1.10.10,<2',
6363
],
6464
tests_require=tests_require,

tests/conftest.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@
2020
from threema.gateway import e2e
2121
from threema.gateway.key import Key
2222

23+
# Turn off deprecation warnings for now
24+
# TODO: Port code to async/await
25+
os.environ['PYTHONWARNINGS'] = 'ignore'
26+
2327
_res_path = os.path.normpath(os.path.join(
2428
os.path.abspath(__file__), os.pardir, 'res'))
2529

@@ -85,7 +89,7 @@ def __init__(self):
8589
@asyncio.coroutine
8690
def pubkeys(self, request):
8791
key = request.match_info['key']
88-
from_, secret = request.GET['from'], request.GET['secret']
92+
from_, secret = request.query['from'], request.query['secret']
8993
if (from_, secret) not in pytest.msgapi.api_identities:
9094
return web.Response(status=401)
9195
elif len(key) != 8:
@@ -99,7 +103,7 @@ def pubkeys(self, request):
99103
@asyncio.coroutine
100104
def lookup_phone(self, request):
101105
phone = request.match_info['phone']
102-
from_, secret = request.GET['from'], request.GET['secret']
106+
from_, secret = request.query['from'], request.query['secret']
103107
if (from_, secret) not in pytest.msgapi.api_identities:
104108
return web.Response(status=401)
105109
elif not phone.isdigit():
@@ -111,7 +115,7 @@ def lookup_phone(self, request):
111115
@asyncio.coroutine
112116
def lookup_phone_hash(self, request):
113117
phone_hash = request.match_info['phone_hash']
114-
from_, secret = request.GET['from'], request.GET['secret']
118+
from_, secret = request.query['from'], request.query['secret']
115119
hash_ = '98b05f6eda7a878f6f016bdcdc9db6eb61a6b190e814ff787142115af144214c'
116120
if (from_, secret) not in pytest.msgapi.api_identities:
117121
return web.Response(status=401)
@@ -127,7 +131,7 @@ def lookup_phone_hash(self, request):
127131
@asyncio.coroutine
128132
def lookup_email(self, request):
129133
email = request.match_info['email']
130-
from_, secret = request.GET['from'], request.GET['secret']
134+
from_, secret = request.query['from'], request.query['secret']
131135
if (from_, secret) not in pytest.msgapi.api_identities:
132136
return web.Response(status=401)
133137
elif email == 'echoecho@example.com':
@@ -137,7 +141,7 @@ def lookup_email(self, request):
137141
@asyncio.coroutine
138142
def lookup_email_hash(self, request):
139143
email_hash = request.match_info['email_hash']
140-
from_, secret = request.GET['from'], request.GET['secret']
144+
from_, secret = request.query['from'], request.query['secret']
141145
hash_ = '45a13d422b40f81936a9987245d3f6d9064c90607273af4f578246b4484669e2'
142146
if (from_, secret) not in pytest.msgapi.api_identities:
143147
return web.Response(status=401)
@@ -153,7 +157,7 @@ def lookup_email_hash(self, request):
153157
@asyncio.coroutine
154158
def capabilities(self, request):
155159
id_ = request.match_info['id']
156-
from_, secret = request.GET['from'], request.GET['secret']
160+
from_, secret = request.query['from'], request.query['secret']
157161
if (from_, secret) not in pytest.msgapi.api_identities:
158162
return web.Response(status=401)
159163
elif id_ == 'ECHOECHO':
@@ -164,7 +168,7 @@ def capabilities(self, request):
164168

165169
@asyncio.coroutine
166170
def credits(self, request):
167-
from_, secret = request.GET['from'], request.GET['secret']
171+
from_, secret = request.query['from'], request.query['secret']
168172
if (from_, secret) not in pytest.msgapi.api_identities:
169173
return web.Response(status=401)
170174
return web.Response(body=b'100')
@@ -227,7 +231,7 @@ def upload_blob(self, request):
227231
data = (yield from request.post())
228232

229233
# Check API identity
230-
api_identity = (request.GET['from'], request.GET['secret'])
234+
api_identity = (request.query['from'], request.query['secret'])
231235
if api_identity not in pytest.msgapi.api_identities:
232236
return web.Response(status=401)
233237
except KeyError:
@@ -244,7 +248,7 @@ def upload_blob(self, request):
244248
blob_id = hashlib.md5(blob).hexdigest()
245249

246250
# Process
247-
if request.GET['from'] == pytest.msgapi.nocredit_id:
251+
if request.query['from'] == pytest.msgapi.nocredit_id:
248252
return web.Response(status=402)
249253
elif len(blob) == 0:
250254
return web.Response(status=400)
@@ -261,7 +265,7 @@ def download_blob(self, request):
261265
blob_id = request.match_info['blob_id']
262266

263267
# Check API identity
264-
from_, secret = request.GET['from'], request.GET['secret']
268+
from_, secret = request.query['from'], request.query['secret']
265269
if (from_, secret) not in pytest.msgapi.api_identities:
266270
return web.Response(status=401)
267271

tests/test_api.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,16 @@
2222
)
2323

2424

25+
@asyncio.coroutine
26+
def download_blob(connection, blob_id):
27+
response = yield from connection.download(blob_id)
28+
return response.read()
29+
30+
2531
@asyncio.coroutine
2632
def get_latest_blob_ids(server, connection):
27-
blobs = [(yield from (yield from connection.download(blob_id)).read())
28-
for blob_id in server.latest_blob_ids]
29-
return blobs
33+
return asyncio.gather(*[download_blob(connection, blob_id)
34+
for blob_id in server.latest_blob_ids])
3035

3136

3237
class TestLookupPublicKey:
@@ -54,16 +59,17 @@ def test_valid_id(self, connection, server):
5459
assert key.hex_pk() == server.echoecho_key
5560

5661
@pytest.mark.asyncio
62+
@asyncio.coroutine
5763
def test_cache_expiration(self, connection, server):
5864
connection.get_public_key.cache_clear()
5965
connection.get_public_key.cache.expiration = 0.05
6066
for _ in range(10):
61-
yield from self.test_valid_id(connection, server)
67+
yield from connection.get_public_key('ECHOECHO')
6268
cache_info = connection.get_public_key.cache_info()
6369
assert cache_info.misses == 1
6470
assert cache_info.hits == 9
6571
yield from asyncio.sleep(0.2)
66-
yield from self.test_valid_id(connection, server)
72+
yield from connection.get_public_key('ECHOECHO')
6773
cache_info = connection.get_public_key.cache_info()
6874
# For some reason, the cache is not always being cleared and I don't want
6975
# Travis to fail all the time

tests/test_cli.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@
22

33
import pytest
44

5+
from threema.gateway import ReceptionCapability
56
from threema.gateway import __version__ as _version
6-
from threema.gateway import (
7-
ReceptionCapability,
8-
feature_level,
9-
)
7+
from threema.gateway import feature_level
108
from threema.gateway.key import Key
119

1210

threema/gateway/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@
2323
"""
2424
import itertools
2525

26-
# noinspection PyUnresolvedReferences
26+
from . import _gateway
27+
from . import exception as _exception
2728
from ._gateway import * # noqa
28-
# noinspection PyUnresolvedReferences
2929
from .exception import * # noqa
3030

3131
__author__ = 'Lennart Grahl <lennart.grahl@gmail.com>'
@@ -36,6 +36,6 @@
3636
__all__ = tuple(itertools.chain(
3737
('feature_level',),
3838
('bin', 'simple', 'e2e', 'key', 'util'),
39-
_gateway.__all__, # noqa
40-
exception.__all__, # noqa
39+
_gateway.__all__,
40+
_exception.__all__,
4141
))

threema/gateway/_gateway.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ class Connection(AioRunMixin):
9090
'download',
9191
}
9292
fingerprint = binascii.unhexlify(
93-
b'a6840a28041a1c43d90c21122ea324272f5c90c82dd64f52701f3a8f1a2b395b')
93+
b'42b1038e72f00c8c4dad78a3ebdc6d7a50c5ef288da9019b9171e4d675c08a17')
9494
urls = {
9595
'get_public_key': 'https://msgapi.threema.ch/pubkeys/{}',
9696
'get_id_by_phone': 'https://msgapi.threema.ch/lookup/phone/{}',

threema/gateway/bin/callback_server.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,9 @@
88
import logbook
99
import logbook.more
1010

11+
from threema.gateway import Connection
1112
from threema.gateway import __version__ as _version
12-
from threema.gateway import (
13-
Connection,
14-
util,
15-
)
13+
from threema.gateway import util
1614
from threema.gateway.e2e import AbstractCallback
1715
from threema.gateway.key import Key
1816

threema/gateway/bin/gateway_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
import logbook
1212
import logbook.more
1313

14+
from threema.gateway import Connection
1415
from threema.gateway import __version__ as _version
1516
from threema.gateway import (
16-
Connection,
1717
e2e,
1818
feature_level,
1919
simple,

0 commit comments

Comments
 (0)