Files
edx-platform/common/djangoapps/student/tests/test_api.py
Justin Hynes a3a05bc440 MICROBA-1038 | Don't check enrollment status when removing allowlist entries
[MICROBA-1038]
- Today, we check if a learner is actively enrolled in a course-run before we add or remove them from the Instructor Dashboard allow list. We ran into an issue where we couldn't remove an entry from the list because the learner is no longer actively enrolled in the course-run. Update instructor dashboard logic to only check enrollment status when _adding_ a learner to the allow list.
2021-03-04 13:44:45 -05:00

58 lines
1.8 KiB
Python

"""
Test Student api.py
"""
from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase
from xmodule.modulestore.tests.factories import CourseFactory
from common.djangoapps.student.api import is_user_enrolled_in_course
from common.djangoapps.student.tests.factories import CourseEnrollmentFactory, UserFactory
class TestStudentApi(SharedModuleStoreTestCase):
"""
Tests for functionality in the api.py file of the Student django app.
"""
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.course = CourseFactory.create()
def setUp(self):
super().setUp()
self.user = UserFactory.create()
self.course_run_key = self.course.id
def test_is_user_enrolled_in_course(self):
"""
Verify the correct value is returned when a learner is actively enrolled in a course-run.
"""
CourseEnrollmentFactory.create(
user_id=self.user.id,
course_id=self.course.id
)
result = is_user_enrolled_in_course(self.user, self.course_run_key)
assert result
def test_is_user_enrolled_in_course_not_active(self):
"""
Verify the correct value is returned when a learner is not actively enrolled in a course-run.
"""
CourseEnrollmentFactory.create(
user_id=self.user.id,
course_id=self.course.id,
is_active=False
)
result = is_user_enrolled_in_course(self.user, self.course_run_key)
assert not result
def test_is_user_enrolled_in_course_no_enrollment(self):
"""
Verify the correct value is returned when a learner is not enrolled in a course-run.
"""
result = is_user_enrolled_in_course(self.user, self.course_run_key)
assert not result