diff --git a/lms/services/__init__.py b/lms/services/__init__.py index 3eaa58a637..b6a188a57f 100644 --- a/lms/services/__init__.py +++ b/lms/services/__init__.py @@ -3,7 +3,6 @@ from lms.services.assignment import AssignmentService from lms.services.canvas import CanvasService from lms.services.canvas_studio import CanvasStudioService -from lms.services.course_roster import CourseRosterService from lms.services.d2l_api.client import D2LAPIClient from lms.services.digest import DigestService from lms.services.email_preferences import EmailPreferencesService, EmailPrefs @@ -36,6 +35,7 @@ from lms.services.moodle import MoodleAPIClient from lms.services.organization import InvalidPublicId, OrganizationService from lms.services.organization_usage_report import OrganizationUsageReportService +from lms.services.roster import RosterService from lms.services.rsa_key import RSAKeyService from lms.services.user import UserService from lms.services.user_preferences import UserPreferencesService @@ -150,9 +150,7 @@ def includeme(config): "lms.services.youtube.factory", iface=YouTubeService ) config.register_service_factory(MoodleAPIClient.factory, iface=MoodleAPIClient) - config.register_service_factory( - "lms.services.course_roster.factory", iface=CourseRosterService - ) + config.register_service_factory("lms.services.roster.factory", iface=RosterService) # Plugins are not the same as top level services but we want to register them as pyramid services too # Importing them here to: diff --git a/lms/services/course_roster.py b/lms/services/roster.py similarity index 98% rename from lms/services/course_roster.py rename to lms/services/roster.py index 2d1369523e..7216437c5e 100644 --- a/lms/services/course_roster.py +++ b/lms/services/roster.py @@ -20,7 +20,7 @@ LOG = getLogger(__name__) -class CourseRosterService: +class RosterService: def __init__( self, db, @@ -136,7 +136,7 @@ def _get_roster_roles(self, roster) -> list[LTIRole]: def factory(_context, request): - return CourseRosterService( + return RosterService( db=request.db, lti_names_roles_service=request.find_service(LTINamesRolesService), lti_role_service=request.find_service(LTIRoleService), diff --git a/lms/tasks/course_roster.py b/lms/tasks/roster.py similarity index 95% rename from lms/tasks/course_roster.py rename to lms/tasks/roster.py index c092e4c380..7d324d3b66 100644 --- a/lms/tasks/course_roster.py +++ b/lms/tasks/roster.py @@ -5,7 +5,7 @@ from sqlalchemy import exists, select from lms.models import Course, CourseRoster, Event, LMSCourse -from lms.services.course_roster import CourseRosterService +from lms.services.roster import RosterService from lms.tasks.celery import app COURSE_LAUNCHED_WINDOW = timedelta(hours=24) @@ -70,7 +70,7 @@ def schedule_fetching_rosters() -> None: def fetch_roster(*, lms_course_id) -> None: """Fetch the roster for one course.""" with app.request_context() as request: - roster_service = request.find_service(CourseRosterService) + roster_service = request.find_service(RosterService) with request.tm: lms_course = request.db.get(LMSCourse, lms_course_id) roster_service.fetch_roster(lms_course) diff --git a/tests/unit/lms/services/course_roster_test.py b/tests/unit/lms/services/roster_test.py similarity index 90% rename from tests/unit/lms/services/course_roster_test.py rename to tests/unit/lms/services/roster_test.py index 7de2a0dccf..ed0d571176 100644 --- a/tests/unit/lms/services/course_roster_test.py +++ b/tests/unit/lms/services/roster_test.py @@ -5,7 +5,7 @@ from sqlalchemy import select from lms.models import CourseRoster -from lms.services.course_roster import CourseRosterService, factory +from lms.services.roster import RosterService, factory from tests import factories @@ -80,7 +80,7 @@ def names_and_roles_roster_response(self): @pytest.fixture def svc(self, lti_names_roles_service, lti_role_service, db_session): - return CourseRosterService( + return RosterService( db_session, lti_names_roles_service=lti_names_roles_service, lti_role_service=lti_role_service, @@ -93,20 +93,20 @@ def test_it( self, pyramid_request, db_session, - CourseRosterService, + RosterService, lti_names_roles_service, lti_role_service, ): service = factory(sentinel.context, pyramid_request) - CourseRosterService.assert_called_once_with( + RosterService.assert_called_once_with( db=db_session, lti_names_roles_service=lti_names_roles_service, lti_role_service=lti_role_service, h_authority=pyramid_request.registry.settings["h_authority"], ) - assert service == CourseRosterService.return_value + assert service == RosterService.return_value @pytest.fixture - def CourseRosterService(self, patch): - return patch("lms.services.course_roster.CourseRosterService") + def RosterService(self, patch): + return patch("lms.services.roster.RosterService") diff --git a/tests/unit/lms/tasks/course_roster_test.py b/tests/unit/lms/tasks/roster_test.py similarity index 87% rename from tests/unit/lms/tasks/course_roster_test.py rename to tests/unit/lms/tasks/roster_test.py index e197754ab4..85868614bb 100644 --- a/tests/unit/lms/tasks/course_roster_test.py +++ b/tests/unit/lms/tasks/roster_test.py @@ -4,18 +4,18 @@ import pytest from freezegun import freeze_time -from lms.tasks.course_roster import fetch_roster, schedule_fetching_rosters +from lms.tasks.roster import fetch_roster, schedule_fetching_rosters from tests import factories class TestFetchRoster: - def test_it(self, course_roster_service, db_session): + def test_it(self, roster_service, db_session): lms_course = factories.LMSCourse() db_session.flush() fetch_roster(lms_course_id=lms_course.id) - course_roster_service.fetch_roster.assert_called_once_with(lms_course) + roster_service.fetch_roster.assert_called_once_with(lms_course) @freeze_time("2024-08-28") @@ -75,12 +75,12 @@ def lms_course_with_launch_and_recent_roster(self): @pytest.fixture def fetch_roster(self, patch): - return patch("lms.tasks.course_roster.fetch_roster") + return patch("lms.tasks.roster.fetch_roster") @pytest.fixture(autouse=True) def app(patch, pyramid_request): - app = patch("lms.tasks.course_roster.app") + app = patch("lms.tasks.roster.app") @contextmanager def request_context(): diff --git a/tests/unit/services.py b/tests/unit/services.py index 9fe45ff0f9..ac0aecb4c4 100644 --- a/tests/unit/services.py +++ b/tests/unit/services.py @@ -18,7 +18,6 @@ from lms.services.canvas_api import CanvasAPIClient from lms.services.canvas_studio import CanvasStudioService from lms.services.course import CourseService -from lms.services.course_roster import CourseRosterService from lms.services.d2l_api import D2LAPIClient from lms.services.dashboard import DashboardService from lms.services.digest import DigestService @@ -48,6 +47,7 @@ from lms.services.oauth2_token import OAuth2TokenService from lms.services.oauth_http import OAuthHTTPService from lms.services.organization_usage_report import OrganizationUsageReportService +from lms.services.roster import RosterService from lms.services.rsa_key import RSAKeyService from lms.services.user import UserService from lms.services.user_preferences import UserPreferencesService @@ -68,7 +68,6 @@ "canvas_service", "canvas_studio_service", "course_service", - "course_roster_service", "d2l_api_client", "dashboard_service", "digest_service", @@ -99,6 +98,7 @@ "oauth_http_service", "organization_service", "organization_usage_report_service", + "roster_service", "rsa_key_service", "user_service", "user_preferences_service", @@ -190,8 +190,8 @@ def course_service(mock_service): @pytest.fixture -def course_roster_service(mock_service): - return mock_service(CourseRosterService) +def roster_service(mock_service): + return mock_service(RosterService) @pytest.fixture