Skip to content

Commit

Permalink
Store group sets on their own table alongside Grouping.extra
Browse files Browse the repository at this point in the history
Duplicate the information for now until we are ready to move the group
set reads to the new table.
  • Loading branch information
marcospri committed Nov 4, 2024
1 parent 6fcf8b4 commit 0e255f6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
20 changes: 15 additions & 5 deletions lms/services/group_set.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from typing import TypedDict

from lms.models.group_set import LMSGroupSet


class GroupSetDict(TypedDict):
"""
Expand All @@ -13,6 +15,9 @@ class GroupSetDict(TypedDict):


class GroupSetService:
def __init__(self, db):
self._db = db

def store_group_sets(self, course, group_sets: list[dict]):
"""
Store this course's available group sets.
Expand All @@ -25,10 +30,15 @@ def store_group_sets(self, course, group_sets: list[dict]):
group_sets = [{"id": str(g["id"]), "name": g["name"]} for g in group_sets]
course.extra["group_sets"] = group_sets

def get_group_sets(self, course) -> list[GroupSetDict]:
"""Get this course's available group sets."""
return course.extra.get("group_sets", [])
for group_set in group_sets:
self._db.add(
LMSGroupSet(
lms_id=group_set["id"],
name=group_set["name"],
lms_course=course.lms_course,
)
)


def factory(_context, _request):
return GroupSetService()
def factory(_context, request):
return GroupSetService(db=request.db)
18 changes: 4 additions & 14 deletions tests/unit/lms/models/group_set_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,26 +26,16 @@ def test_set_group_sets(self, group_set, expected, svc):

assert course.extra["group_sets"] == [expected]

def test_get_group_sets(self, svc):
course = factories.Course(extra={"group_sets": sentinel.group_sets})

assert svc.get_group_sets(course) == sentinel.group_sets

def test_get_group_set_empty(self, svc):
course = factories.Course(extra={})

assert not svc.get_group_sets(course)

@pytest.fixture
def svc(self):
return GroupSetService()
def svc(self, db_session):
return GroupSetService(db=db_session)


class TestFactory:
def test_it(self, pyramid_request, GroupSetService):
def test_it(self, pyramid_request, GroupSetService, db_session):
service = factory(sentinel.context, pyramid_request)

GroupSetService.assert_called_once_with()
GroupSetService.assert_called_once_with(db=db_session)
assert service == GroupSetService.return_value

@pytest.fixture
Expand Down

0 comments on commit 0e255f6

Please sign in to comment.