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:
2017-09-12 11:29:36 +02:00
parent ea0f88b4b8
commit f4ac9635a9
2 changed files with 43 additions and 2 deletions

View File

@@ -24,10 +24,10 @@ def count_nodes(query=None) -> int:
{
'$project':
{
'p.is_private': 1,
'project.is_private': 1,
}
},
{'$match': {'p.is_private': {'$ne': True}}},
{'$match': {'project.is_private': False}},
{'$count': 'tot'}
]
c = current_app.db()['nodes']

41
tests/test_stats.py Normal file
View 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)