@@ -1260,13 +1260,15 @@ def make_minimal_cs_thread(self, overrides=None):
1260
1260
overrides .setdefault ("course_id" , str (self .course .id ))
1261
1261
return make_minimal_cs_thread (overrides )
1262
1262
1263
- def get_comment_list (self , thread , endorsed = None , page = 1 , page_size = 1 ):
1263
+ def get_comment_list (self , thread , endorsed = None , page = 1 , page_size = 1 ,
1264
+ merge_question_type_responses = False ):
1264
1265
"""
1265
1266
Register the appropriate comments service response, then call
1266
1267
get_comment_list and return the result.
1267
1268
"""
1268
1269
self .register_get_thread_response (thread )
1269
- return get_comment_list (self .request , thread ["id" ], endorsed , page , page_size )
1270
+ return get_comment_list (self .request , thread ["id" ], endorsed , page , page_size ,
1271
+ merge_question_type_responses = merge_question_type_responses )
1270
1272
1271
1273
def test_nonexistent_thread (self ):
1272
1274
thread_id = "nonexistent_thread"
@@ -1398,10 +1400,14 @@ def test_basic_query_params(self):
1398
1400
"resp_limit" : ["14" ],
1399
1401
"with_responses" : ["True" ],
1400
1402
"reverse_order" : ["False" ],
1403
+ "merge_question_type_responses" : ["False" ],
1401
1404
}
1402
1405
)
1403
1406
1404
- def test_discussion_content (self ):
1407
+ def get_source_and_expected_comments (self ):
1408
+ """
1409
+ Returns the source comments and expected comments for testing purposes.
1410
+ """
1405
1411
source_comments = [
1406
1412
{
1407
1413
"type" : "comment" ,
@@ -1414,7 +1420,7 @@ def test_discussion_content(self):
1414
1420
"created_at" : "2015-05-11T00:00:00Z" ,
1415
1421
"updated_at" : "2015-05-11T11:11:11Z" ,
1416
1422
"body" : "Test body" ,
1417
- "endorsed" : False ,
1423
+ "endorsed" : True ,
1418
1424
"abuse_flaggers" : [],
1419
1425
"votes" : {"up_count" : 4 },
1420
1426
"child_count" : 0 ,
@@ -1449,7 +1455,7 @@ def test_discussion_content(self):
1449
1455
"updated_at" : "2015-05-11T11:11:11Z" ,
1450
1456
"raw_body" : "Test body" ,
1451
1457
"rendered_body" : "<p>Test body</p>" ,
1452
- "endorsed" : False ,
1458
+ "endorsed" : True ,
1453
1459
"endorsed_by" : None ,
1454
1460
"endorsed_by_label" : None ,
1455
1461
"endorsed_at" : None ,
@@ -1508,12 +1514,26 @@ def test_discussion_content(self):
1508
1514
},
1509
1515
},
1510
1516
]
1517
+ return source_comments , expected_comments
1518
+
1519
+ def test_discussion_content (self ):
1520
+ source_comments , expected_comments = self .get_source_and_expected_comments ()
1511
1521
actual_comments = self .get_comment_list (
1512
1522
self .make_minimal_cs_thread ({"children" : source_comments })
1513
1523
).data ["results" ]
1514
1524
assert actual_comments == expected_comments
1515
1525
1516
- def test_question_content (self ):
1526
+ def test_question_content_with_merge_question_type_responses (self ):
1527
+ source_comments , expected_comments = self .get_source_and_expected_comments ()
1528
+ actual_comments = self .get_comment_list (
1529
+ self .make_minimal_cs_thread ({
1530
+ "thread_type" : "question" ,
1531
+ "children" : source_comments ,
1532
+ "resp_total" : len (source_comments )
1533
+ }), merge_question_type_responses = True ).data ["results" ]
1534
+ assert actual_comments == expected_comments
1535
+
1536
+ def test_question_content_ (self ):
1517
1537
thread = self .make_minimal_cs_thread ({
1518
1538
"thread_type" : "question" ,
1519
1539
"endorsed_responses" : [make_minimal_cs_comment ({"id" : "endorsed_comment" , "username" : self .user .username })],
@@ -1547,11 +1567,13 @@ def test_endorsed_by_anonymity(self):
1547
1567
assert actual_comments [0 ]['endorsed_by' ] is None
1548
1568
1549
1569
@ddt .data (
1550
- ("discussion" , None , "children" , "resp_total" ),
1551
- ("question" , False , "non_endorsed_responses" , "non_endorsed_resp_total" ),
1570
+ ("discussion" , None , "children" , "resp_total" , False ),
1571
+ ("question" , False , "non_endorsed_responses" , "non_endorsed_resp_total" , False ),
1572
+ ("question" , None , "children" , "resp_total" , True ),
1552
1573
)
1553
1574
@ddt .unpack
1554
- def test_cs_pagination (self , thread_type , endorsed_arg , response_field , response_total_field ):
1575
+ def test_cs_pagination (self , thread_type , endorsed_arg , response_field ,
1576
+ response_total_field , merge_question_type_responses ):
1555
1577
"""
1556
1578
Test cases in which pagination is done by the comments service.
1557
1579
@@ -1571,22 +1593,26 @@ def test_cs_pagination(self, thread_type, endorsed_arg, response_field, response
1571
1593
})
1572
1594
1573
1595
# Only page
1574
- actual = self .get_comment_list (thread , endorsed = endorsed_arg , page = 1 , page_size = 5 ).data
1596
+ actual = self .get_comment_list (thread , endorsed = endorsed_arg , page = 1 , page_size = 5 ,
1597
+ merge_question_type_responses = merge_question_type_responses ).data
1575
1598
assert actual ['pagination' ]['next' ] is None
1576
1599
assert actual ['pagination' ]['previous' ] is None
1577
1600
1578
1601
# First page of many
1579
- actual = self .get_comment_list (thread , endorsed = endorsed_arg , page = 1 , page_size = 2 ).data
1602
+ actual = self .get_comment_list (thread , endorsed = endorsed_arg , page = 1 , page_size = 2 ,
1603
+ merge_question_type_responses = merge_question_type_responses ).data
1580
1604
assert actual ['pagination' ]['next' ] == 'http://testserver/test_path?page=2'
1581
1605
assert actual ['pagination' ]['previous' ] is None
1582
1606
1583
1607
# Middle page of many
1584
- actual = self .get_comment_list (thread , endorsed = endorsed_arg , page = 2 , page_size = 2 ).data
1608
+ actual = self .get_comment_list (thread , endorsed = endorsed_arg , page = 2 , page_size = 2 ,
1609
+ merge_question_type_responses = merge_question_type_responses ).data
1585
1610
assert actual ['pagination' ]['next' ] == 'http://testserver/test_path?page=3'
1586
1611
assert actual ['pagination' ]['previous' ] == 'http://testserver/test_path?page=1'
1587
1612
1588
1613
# Last page of many
1589
- actual = self .get_comment_list (thread , endorsed = endorsed_arg , page = 3 , page_size = 2 ).data
1614
+ actual = self .get_comment_list (thread , endorsed = endorsed_arg , page = 3 , page_size = 2 ,
1615
+ merge_question_type_responses = merge_question_type_responses ).data
1590
1616
assert actual ['pagination' ]['next' ] is None
1591
1617
assert actual ['pagination' ]['previous' ] == 'http://testserver/test_path?page=2'
1592
1618
@@ -1597,7 +1623,8 @@ def test_cs_pagination(self, thread_type, endorsed_arg, response_field, response
1597
1623
response_total_field : 5
1598
1624
})
1599
1625
with pytest .raises (PageNotFoundError ):
1600
- self .get_comment_list (thread , endorsed = endorsed_arg , page = 2 , page_size = 5 )
1626
+ self .get_comment_list (thread , endorsed = endorsed_arg , page = 2 , page_size = 5 ,
1627
+ merge_question_type_responses = merge_question_type_responses )
1601
1628
1602
1629
def test_question_endorsed_pagination (self ):
1603
1630
thread = self .make_minimal_cs_thread ({
@@ -4078,6 +4105,7 @@ class CourseTopicsV2Test(ModuleStoreTestCase):
4078
4105
"""
4079
4106
Tests for discussions topic API v2 code.
4080
4107
"""
4108
+
4081
4109
def setUp (self ) -> None :
4082
4110
super ().setUp ()
4083
4111
self .course = CourseFactory .create (
0 commit comments