Skip to content

Commit

Permalink
test: add FilterUserWithAllowedNewsletter unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
BryanttV committed Dec 13, 2024
1 parent ec6cff9 commit 673057c
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion nau_openedx_extensions/tests/test_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@

from unittest.mock import MagicMock, Mock, patch

from django.db.models import QuerySet
from django.test import TestCase
from django.test.utils import override_settings
from opaque_keys.edx.keys import CourseKey
from openedx_filters.learning.filters import CourseEnrollmentStarted

from nau_openedx_extensions.filters.pipeline import FilterEnrollmentByDomain
from nau_openedx_extensions.filters.pipeline import FilterEnrollmentByDomain, FilterUsersWithAllowedNewsletter


class FilterEnrollmentByDomainTest(TestCase):
Expand Down Expand Up @@ -246,3 +247,34 @@ def test_inactive_user_with_email_not_in_allowed_domains(self):
"You need to activate your account before you can enroll in the course. "
"Check your example@example.com inbox for an account activation link from NAU."
))


class TestFilterUsersWithAllowedNewsletter(TestCase):
"""Test the FilterUsersWithAllowedNewsletter class that filters users who have allowed newsletters."""

def test_run_filter_with_allowed_newsletter_users(self):
"""
Test that the filter returns only schedules for users who have allowed newsletters.
"""
mock_schedules = Mock(spec=QuerySet)
mock_schedules.filter.return_value = mock_schedules

result = FilterUsersWithAllowedNewsletter.run_filter(self, mock_schedules)

mock_schedules.filter.assert_called_once_with(enrollment__user__nauuserextendedmodel__allow_newsletter=True)
self.assertIsInstance(result, dict)
self.assertIn("schedules", result)
self.assertEqual(result["schedules"], mock_schedules)

def test_run_filter_with_empty_queryset(self):
"""
Test that the filter works correctly with an empty queryset.
"""
mock_schedules = Mock(spec=QuerySet)
mock_schedules.filter.return_value = mock_schedules

result = FilterUsersWithAllowedNewsletter.run_filter(self, mock_schedules)

mock_schedules.filter.assert_called_once_with(enrollment__user__nauuserextendedmodel__allow_newsletter=True)
self.assertIsInstance(result, dict)
self.assertIn("schedules", result)

0 comments on commit 673057c

Please sign in to comment.