Fixed two mistakes in stats query count_nodes()
- 'p.x' → 'project.x' - is_private: {$ne: true} → is_private: False, because true is the default.
This commit is contained in:
@@ -24,10 +24,10 @@ def count_nodes(query=None) -> int:
|
|||||||
{
|
{
|
||||||
'$project':
|
'$project':
|
||||||
{
|
{
|
||||||
'p.is_private': 1,
|
'project.is_private': 1,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{'$match': {'p.is_private': {'$ne': True}}},
|
{'$match': {'project.is_private': False}},
|
||||||
{'$count': 'tot'}
|
{'$count': 'tot'}
|
||||||
]
|
]
|
||||||
c = current_app.db()['nodes']
|
c = current_app.db()['nodes']
|
||||||
|
41
tests/test_stats.py
Normal file
41
tests/test_stats.py
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
import copy
|
||||||
|
|
||||||
|
from bson import ObjectId
|
||||||
|
from pillar.tests import common_test_data as ctd
|
||||||
|
|
||||||
|
from abstract_cloud_test import AbstractCloudTest
|
||||||
|
|
||||||
|
|
||||||
|
class StatsTest(AbstractCloudTest):
|
||||||
|
def test_count_public_nodes(self):
|
||||||
|
self.enter_app_context()
|
||||||
|
|
||||||
|
# Create two public and two private projects. Only the assets from the
|
||||||
|
# public projects should be counted.
|
||||||
|
public1 = self.create_project_with_admin(
|
||||||
|
24 * 'a', project_overrides={'_id': ObjectId(), 'is_private': False})
|
||||||
|
public2 = self.create_project_with_admin(
|
||||||
|
24 * 'b', project_overrides={'_id': ObjectId(), 'is_private': False})
|
||||||
|
private1 = self.create_project_with_admin(
|
||||||
|
24 * 'c', project_overrides={'_id': ObjectId(), 'is_private': True})
|
||||||
|
private2 = self.create_project_with_admin(
|
||||||
|
24 * 'd', project_overrides={'_id': ObjectId(), 'is_private': None})
|
||||||
|
|
||||||
|
self.assertEqual(4, self.app.db('projects').count())
|
||||||
|
|
||||||
|
# Create asset node
|
||||||
|
self.assertEqual('asset', ctd.EXAMPLE_NODE['node_type'])
|
||||||
|
example_node = copy.deepcopy(ctd.EXAMPLE_NODE)
|
||||||
|
del example_node['_id']
|
||||||
|
del example_node['project']
|
||||||
|
|
||||||
|
for pid in (public1, public2, private1, private2):
|
||||||
|
self.create_node({'_id': ObjectId(), 'project': pid, **example_node})
|
||||||
|
self.create_node({'_id': ObjectId(), 'project': pid, **example_node})
|
||||||
|
self.create_node({'_id': ObjectId(), 'project': pid, **example_node})
|
||||||
|
self.create_node({'_id': ObjectId(), 'project': pid, **example_node})
|
||||||
|
|
||||||
|
# Count the asset nodes
|
||||||
|
from cloud.stats import count_nodes
|
||||||
|
count = count_nodes({'node_type': 'asset'})
|
||||||
|
self.assertEqual(8, count)
|
Reference in New Issue
Block a user