MongoDB: fixed deprecation warnings
- collection.count() → either counting the result or using count_documents() - collection.update() → replaced by update_one()
This commit is contained in:
@@ -101,8 +101,8 @@ def insert_or_fetch_user(wh_payload: dict) -> typing.Optional[dict]:
|
|||||||
{'auth.provider': 'blender-id', 'auth.user_id': bid_str},
|
{'auth.provider': 'blender-id', 'auth.user_id': bid_str},
|
||||||
{'email': {'$in': [wh_payload['old_email'], email]}},
|
{'email': {'$in': [wh_payload['old_email'], email]}},
|
||||||
]}
|
]}
|
||||||
db_users = users_coll.find(query)
|
db_users = list(users_coll.find(query))
|
||||||
user_count = db_users.count()
|
user_count = len(db_users)
|
||||||
if user_count > 1:
|
if user_count > 1:
|
||||||
# Now we have to pay the price for finding users in one query; we
|
# Now we have to pay the price for finding users in one query; we
|
||||||
# have to prioritise them and return the one we think is most reliable.
|
# have to prioritise them and return the one we think is most reliable.
|
||||||
|
@@ -52,7 +52,7 @@ class RandomFeaturedNodeTest(AbstractCloudTest):
|
|||||||
|
|
||||||
with self.app.app_context():
|
with self.app.app_context():
|
||||||
proj_col = self.app.db('projects')
|
proj_col = self.app.db('projects')
|
||||||
proj_col.update(
|
proj_col.update_one(
|
||||||
{'_id': self.pid},
|
{'_id': self.pid},
|
||||||
{'$set': {
|
{'$set': {
|
||||||
'nodes_featured': all_asset_ids,
|
'nodes_featured': all_asset_ids,
|
||||||
@@ -99,7 +99,7 @@ class RandomFeaturedNodeTest(AbstractCloudTest):
|
|||||||
# Featured but project is private, should be ignored
|
# Featured but project is private, should be ignored
|
||||||
with self.app.app_context():
|
with self.app.app_context():
|
||||||
proj_col = self.app.db('projects')
|
proj_col = self.app.db('projects')
|
||||||
proj_col.update(
|
proj_col.update_one(
|
||||||
{'_id': self.pid},
|
{'_id': self.pid},
|
||||||
{'$set': {
|
{'$set': {
|
||||||
'nodes_featured': [node_id],
|
'nodes_featured': [node_id],
|
||||||
@@ -110,7 +110,7 @@ class RandomFeaturedNodeTest(AbstractCloudTest):
|
|||||||
# Featured but node is deleted, should be ignored
|
# Featured but node is deleted, should be ignored
|
||||||
with self.app.app_context():
|
with self.app.app_context():
|
||||||
proj_col = self.app.db('projects')
|
proj_col = self.app.db('projects')
|
||||||
proj_col.update(
|
proj_col.update_one(
|
||||||
{'_id': self.pid},
|
{'_id': self.pid},
|
||||||
{'$set': {
|
{'$set': {
|
||||||
'nodes_featured': [node_id],
|
'nodes_featured': [node_id],
|
||||||
@@ -118,7 +118,7 @@ class RandomFeaturedNodeTest(AbstractCloudTest):
|
|||||||
}})
|
}})
|
||||||
|
|
||||||
node_col = self.app.db('nodes')
|
node_col = self.app.db('nodes')
|
||||||
node_col.update(
|
node_col.update_one(
|
||||||
{'_id': node_id},
|
{'_id': node_id},
|
||||||
{'$set': {
|
{'$set': {
|
||||||
'_deleted': True,
|
'_deleted': True,
|
||||||
@@ -149,7 +149,7 @@ class RandomFeaturedNodeTest(AbstractCloudTest):
|
|||||||
|
|
||||||
with self.app.app_context():
|
with self.app.app_context():
|
||||||
proj_col = self.app.db('projects')
|
proj_col = self.app.db('projects')
|
||||||
proj_col.update(
|
proj_col.update_one(
|
||||||
{'_id': self.pid},
|
{'_id': self.pid},
|
||||||
{'$set': {
|
{'$set': {
|
||||||
'nodes_featured': [node_id],
|
'nodes_featured': [node_id],
|
||||||
|
@@ -21,7 +21,7 @@ class StatsTest(AbstractCloudTest):
|
|||||||
private2 = self.create_project_with_admin(
|
private2 = self.create_project_with_admin(
|
||||||
24 * 'd', project_overrides={'_id': ObjectId(), 'is_private': None})
|
24 * 'd', project_overrides={'_id': ObjectId(), 'is_private': None})
|
||||||
|
|
||||||
self.assertEqual(4, self.app.db('projects').count())
|
self.assertEqual(4, self.app.db('projects').count_documents({}))
|
||||||
|
|
||||||
# Create asset node
|
# Create asset node
|
||||||
self.assertEqual('asset', ctd.EXAMPLE_NODE['node_type'])
|
self.assertEqual('asset', ctd.EXAMPLE_NODE['node_type'])
|
||||||
|
Reference in New Issue
Block a user