Skip to content

Commit

Permalink
Add 'get_selectable_groups' method
Browse files Browse the repository at this point in the history
An earlier oversight - the courts we want to show grouped in the context of the search form are the _selectable_ courts, not the _listable_ ones.
  • Loading branch information
timcowlishaw committed Oct 4, 2023
1 parent 935829b commit bce1d10
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
12 changes: 12 additions & 0 deletions src/ds_caselaw_utils/courts.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,18 @@ def get_selectable(self):
courts.append(Court(court))
return courts

def get_selectable_groups(self):
groups = []
for category in self._data:
courts = [
Court(court)
for court in category.get("courts")
if court.get("selectable")
]
if len(courts) > 0:
groups.append(CourtGroup(category.get("display_name"), courts))
return groups

def get_listable_groups(self):
groups = []
for category in self._data:
Expand Down
14 changes: 13 additions & 1 deletion src/ds_caselaw_utils/test_courts.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,31 @@ def test_loads_selectable_courts(self):
data = [
{
"name": "court_group",
"display_name": "court group 1",
"courts": [
{
"name": "court1",
"selectable": True,
},
{"name": "court2", "selectable": False},
],
}
},
{
"name": "court_group2",
"display_name": "court group 2",
"courts": [{"name": "court3", "selectable": False}],
},
]
repo = CourtsRepository(data)
selectable = repo.get_selectable()
self.assertIn("court1", [c.name for c in selectable])
self.assertNotIn("court2", [c.name for c in selectable])
groups = repo.get_selectable_groups()
self.assertIn("court group 1", [g.name for g in groups])
self.assertNotIn("court group 2", [g.name for g in groups])
self.assertIn("court1", [c.name for g in groups for c in g.courts])
self.assertNotIn("court2", [c.name for g in groups for c in g.courts])
self.assertNotIn("court3", [c.name for g in groups for c in g.courts])

def test_loads_listable_courts(self):
data = [
Expand Down

0 comments on commit bce1d10

Please sign in to comment.