Skip to content

Commit

Permalink
test: adds unit tests for ensure_course_enrollment_is_allowed
Browse files Browse the repository at this point in the history
  • Loading branch information
tecoholic committed Aug 16, 2024
1 parent 3e132a3 commit 0c6f7a6
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions tests/test_enterprise/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
parse_lms_api_datetime,
serialize_notification_content,
truncate_string,
ensure_course_enrollment_is_allowed,
)
from test_utils import FAKE_UUIDS, TEST_PASSWORD, TEST_USERNAME, factories

Expand Down Expand Up @@ -650,3 +651,22 @@ def test_truncate_string(self):
(truncated_string, was_truncated) = truncate_string(test_string_2)
self.assertTrue(was_truncated)
self.assertEqual(len(truncated_string), MAX_ALLOWED_TEXT_LENGTH)

@ddt.data(True, False)
def test_ensure_course_enrollment_is_allowed(self, invite_only):
"""
Test that the enrollment allow endpoint is called for the "invite_only" courses.
"""
self.create_user()
mock_enrollment_api = mock.Mock()
mock_enrollment_api.get_course_details.return_value = {"invite_only": invite_only}

ensure_course_enrollment_is_allowed("test-course-id", self.user.email, mock_enrollment_api)

if invite_only:
mock_enrollment_api.allow_enrollment.assert_called_with(
self.user.email,
"test-course-id",
)
else:
mock_enrollment_api.allow_enrollment.assert_not_called()

0 comments on commit 0c6f7a6

Please sign in to comment.