Skip to content

Commit

Permalink
Don't return a last_update date when roster data is disabled.
Browse files Browse the repository at this point in the history
Only return the last_update when the roster data is returned to the
client. Avoid returning it when we do have that roster data but the
feature is disabled.
  • Loading branch information
marcospri committed Dec 16, 2024
1 parent 503fa0c commit 21cde1c
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 36 deletions.
2 changes: 2 additions & 0 deletions lms/services/dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,8 @@ def get_assignment_roster(
)

else:
# If we are not going to return data from the roster, don't return the last updated date
roster_last_updated = None
# Always fallback to fetch users that have launched the assignment at some point
query = self._user_service.get_users_for_assignment(
role_scope=RoleScope.COURSE,
Expand Down
72 changes: 36 additions & 36 deletions tests/unit/lms/services/dashboard_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,50 +217,50 @@ def test_get_request_admin_organizations_for_staff(

assert svc.get_request_admin_organizations(pyramid_request) == [organization]

@pytest.mark.parametrize("rosters_enabled", [True, False])
@pytest.mark.parametrize("roster_available", [True, False])
def test_get_assignment_roster_with_roster_disabled(
self, svc, application_instance, user_service, roster_service
):
assignment = factories.Assignment(
course=factories.Course(application_instance=application_instance)
)
roster_service.assignment_roster_exists.return_value = None

last_updated, roster = svc.get_assignment_roster(assignment, sentinel.h_userids)

user_service.get_users_for_assignment.assert_called_once_with(
role_scope=RoleScope.COURSE,
role_type=RoleType.LEARNER,
assignment_id=assignment.id,
h_userids=sentinel.h_userids,
)

assert (
roster
== user_service.get_users_for_assignment.return_value.add_columns.return_value.order_by.return_value
)
assert not last_updated

def test_get_assignment_roster_with_roster_enabled(
self, svc, application_instance, roster_service
self,
svc,
application_instance,
user_service,
roster_service,
rosters_enabled,
roster_available,
):
application_instance.settings.set("dashboard", "rosters", True)
application_instance.settings.set("dashboard", "rosters", rosters_enabled)
assignment = factories.Assignment(
course=factories.Course(application_instance=application_instance)
)
if not roster_available:
roster_service.assignment_roster_exists.return_value = None

last_updated, roster = svc.get_assignment_roster(assignment, sentinel.h_userids)

roster_service.get_assignment_roster.assert_called_once_with(
assignment,
role_scope=RoleScope.COURSE,
role_type=RoleType.LEARNER,
h_userids=sentinel.h_userids,
)
assert (
roster
== roster_service.get_assignment_roster.return_value.order_by.return_value
)
assert last_updated == roster_service.assignment_roster_exists.return_value
if not roster_available or not rosters_enabled:
user_service.get_users_for_assignment.assert_called_once_with(
role_scope=RoleScope.COURSE,
role_type=RoleType.LEARNER,
assignment_id=assignment.id,
h_userids=sentinel.h_userids,
)
assert not last_updated
assert (
roster
== user_service.get_users_for_assignment.return_value.add_columns.return_value.order_by.return_value
)
else:
roster_service.get_assignment_roster.assert_called_once_with(
assignment,
role_scope=RoleScope.COURSE,
role_type=RoleType.LEARNER,
h_userids=sentinel.h_userids,
)
assert last_updated == roster_service.assignment_roster_exists.return_value
assert (
roster
== roster_service.get_assignment_roster.return_value.order_by.return_value
)

@pytest.fixture()
def svc(
Expand Down

0 comments on commit 21cde1c

Please sign in to comment.