diff --git a/src/solo_turnier/tests/test_worker.py b/src/solo_turnier/tests/test_worker.py index e7237f8..0bde14b 100644 --- a/src/solo_turnier/tests/test_worker.py +++ b/src/solo_turnier/tests/test_worker.py @@ -339,3 +339,22 @@ def test_getAllDancesInCompetitions(fixture_getAllDancesInCompetition): dataWorker = worker.DataWorker() ret = dataWorker.getAllDancesInCompetitions(data) assert ret == fixture_getAllDancesInCompetition[1] + +def test_collectPersonsInGroups(mocker): + def mockPerson(group): + mock = mocker.patch('solo_turnier.worker.ResultPerson') + mock.group = group + return mock + persons = ( + mockPerson('Kin.'), mockPerson('Kin.'), mockPerson('Jun.'), + mockPerson('Kin.'), mockPerson(None), mockPerson('Jug.'), + mockPerson(None), mockPerson('Kin./Jun.'), mockPerson('Jun.') + ) + data = {p: [] for p in persons} + dataWorker = worker.DataWorker() + groups = dataWorker.collectPersonsInGroups(data) + + assert groups['Kin.'] == [persons[0], persons[1], persons[3]] + assert groups['Jun.'] == [persons[2], persons[8]] + assert groups['Jug.'] == [persons[5]] + assert groups['Sonst'] == [persons[4], persons[6], persons[7]] diff --git a/src/solo_turnier/worker.py b/src/solo_turnier/worker.py index 118456e..ab511c4 100644 --- a/src/solo_turnier/worker.py +++ b/src/solo_turnier/worker.py @@ -233,3 +233,13 @@ class DataWorker: dancesPresent[competition.dance] = True return [d for d in allDances if dancesPresent[d]] + + def collectPersonsInGroups(self, data:dict[ResultPerson, list[CompetitionResult]]) -> list[tuple[str, list[ResultPerson]]]: + groups = { + 'Kin.': [p for p in data.keys() if p.group == 'Kin.'], + 'Jun.': [p for p in data.keys() if p.group == 'Jun.'], + 'Jug.': [p for p in data.keys() if p.group == 'Jug.'], + } + found = groups['Kin.'] + groups['Jun.'] + groups['Jug.'] + groups['Sonst'] = [p for p in data.keys() if p not in found] + return groups