Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Take both a list of strings and comma separated string in get_roles #6600

Merged
merged 1 commit into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions lms/services/lti_role_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,17 @@ class LTIRoleService:
def __init__(self, db_session: Session):
self._db = db_session

def get_roles(self, role_description: str) -> list[LTIRole]:
def get_roles(self, role_description: str | list[str]) -> list[LTIRole]:
"""
Get a list of role objects for the provided strings.

:param role_description: A comma delimited set of role strings
:param role_description: A comma delimited set of role strings for LTI1.1 or a list of string for LTI1.3
"""
role_strings = [role.strip() for role in role_description.split(",")]
if isinstance(role_description, str):
role_strings = [role.strip() for role in role_description.split(",")]
else:
role_strings = role_description

# Pylint is confused about the `in_` for some reason
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess there was some pylint pragma here but not anymore 🤷

roles = self._db.query(LTIRole).filter(LTIRole.value.in_(role_strings)).all()

for role in roles:
Expand Down
8 changes: 6 additions & 2 deletions tests/unit/lms/services/lti_role_service_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@


class TestLTIRoleService:
def test_get_roles(self, svc, existing_roles):
@pytest.mark.parametrize("roles_as_string", [True, False])
def test_get_roles(self, svc, existing_roles, roles_as_string):
existing_role_strings = [role.value for role in existing_roles]
new_roles = [
"http://purl.imsglobal.org/vocab/lis/v2/system/person#SysSupport",
Expand All @@ -22,7 +23,10 @@ def test_get_roles(self, svc, existing_roles):
role_descriptions.append(existing_roles[0].value)
role_descriptions.extend(new_roles)

roles = svc.get_roles(", ".join(role_descriptions))
if roles_as_string:
# pylint: disable=redefined-variable-type
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we are redefining the type of a variable here pylint, but that's the point here so adding a disable

role_descriptions = ", ".join(role_descriptions)
roles = svc.get_roles(role_descriptions)

expected_new_roles = [
Any.instance_of(LTIRole).with_attrs({"value": value}) for value in new_roles
Expand Down
Loading