@@ -583,6 +583,49 @@ def test_patch_cohort_with_group_id_missing_partition_id(self):
583583 assert data ['developer_message' ] == 'If group_id is specified, user_partition_id must also be specified.'
584584 assert data ['error_code' ] == 'missing-user-partition-id'
585585
586+ def test_get_cohorts_default_ordering (self ):
587+ """
588+ Test that cohorts are returned in ascending alphabetical order by default.
589+ """
590+ cohorts .add_cohort (self .course_key , "Zebra" , "manual" )
591+ cohorts .add_cohort (self .course_key , "Alpha" , "manual" )
592+ cohorts .add_cohort (self .course_key , "Mango" , "manual" )
593+
594+ path = reverse ('api_cohorts:cohort_handler' , kwargs = {'course_key_string' : self .course_str })
595+ self .client .login (username = self .staff_user .username , password = self .password )
596+ response = self .client .get (path = path )
597+
598+ assert response .status_code == 200
599+ names = [c ['name' ] for c in response .json ()]
600+ assert names == ['Alpha' , 'Mango' , 'Zebra' ]
601+
602+ def test_get_cohorts_desc_ordering (self ):
603+ """
604+ Test that cohorts are returned in descending alphabetical order when ordering=desc.
605+ """
606+ cohorts .add_cohort (self .course_key , "Zebra" , "manual" )
607+ cohorts .add_cohort (self .course_key , "Alpha" , "manual" )
608+ cohorts .add_cohort (self .course_key , "Mango" , "manual" )
609+
610+ path = reverse ('api_cohorts:cohort_handler' , kwargs = {'course_key_string' : self .course_str })
611+ self .client .login (username = self .staff_user .username , password = self .password )
612+ response = self .client .get (path = path , data = {'ordering' : 'desc' })
613+
614+ assert response .status_code == 200
615+ names = [c ['name' ] for c in response .json ()]
616+ assert names == ['Zebra' , 'Mango' , 'Alpha' ]
617+
618+ def test_get_cohorts_invalid_ordering (self ):
619+ """
620+ Test that an invalid ordering value returns a 400 error.
621+ """
622+ path = reverse ('api_cohorts:cohort_handler' , kwargs = {'course_key_string' : self .course_str })
623+ self .client .login (username = self .staff_user .username , password = self .password )
624+ response = self .client .get (path = path , data = {'ordering' : 'invalid' })
625+
626+ assert response .status_code == 400
627+ assert response .json ().get ('error_code' ) == 'invalid-ordering-value'
628+
586629 def test_patch_cohort_with_name_only (self ):
587630 """
588631 Test that PATCH with only name is now valid (previously required assignment_type too).
0 commit comments