Skip to content

Commit f166066

Browse files
committed
test: add test for private fields visibility in student features endpoint
1 parent 1e0e599 commit f166066

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

lms/djangoapps/instructor/tests/test_api.py

+18
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
from django.http import HttpRequest, HttpResponse
2323
from django.test import RequestFactory, TestCase
2424
from django.test.client import MULTIPART_CONTENT
25+
from django.test.utils import override_settings
2526
from django.urls import reverse as django_reverse
2627
from django.utils.translation import gettext as _
2728
from edx_when.api import get_dates_for_course, get_overrides_for_user, set_date_for_block
@@ -2626,6 +2627,23 @@ def test_get_students_features(self):
26262627
assert student_json['city'] == student.profile.city
26272628
assert student_json['country'] == ''
26282629

2630+
@ddt.data(True, False)
2631+
def test_get_students_features_private_fields(self, show_private_fields):
2632+
"""
2633+
Test that the get_students_features returns the expected private fields
2634+
"""
2635+
with override_settings(FEATURES={'SHOW_PRIVATE_FIELDS_IN_PROFILE_INFORMATION_REPORT': show_private_fields}):
2636+
url = reverse('get_students_features', kwargs={'course_id': str(self.course.id)})
2637+
response = self.client.post(url, {})
2638+
res_json = json.loads(response.content.decode('utf-8'))
2639+
2640+
assert 'students' in res_json
2641+
for student in res_json['students']:
2642+
if show_private_fields:
2643+
assert 'year_of_birth' in student
2644+
else:
2645+
assert 'year_of_birth' not in student
2646+
26292647
@ddt.data(True, False)
26302648
def test_get_students_features_cohorted(self, is_cohorted):
26312649
"""

0 commit comments

Comments
 (0)