Skip to content

Commit 1e63562

Browse files
authored
Merge pull request #413 from aio-libs/pyup-scheduled-update-2019-02-11
Scheduled weekly dependency update for week 06
2 parents 6470af3 + 7e13bd9 commit 1e63562

12 files changed

Lines changed: 68 additions & 64 deletions

aiohttp_admin/backends/mongo.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ async def list(self, request):
4444
.sort(paging.sort_field, sort_direction))
4545

4646
entities = await cursor.to_list(paging.limit)
47-
count = await self._collection.find(query).count()
47+
count = await self._collection.count_documents(query)
4848
headers = {'X-Total-Count': str(count)}
4949
return json_response(entities, headers=headers)
5050

@@ -66,8 +66,8 @@ async def create(self, request):
6666
raw_payload = await request.read()
6767
data = validate_payload(raw_payload, self._update_schema)
6868

69-
entity_id = await self._collection.insert(data)
70-
query = {self._primary_key: ObjectId(entity_id)}
69+
result = await self._collection.insert_one(data)
70+
query = {self._primary_key: result.inserted_id}
7171
doc = await self._collection.find_one(query)
7272

7373
return json_response(doc)
@@ -79,7 +79,7 @@ async def update(self, request):
7979
data = validate_payload(raw_payload, self._update_schema)
8080
query = {self._primary_key: ObjectId(entity_id)}
8181

82-
doc = await self._collection.find_and_modify(
82+
doc = await self._collection.find_one_and_update(
8383
query, {"$set": data}, upsert=False, new=True)
8484

8585
if not doc:
@@ -93,5 +93,5 @@ async def delete(self, request):
9393
entity_id = request.match_info['entity_id']
9494
# TODO: fix ObjectId is not always valid case
9595
query = {self._primary_key: ObjectId(entity_id)}
96-
await self._collection.remove(query)
96+
await self._collection.delete_one(query)
9797
return json_response({'status': 'deleted'})

aiohttp_admin/backends/mongo_utils.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,4 @@ def create_validator(schema, primary_key):
123123
# create validator without primary key, used for update queries
124124
# where pk supplied in url and rest in body
125125
keys = [s for s in schema.keys if s.get_name() != primary_key]
126-
new_schema = t.Dict({})
127-
new_schema.keys = keys
128-
return new_schema.ignore_extra(primary_key)
126+
return t.Dict().merge(keys).ignore_extra(primary_key)

demos/blog/requirements-dev.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
pyflakes==2.0.0
1+
pyflakes==2.1.0
22
pep8==1.7.1
3-
pytest==3.6.1
3+
pytest==4.2.0
44
ipdb==0.11
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
pyflakes==2.0.0
1+
pyflakes==2.1.0
22
pep8==1.7.1
3-
pytest==3.6.1
3+
pytest==4.2.0
44
ipdb==0.11

requirements-dev.txt

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
aiohttp-jinja2==1.0.0
2-
aiohttp-security==0.2.0
3-
aiohttp-session==2.5.1
4-
aiohttp==3.3.1
5-
aiomysql==0.0.16
6-
aiopg==0.14.0
7-
coverage==4.5.1
8-
docker==3.3.0
9-
flake8==3.5.0
1+
aiohttp-jinja2==1.1.0
2+
aiohttp-security==0.4.0
3+
aiohttp-session==2.7.0
4+
aiohttp==3.5.4
5+
aiomysql==0.0.20
6+
aiopg==0.16.0
7+
coverage==4.5.2
8+
docker==3.7.0
9+
flake8==3.7.5
1010
ipdb==0.11
11-
motor==1.2.2
12-
pytest-cov==2.5.1
13-
pytest-sugar==0.9.1
14-
pytest==3.6.1
15-
python-dateutil==2.7.3
16-
sqlalchemy==1.2.8
17-
trafaret==2.0.0a1
18-
pymysql==0.8.1
11+
motor==2.0.0
12+
pytest-cov==2.6.1
13+
pytest-sugar==0.9.2
14+
pytest==4.2.0
15+
python-dateutil==2.8.0
16+
sqlalchemy==1.2.17
17+
trafaret==1.2.0
18+
pymysql==0.9.3
1919
-r requirements-doc.txt

requirements-doc.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
sphinx==1.7.5
1+
sphinx==1.8.4
22
sphinxcontrib-asyncio==0.2.0

tests/admin_fixtures.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,11 @@ async def mongo_admin(resource_name='test_post', security=setup_security):
6363
@pytest.fixture
6464
def create_admin(request, admin_type):
6565
if admin_type == 'mongo':
66-
f = request.getfuncargvalue('mongo_admin_creator')
66+
f = request.getfixturevalue('mongo_admin_creator')
6767
elif admin_type == 'mysql':
68-
f = request.getfuncargvalue('mysql_admin_creator')
68+
f = request.getfixturevalue('mysql_admin_creator')
6969
else:
70-
f = request.getfuncargvalue('pg_admin_creator')
70+
f = request.getfixturevalue('pg_admin_creator')
7171
return f
7272

7373

tests/db_fixtures.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@
1313
from trafaret.contrib.rfc_3339 import DateTime
1414

1515

16-
def pytest_namespace():
17-
dbs = 'pg', 'mongo', 'mysql'
18-
return {'admin_type_list': dbs}
16+
ADMIN_TYPE_LIST = 'pg', 'mongo', 'mysql'
1917

2018

2119
@pytest.fixture
@@ -27,9 +25,9 @@ def admin_type():
2725
@pytest.fixture
2826
def database(request, admin_type):
2927
if admin_type == 'mysql':
30-
f = request.getfuncargvalue('mysql')
28+
f = request.getfixturevalue('mysql')
3129
else:
32-
f = request.getfuncargvalue('postgres')
30+
f = request.getfixturevalue('postgres')
3331
return f
3432

3533

@@ -203,7 +201,7 @@ async def f(rows):
203201
await mongo_collection.drop()
204202
values = create_entries(rows)
205203
for doc in values:
206-
await mongo_collection.insert(doc)
204+
await mongo_collection.insert_one(doc)
207205
return sa_table
208206
yield f
209207
loop.run_until_complete(mongo_collection.drop())

tests/test_admin_handlers.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import pytest
22

3+
from db_fixtures import ADMIN_TYPE_LIST
4+
35

46
async def prepare_admin(create_admin):
57
resource = 'posts'
@@ -9,7 +11,7 @@ async def prepare_admin(create_admin):
911
return admin, client
1012

1113

12-
@pytest.mark.parametrize('admin_type', pytest.admin_type_list)
14+
@pytest.mark.parametrize('admin_type', ADMIN_TYPE_LIST)
1315
@pytest.mark.run_loop
1416
async def test_login_page(create_admin):
1517
_, client = await prepare_admin(create_admin)
@@ -19,7 +21,7 @@ async def test_login_page(create_admin):
1921
assert b'username' in page
2022

2123

22-
@pytest.mark.parametrize('admin_type', pytest.admin_type_list)
24+
@pytest.mark.parametrize('admin_type', ADMIN_TYPE_LIST)
2325
@pytest.mark.run_loop
2426
async def test_admin_page_redirect(create_admin):
2527
_, client = await prepare_admin(create_admin)
@@ -30,7 +32,7 @@ async def test_admin_page_redirect(create_admin):
3032
assert b"ng-admin" in page
3133

3234

33-
@pytest.mark.parametrize('admin_type', pytest.admin_type_list)
35+
@pytest.mark.parametrize('admin_type', ADMIN_TYPE_LIST)
3436
@pytest.mark.run_loop
3537
async def test_token(create_admin):
3638
_, client = await prepare_admin(create_admin)
@@ -44,7 +46,7 @@ async def test_token(create_admin):
4446
assert ctx.value.error_json == msg
4547

4648

47-
@pytest.mark.parametrize('admin_type', pytest.admin_type_list)
49+
@pytest.mark.parametrize('admin_type', ADMIN_TYPE_LIST)
4850
@pytest.mark.run_loop
4951
async def test_token_invalid_payload(create_admin):
5052
_, client = await prepare_admin(create_admin)
@@ -60,7 +62,7 @@ async def test_token_invalid_payload(create_admin):
6062
assert ctx.value.error_json == msg
6163

6264

63-
@pytest.mark.parametrize('admin_type', pytest.admin_type_list)
65+
@pytest.mark.parametrize('admin_type', ADMIN_TYPE_LIST)
6466
@pytest.mark.run_loop
6567
async def test_logout(create_admin):
6668
_, client = await prepare_admin(create_admin)

tests/test_permissions.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
from aiohttp_admin.security import DummyAuthPolicy, DummyTokenIdentityPolicy
66
from aiohttp_admin.security import Permissions
77

8+
from db_fixtures import ADMIN_TYPE_LIST
9+
810

911
def setup_security(app, permissions=None):
1012
# setup dummy auth and identity
@@ -24,7 +26,7 @@ async def prepare_admin(create_admin, permissions=None):
2426
return resource, client
2527

2628

27-
@pytest.mark.parametrize('admin_type', pytest.admin_type_list)
29+
@pytest.mark.parametrize('admin_type', ADMIN_TYPE_LIST)
2830
@pytest.mark.run_loop
2931
async def test_list_without_permisson(create_admin):
3032
p = [Permissions.edit, Permissions.add, Permissions.delete]

0 commit comments

Comments
 (0)