From 51660646ff32b4d8b67d4c6675ab532682c8ac9b Mon Sep 17 00:00:00 2001 From: andrey-canon Date: Thu, 23 Jan 2025 18:07:05 -0500 Subject: [PATCH] feat: add site-aware unit test --- lms/djangoapps/mobile_api/users/tests.py | 29 ++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/lms/djangoapps/mobile_api/users/tests.py b/lms/djangoapps/mobile_api/users/tests.py index 2cfefaa058d9..acccd9869e56 100644 --- a/lms/djangoapps/mobile_api/users/tests.py +++ b/lms/djangoapps/mobile_api/users/tests.py @@ -285,6 +285,35 @@ def test_org_query(self, api_version): for entry in courses: assert entry['course']['org'] == 'edX' + @ddt.data(API_V05, API_V1, API_V2) + @patch('lms.djangoapps.mobile_api.users.views.get_current_site_orgs', return_value=['edX']) + def test_filter_by_current_site_orgs(self, get_current_site_orgs_mock, api_version): + self.login() + + # Create list of courses with various organizations + courses = [ + CourseFactory.create(org='edX', mobile_available=True), + CourseFactory.create(org='edX', mobile_available=True), + CourseFactory.create(org='edX', mobile_available=True, visible_to_staff_only=True), + CourseFactory.create(org='Proversity.org', mobile_available=True), + CourseFactory.create(org='MITx', mobile_available=True), + CourseFactory.create(org='HarvardX', mobile_available=True), + ] + + # Enroll in all the courses + for course in courses: + self.enroll(course.id) + + response = self.api_response(api_version=api_version) + courses = response.data['enrollments'] if api_version == API_V2 else response.data + + # Test for 3 expected courses + self.assertEqual(len(courses), 3) + + # Verify only edX courses are returned + for entry in courses: + self.assertEqual(entry['course']['org'], 'edX') + def create_enrollment(self, expired): """ Create an enrollment