diff --git a/src/solo_turnier/tests/test_worker.py b/src/solo_turnier/tests/test_worker.py index 8fcc828..e7237f8 100644 --- a/src/solo_turnier/tests/test_worker.py +++ b/src/solo_turnier/tests/test_worker.py @@ -310,3 +310,32 @@ def test_mergeHtmlData(mocker): } assert finalists == expectedFinalists + +@pytest.fixture(params=range(4)) +def fixture_getAllDancesInCompetition(request, mocker): + def mockCompetition(comp): + def mockUser(): + return mocker.patch('solo_turnier.worker.ResultPerson') + def mockDances(dances): + def mockDance(name): + mock = mocker.patch('solo_turnier.worker.CompetitionResult') + mock.dance = name + return mock + return [mockDance(d) for d in dances] + return {mockUser(): mockDances(dances) for dances in comp} + + cases = ( + ([['Samba']], ['Samba']), + ([['Samba', 'Rumba'], ['Cha Cha']], ['Samba', 'Cha Cha', 'Rumba']), + ([['Samba', 'Rumba'], ['Cha Cha', 'Tango', 'Langs. Walzer']], ['Samba', 'Cha Cha', 'Rumba', 'Langs. Walzer', 'Tango']), + ([['Cha Cha', 'Rumba', 'Jive'], ['Quickstep', 'Tango', 'Wiener Walzer', 'Langs. Walzer'], ['Slowfox', 'Langs. Walzer', 'Paso Doble', 'Samba']], ['Samba', 'Cha Cha', 'Rumba', 'Paso Doble', 'Jive', 'Langs. Walzer', 'Tango', 'Wiener Walzer', 'Slowfox', 'Quickstep']) + ) + case = cases[request.param] + return (mockCompetition(case[0]), case[1]) + +def test_getAllDancesInCompetitions(fixture_getAllDancesInCompetition): + print(fixture_getAllDancesInCompetition) + data = fixture_getAllDancesInCompetition[0] + dataWorker = worker.DataWorker() + ret = dataWorker.getAllDancesInCompetitions(data) + assert ret == fixture_getAllDancesInCompetition[1] diff --git a/src/solo_turnier/worker.py b/src/solo_turnier/worker.py index 9e9cbe4..118456e 100644 --- a/src/solo_turnier/worker.py +++ b/src/solo_turnier/worker.py @@ -219,3 +219,17 @@ class DataWorker: if participant.name != person.name: self.l.error(f'Names for {person} and participant in HTML import ({participant}) do not match. Please check carefully.') competition.finalist = participant.finalist + + def getAllDancesInCompetitions(self, data:dict[ResultPerson, list[CompetitionResult]]) -> list[str]: + allDances = [ + 'Samba', 'Cha Cha', 'Rumba', 'Paso Doble', 'Jive', + 'Langs. Walzer', 'Tango', 'Wiener Walzer', 'Slowfox', 'Quickstep' + ] + dancesPresent = {d: False for d in allDances} + + for person in data: + print(person) + for competition in data[person]: + dancesPresent[competition.dance] = True + + return [d for d in allDances if dancesPresent[d]]