@@ -1371,24 +1371,38 @@ def test_can_download_plain_text(self):
13711371 expected_status = status .HTTP_400_BAD_REQUEST )
13721372
13731373
1374- class TestStatisticsAPI (APITestCase ):
1374+ class TestStatisticsAPI (APITestCase , TestUtilsMixin ):
13751375
13761376 @classmethod
13771377 def setUpTestData (cls ):
13781378 cls .super_user_name = 'super_user_name'
13791379 cls .super_user_pass = 'super_user_pass'
1380+ cls .other_user_name = 'other_user_name'
1381+ cls .other_user_pass = 'other_user_pass'
13801382 create_default_roles ()
13811383 # Todo: change super_user to project_admin.
13821384 super_user = User .objects .create_superuser (username = cls .super_user_name ,
13831385 password = cls .super_user_pass ,
13841386 email = 'fizz@buzz.com' )
13851387
1386- main_project = mommy .make ('TextClassificationProject' , users = [super_user ])
1387- doc1 = mommy .make ('Document' , project = main_project )
1388- mommy .make ('Document' , project = main_project )
1388+ other_user = User .objects .create_user (username = cls .other_user_name ,
1389+ password = cls .other_user_pass ,
1390+ email = 'bar@buzz.com' )
1391+
1392+ cls .project = mommy .make ('TextClassificationProject' , users = [super_user , other_user ])
1393+ doc1 = mommy .make ('Document' , project = cls .project )
1394+ doc2 = mommy .make ('Document' , project = cls .project )
13891395 mommy .make ('DocumentAnnotation' , document = doc1 , user = super_user )
1390- cls .url = reverse (viewname = 'statistics' , args = [main_project .id ])
1391- cls .doc = Document .objects .filter (project = main_project )
1396+ mommy .make ('DocumentAnnotation' , document = doc2 , user = other_user )
1397+ cls .url = reverse (viewname = 'statistics' , args = [cls .project .id ])
1398+ cls .doc = Document .objects .filter (project = cls .project )
1399+
1400+ assign_user_to_role (project_member = other_user , project = cls .project ,
1401+ role_name = settings .ROLE_ANNOTATOR )
1402+
1403+ @classmethod
1404+ def doCleanups (cls ):
1405+ remove_all_role_mappings ()
13921406
13931407 def test_returns_exact_progress (self ):
13941408 self .client .login (username = self .super_user_name ,
@@ -1397,6 +1411,15 @@ def test_returns_exact_progress(self):
13971411 self .assertEqual (response .data ['total' ], 2 )
13981412 self .assertEqual (response .data ['remaining' ], 1 )
13991413
1414+ def test_returns_exact_progress_with_collaborative_annotation (self ):
1415+ self ._patch_project (self .project , 'collaborative_annotation' , True )
1416+
1417+ self .client .login (username = self .other_user_name ,
1418+ password = self .other_user_pass )
1419+ response = self .client .get (self .url , format = 'json' )
1420+ self .assertEqual (response .data ['total' ], 2 )
1421+ self .assertEqual (response .data ['remaining' ], 0 )
1422+
14001423 def test_returns_user_count (self ):
14011424 self .client .login (username = self .super_user_name ,
14021425 password = self .super_user_pass )
0 commit comments