@@ -1371,24 +1371,38 @@ def test_can_download_plain_text(self):
1371
1371
expected_status = status .HTTP_400_BAD_REQUEST )
1372
1372
1373
1373
1374
- class TestStatisticsAPI (APITestCase ):
1374
+ class TestStatisticsAPI (APITestCase , TestUtilsMixin ):
1375
1375
1376
1376
@classmethod
1377
1377
def setUpTestData (cls ):
1378
1378
cls .super_user_name = 'super_user_name'
1379
1379
cls .super_user_pass = 'super_user_pass'
1380
+ cls .other_user_name = 'other_user_name'
1381
+ cls .other_user_pass = 'other_user_pass'
1380
1382
create_default_roles ()
1381
1383
# Todo: change super_user to project_admin.
1382
1384
super_user = User .objects .create_superuser (username = cls .super_user_name ,
1383
1385
password = cls .super_user_pass ,
1384
1386
1385
1387
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
+
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 )
1389
1395
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 ()
1392
1406
1393
1407
def test_returns_exact_progress (self ):
1394
1408
self .client .login (username = self .super_user_name ,
@@ -1397,6 +1411,15 @@ def test_returns_exact_progress(self):
1397
1411
self .assertEqual (response .data ['total' ], 2 )
1398
1412
self .assertEqual (response .data ['remaining' ], 1 )
1399
1413
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
+
1400
1423
def test_returns_user_count (self ):
1401
1424
self .client .login (username = self .super_user_name ,
1402
1425
password = self .super_user_pass )
0 commit comments