88 GroupFactory ,
99 MappingSessionFactory ,
1010 MappingSessionResultFactory ,
11+ MappingSessionUserGroupFactory ,
1112 ProjectFactory ,
1213 TaskFactory ,
1314 UserFactory ,
@@ -52,10 +53,23 @@ def setUpTestData(cls):
5253 for task in tasks
5354 ]
5455 for value , tasks in [
55- (0 , cls .tasks [:10 ]),
56- (1 , cls .tasks [10 :]),
56+ (0 , cls .tasks [:5 ]),
57+ (1 , cls .tasks [5 :]),
5758 ]
5859 }
60+ cls .user_groups = UserGroupFactory .create_batch (4 )
61+ cls .user_group_results = [
62+ MappingSessionUserGroupFactory (
63+ mapping_session = result .mapping_session ,
64+ user_group = user_group ,
65+ )
66+ for results_set , user_groups in [
67+ (cls .results [0 ], cls .user_groups [:2 ]),
68+ (cls .results [1 ], cls .user_groups [3 :]),
69+ ]
70+ for result in results_set
71+ for user_group in user_groups
72+ ]
5973 AggregateCommand ().run ()
6074
6175 def test_community_stats (self ):
@@ -66,19 +80,78 @@ def test_community_stats(self):
6680 totalSwipes
6781 totalUserGroups
6882 }
83+ communityStatsLatest {
84+ totalContributors
85+ totalSwipes
86+ totalUserGroups
87+ }
6988 }
7089 """
7190
7291 resp = self .query_check (query )
7392 self .assertEqual (
74- resp ["data" ][ "communityStats" ] ,
93+ resp ["data" ],
7594 dict (
76- totalContributors = 1 ,
77- totalSwipes = 9 ,
78- totalUserGroups = 0 ,
95+ communityStats = dict (
96+ totalContributors = 1 ,
97+ totalSwipes = 9 ,
98+ totalUserGroups = 3 ,
99+ ),
100+ communityStatsLatest = dict (
101+ totalContributors = 1 ,
102+ totalSwipes = 9 ,
103+ totalUserGroups = 3 ,
104+ ),
79105 ),
80106 )
81107
108+ def test_user_group_aggregated_calc (self ):
109+ query = """
110+ query MyQuery($userGroupId: ID!) {
111+ userGroupStats(userGroupId: $userGroupId) {
112+ stats {
113+ totalAreaSwiped
114+ totalContributors
115+ totalMappingProjects
116+ totalOrganization
117+ totalSwipeTime
118+ totalSwipes
119+ }
120+ }
121+ }
122+ """
123+ with_data = dict (
124+ totalAreaSwiped = 0 ,
125+ totalContributors = 1 ,
126+ totalMappingProjects = 1 ,
127+ totalOrganization = 0 ,
128+ totalSwipeTime = 0 ,
129+ totalSwipes = 6 ,
130+ )
131+ without_data = dict (
132+ totalAreaSwiped = 0 ,
133+ totalContributors = 0 ,
134+ totalMappingProjects = 0 ,
135+ totalOrganization = 0 ,
136+ totalSwipeTime = 0 ,
137+ totalSwipes = 0 ,
138+ )
139+ resp_collection = {}
140+ for user_group in self .user_groups :
141+ resp = self .query_check (
142+ query ,
143+ variables = dict (
144+ userGroupId = user_group .user_group_id ,
145+ ),
146+ )
147+ resp_collection [user_group .user_group_id ] = resp ["data" ]["userGroupStats" ][
148+ "stats"
149+ ]
150+ assert resp_collection == {
151+ user_group .user_group_id : (without_data if index == 2 else with_data )
152+ for index , user_group in enumerate (self .user_groups )
153+ }
154+
82155 def test_user_group_query (self ):
83156 query = """
84157 query MyQuery($userGroupId: ID!, $pagination: OffsetPaginationInput!) {
0 commit comments