Make style code conformant with black
This commit is contained in:
@@ -1,21 +1,23 @@
|
||||
import solo_turnier.competition_class
|
||||
import pytest
|
||||
|
||||
|
||||
@pytest.fixture(params=range(9))
|
||||
def fix_pureClass(request):
|
||||
cases = (
|
||||
('Newc', 'Newc.'),
|
||||
('Newc.', 'Newc.'),
|
||||
('Newcomer', 'Newc.'),
|
||||
('Beg', 'Beg.'),
|
||||
('Beg.', 'Beg.'),
|
||||
('Beginner', 'Beg.'),
|
||||
('Adv', 'Adv.'),
|
||||
('Adv.', 'Adv.'),
|
||||
('Advanced', 'Adv.'),
|
||||
("Newc", "Newc."),
|
||||
("Newc.", "Newc."),
|
||||
("Newcomer", "Newc."),
|
||||
("Beg", "Beg."),
|
||||
("Beg.", "Beg."),
|
||||
("Beginner", "Beg."),
|
||||
("Adv", "Adv."),
|
||||
("Adv.", "Adv."),
|
||||
("Advanced", "Adv."),
|
||||
)
|
||||
return cases[request.param]
|
||||
|
||||
|
||||
def test_pureClassParsing(fix_pureClass):
|
||||
className = fix_pureClass[0]
|
||||
expected = fix_pureClass[1]
|
||||
@@ -28,39 +30,43 @@ def test_pureClassParsing(fix_pureClass):
|
||||
|
||||
assert parser.isPureClass(className)
|
||||
|
||||
|
||||
def test_classParsingWithPreview():
|
||||
parser = solo_turnier.competition_class.CompetitionClassParser()
|
||||
ret = parser.parseClass('Sichtung', True)
|
||||
ret = parser.parseClass("Sichtung", True)
|
||||
|
||||
assert isinstance(ret, solo_turnier.competition_class.CompetitionClass)
|
||||
assert str(ret) == 'Sichtung'
|
||||
assert str(ret) == "Sichtung"
|
||||
|
||||
assert parser.isPureClass("Sichtung", True)
|
||||
|
||||
assert parser.isPureClass('Sichtung', True)
|
||||
|
||||
def test_classParsingInvalidPreview():
|
||||
parser = solo_turnier.competition_class.CompetitionClassParser()
|
||||
try:
|
||||
parser.parseClass('Sichtung')
|
||||
parser.parseClass("Sichtung")
|
||||
assert False
|
||||
except:
|
||||
assert True
|
||||
|
||||
try:
|
||||
parser.isPureClass('Sichtung')
|
||||
parser.isPureClass("Sichtung")
|
||||
assert False
|
||||
except:
|
||||
assert True
|
||||
|
||||
|
||||
@pytest.fixture(params=range(4))
|
||||
def fix_combinedClass(request):
|
||||
cases = (
|
||||
('Newc/Beg', 'Newc./Beg.'),
|
||||
('Newc./Beg', 'Newc./Beg.'),
|
||||
('Beginner/Adv', 'Beg./Adv.'),
|
||||
('Beg/Adv', 'Beg./Adv.'),
|
||||
("Newc/Beg", "Newc./Beg."),
|
||||
("Newc./Beg", "Newc./Beg."),
|
||||
("Beginner/Adv", "Beg./Adv."),
|
||||
("Beg/Adv", "Beg./Adv."),
|
||||
)
|
||||
return cases[request.param]
|
||||
|
||||
|
||||
def test_combinedClassParsing(fix_combinedClass):
|
||||
className = fix_combinedClass[0]
|
||||
expected = fix_combinedClass[1]
|
||||
|
||||
@@ -2,12 +2,13 @@ import solo_turnier.reader
|
||||
import os
|
||||
import json
|
||||
|
||||
|
||||
def test_import():
|
||||
fileName = os.path.join(os.path.dirname(__file__), 'reader', 'test.csv')
|
||||
fileName = os.path.join(os.path.dirname(__file__), "reader", "test.csv")
|
||||
reader = solo_turnier.reader.CSVResultReader(fileName)
|
||||
ret = reader.readFile()
|
||||
|
||||
with open(os.path.join(os.path.dirname(__file__), 'reader', 'expected.json')) as fp:
|
||||
with open(os.path.join(os.path.dirname(__file__), "reader", "expected.json")) as fp:
|
||||
expected = json.load(fp)
|
||||
|
||||
assert ret == expected
|
||||
|
||||
@@ -1,21 +1,23 @@
|
||||
import solo_turnier.group
|
||||
import pytest
|
||||
|
||||
|
||||
@pytest.fixture(params=range(9))
|
||||
def fix_pureClass(request):
|
||||
cases = (
|
||||
('Kin', 'Kin.'),
|
||||
('Kin.', 'Kin.'),
|
||||
('Kinder', 'Kin.'),
|
||||
('Jun', 'Jun.'),
|
||||
('Jun.', 'Jun.'),
|
||||
('Junioren', 'Jun.'),
|
||||
('Jug', 'Jug.'),
|
||||
('Jug.', 'Jug.'),
|
||||
('Jugend', 'Jug.'),
|
||||
("Kin", "Kin."),
|
||||
("Kin.", "Kin."),
|
||||
("Kinder", "Kin."),
|
||||
("Jun", "Jun."),
|
||||
("Jun.", "Jun."),
|
||||
("Junioren", "Jun."),
|
||||
("Jug", "Jug."),
|
||||
("Jug.", "Jug."),
|
||||
("Jugend", "Jug."),
|
||||
)
|
||||
return cases[request.param]
|
||||
|
||||
|
||||
def test_pureClassParsing(fix_pureClass):
|
||||
className = fix_pureClass[0]
|
||||
expected = fix_pureClass[1]
|
||||
@@ -28,16 +30,18 @@ def test_pureClassParsing(fix_pureClass):
|
||||
|
||||
assert parser.isPureClass(className)
|
||||
|
||||
|
||||
@pytest.fixture(params=range(4))
|
||||
def fix_combinedClass(request):
|
||||
cases = (
|
||||
('Kin/Jun', 'Kin./Jun.'),
|
||||
('Kin./Jun', 'Kin./Jun.'),
|
||||
('Junioren/Jug', 'Jun./Jug.'),
|
||||
('Jun/Jug', 'Jun./Jug.'),
|
||||
("Kin/Jun", "Kin./Jun."),
|
||||
("Kin./Jun", "Kin./Jun."),
|
||||
("Junioren/Jug", "Jun./Jug."),
|
||||
("Jun/Jug", "Jun./Jug."),
|
||||
)
|
||||
return cases[request.param]
|
||||
|
||||
|
||||
def test_combinedClassParsing(fix_combinedClass):
|
||||
className = fix_combinedClass[0]
|
||||
expected = fix_combinedClass[1]
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
|
||||
import os
|
||||
import solo_turnier.html_locator
|
||||
|
||||
|
||||
def test_fetchLocationCandidates():
|
||||
folder = os.path.join(os.path.dirname(__file__), 'html_locator', 'export')
|
||||
folder = os.path.join(os.path.dirname(__file__), "html_locator", "export")
|
||||
relFolder = os.path.relpath(folder)
|
||||
|
||||
locator = solo_turnier.html_locator.HtmlLocator()
|
||||
candidates = locator.findCandidates(relFolder)
|
||||
|
||||
expected = [
|
||||
'solo_turnier/tests/html_locator/export/2-bar/erg.htm',
|
||||
'solo_turnier/tests/html_locator/export/3-baz/erg.htm',
|
||||
'solo_turnier/tests/html_locator/export/3-baz/subfolder/4-baz/erg.htm'
|
||||
"solo_turnier/tests/html_locator/export/2-bar/erg.htm",
|
||||
"solo_turnier/tests/html_locator/export/3-baz/erg.htm",
|
||||
"solo_turnier/tests/html_locator/export/3-baz/subfolder/4-baz/erg.htm",
|
||||
]
|
||||
assert set(candidates) == set(expected)
|
||||
|
||||
@@ -4,20 +4,22 @@ import json
|
||||
|
||||
import solo_turnier.html_parser
|
||||
|
||||
@pytest.fixture(scope='module', params=range(2))
|
||||
|
||||
@pytest.fixture(scope="module", params=range(2))
|
||||
def dataProviderHtmlParser(request):
|
||||
variant = str(request.param+1)
|
||||
dir = os.path.join(os.path.dirname(__file__), 'html_parser', 'erg', variant)
|
||||
htmlFile = os.path.join(dir, 'erg.htm')
|
||||
jsonFile = os.path.join(dir, 'expected.json')
|
||||
|
||||
with open(htmlFile, 'r') as fp:
|
||||
variant = str(request.param + 1)
|
||||
dir = os.path.join(os.path.dirname(__file__), "html_parser", "erg", variant)
|
||||
htmlFile = os.path.join(dir, "erg.htm")
|
||||
jsonFile = os.path.join(dir, "expected.json")
|
||||
|
||||
with open(htmlFile, "r") as fp:
|
||||
html = fp.read()
|
||||
with open(jsonFile, 'r') as fp:
|
||||
with open(jsonFile, "r") as fp:
|
||||
jsonContent = json.load(fp)
|
||||
|
||||
|
||||
return (html, jsonContent)
|
||||
|
||||
|
||||
def test_extractDataFromHtml(dataProviderHtmlParser):
|
||||
htmlString = dataProviderHtmlParser[0]
|
||||
expected = dataProviderHtmlParser[1]
|
||||
@@ -29,67 +31,71 @@ def test_extractDataFromHtml(dataProviderHtmlParser):
|
||||
for i in actualResult.participants:
|
||||
participants[i] = actualResult.participants[i].__dict__
|
||||
|
||||
assert actualResult.title == expected['title']
|
||||
assert participants == expected['participants']
|
||||
assert actualResult.title == expected["title"]
|
||||
assert participants == expected["participants"]
|
||||
|
||||
|
||||
@pytest.fixture(params=range(6))
|
||||
def fixture_guessDataFromTitle(request):
|
||||
cases = {
|
||||
'09.07.2022 - ETW, Solos Jun. Beginner Jive': {
|
||||
'class_': 'Beg.',
|
||||
'dance': 'Jive',
|
||||
'group': 'Jun.'
|
||||
"09.07.2022 - ETW, Solos Jun. Beginner Jive": {
|
||||
"class_": "Beg.",
|
||||
"dance": "Jive",
|
||||
"group": "Jun.",
|
||||
},
|
||||
'09.07.2022 - ETW, Solos Jun. Newc./Beg. Rumba': {
|
||||
'class_': 'Newc./Beg.',
|
||||
'dance': 'Rumba',
|
||||
'group': 'Jun.'
|
||||
"09.07.2022 - ETW, Solos Jun. Newc./Beg. Rumba": {
|
||||
"class_": "Newc./Beg.",
|
||||
"dance": "Rumba",
|
||||
"group": "Jun.",
|
||||
},
|
||||
'09.07.2022 - ETW, Solos Kin./Jun. Beginner Cha Cha': {
|
||||
'class_': 'Beg.',
|
||||
'dance': 'Cha Cha',
|
||||
'group': 'Kin./Jun.'
|
||||
"09.07.2022 - ETW, Solos Kin./Jun. Beginner Cha Cha": {
|
||||
"class_": "Beg.",
|
||||
"dance": "Cha Cha",
|
||||
"group": "Kin./Jun.",
|
||||
},
|
||||
'09.07.2022 - ETW, Solos Kin. Newcomer Samba': {
|
||||
'class_': 'Newc.',
|
||||
'dance': 'Samba',
|
||||
'group': 'Kin.'
|
||||
"09.07.2022 - ETW, Solos Kin. Newcomer Samba": {
|
||||
"class_": "Newc.",
|
||||
"dance": "Samba",
|
||||
"group": "Kin.",
|
||||
},
|
||||
'09.07.2022 - ETW, Solos Jugend Beg./Adv. Wiener Walzer': {
|
||||
'class_': 'Beg./Adv.',
|
||||
'dance': 'Wiener Walzer',
|
||||
'group': 'Jug.'
|
||||
"09.07.2022 - ETW, Solos Jugend Beg./Adv. Wiener Walzer": {
|
||||
"class_": "Beg./Adv.",
|
||||
"dance": "Wiener Walzer",
|
||||
"group": "Jug.",
|
||||
},
|
||||
'09.07.2022 - ETW, Solos Jugend Sichtung Wiener Walzer': {
|
||||
'class_': 'Sichtung',
|
||||
'dance': 'Wiener Walzer',
|
||||
'group': 'Jug.'
|
||||
"09.07.2022 - ETW, Solos Jugend Sichtung Wiener Walzer": {
|
||||
"class_": "Sichtung",
|
||||
"dance": "Wiener Walzer",
|
||||
"group": "Jug.",
|
||||
},
|
||||
}
|
||||
keys = list(cases.keys())
|
||||
key = keys[request.param]
|
||||
return (key, cases[key])
|
||||
|
||||
|
||||
def test_guessDataFromTitle(fixture_guessDataFromTitle):
|
||||
parser = solo_turnier.html_parser.HtmlParser('')
|
||||
parser = solo_turnier.html_parser.HtmlParser("")
|
||||
ret = parser.guessDataFromHtmlTitle(fixture_guessDataFromTitle[0])
|
||||
|
||||
assert ret == fixture_guessDataFromTitle[1]
|
||||
|
||||
|
||||
@pytest.fixture(params=range(1))
|
||||
def fixture_parsePreparationResult(request):
|
||||
variant = str(request.param+1)
|
||||
dir = os.path.join(os.path.dirname(__file__), 'html_parser', 'tabges', variant)
|
||||
htmlFile = os.path.join(dir, 'tabges.htm')
|
||||
jsonFile = os.path.join(dir, 'expected.json')
|
||||
|
||||
with open(htmlFile, 'r') as fp:
|
||||
variant = str(request.param + 1)
|
||||
dir = os.path.join(os.path.dirname(__file__), "html_parser", "tabges", variant)
|
||||
htmlFile = os.path.join(dir, "tabges.htm")
|
||||
jsonFile = os.path.join(dir, "expected.json")
|
||||
|
||||
with open(htmlFile, "r") as fp:
|
||||
html = fp.read()
|
||||
with open(jsonFile, 'r') as fp:
|
||||
with open(jsonFile, "r") as fp:
|
||||
jsonContent = json.load(fp)
|
||||
|
||||
|
||||
return (html, jsonContent)
|
||||
|
||||
|
||||
def test_parsePreparationResult(fixture_parsePreparationResult):
|
||||
html = fixture_parsePreparationResult[0]
|
||||
jsonContent = fixture_parsePreparationResult[1]
|
||||
@@ -99,25 +105,27 @@ def test_parsePreparationResult(fixture_parsePreparationResult):
|
||||
|
||||
assert ret == jsonContent
|
||||
|
||||
|
||||
@pytest.fixture(params=range(1))
|
||||
def fixture_cleanPreparationImport(request):
|
||||
variant = str(request.param+1)
|
||||
dir = os.path.join(os.path.dirname(__file__), 'html_parser', 'tabges', variant)
|
||||
srcFile = os.path.join(dir, 'expected.json')
|
||||
expectedFile = os.path.join(dir, 'cleaned.json')
|
||||
|
||||
with open(srcFile, 'r') as fp:
|
||||
variant = str(request.param + 1)
|
||||
dir = os.path.join(os.path.dirname(__file__), "html_parser", "tabges", variant)
|
||||
srcFile = os.path.join(dir, "expected.json")
|
||||
expectedFile = os.path.join(dir, "cleaned.json")
|
||||
|
||||
with open(srcFile, "r") as fp:
|
||||
source = json.load(fp)
|
||||
with open(expectedFile, 'r') as fp:
|
||||
with open(expectedFile, "r") as fp:
|
||||
expected = json.load(fp)
|
||||
|
||||
|
||||
return (source, expected)
|
||||
|
||||
|
||||
def test_cleanPreparationImport(fixture_cleanPreparationImport):
|
||||
src = fixture_cleanPreparationImport[0]
|
||||
expected = fixture_cleanPreparationImport[1]
|
||||
|
||||
parser = solo_turnier.html_parser.HtmlParser('')
|
||||
parser = solo_turnier.html_parser.HtmlParser("")
|
||||
parser.cleanPreparationRoundImport(src)
|
||||
|
||||
assert src == expected
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
import pytest
|
||||
import solo_turnier.types as types
|
||||
|
||||
|
||||
def test_HtmlPreviewParticipant_eq():
|
||||
name = 'Max Mustermann'
|
||||
name = "Max Mustermann"
|
||||
id = 123
|
||||
group = 'Kin'
|
||||
group = "Kin"
|
||||
participant = types.HtmlPreviewParticipant(name, id, group)
|
||||
|
||||
l = []
|
||||
@@ -13,6 +14,6 @@ def test_HtmlPreviewParticipant_eq():
|
||||
assert participant in l
|
||||
|
||||
assert types.HtmlPreviewParticipant(name, id, group) in l
|
||||
assert types.HtmlPreviewParticipant('Maxime Musterfrau', id, group) not in l
|
||||
assert types.HtmlPreviewParticipant("Maxime Musterfrau", id, group) not in l
|
||||
assert types.HtmlPreviewParticipant(name, 234, group) not in l
|
||||
assert types.HtmlPreviewParticipant(name, id, 'Jun') not in l
|
||||
assert types.HtmlPreviewParticipant(name, id, "Jun") not in l
|
||||
|
||||
@@ -4,178 +4,298 @@ import json
|
||||
import pytest
|
||||
import pytest_mock
|
||||
|
||||
|
||||
def __importJSONData(name):
|
||||
path = os.path.join(os.path.dirname(__file__), 'worker', name)
|
||||
with open(path, 'r') as fp:
|
||||
path = os.path.join(os.path.dirname(__file__), "worker", name)
|
||||
with open(path, "r") as fp:
|
||||
return json.load(fp)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def fixture_csvExtractor():
|
||||
data = __importJSONData('csvImport.json')
|
||||
expected = __importJSONData('csvImportResult.json')
|
||||
data = __importJSONData("csvImport.json")
|
||||
expected = __importJSONData("csvImportResult.json")
|
||||
return (data, expected)
|
||||
|
||||
|
||||
def test_csvExtractor(fixture_csvExtractor):
|
||||
extractor = worker.CSVExtractor()
|
||||
mapped = extractor.mapCSVImport(fixture_csvExtractor[0])
|
||||
|
||||
assert len(mapped) == len(fixture_csvExtractor[1])
|
||||
for i,elem in enumerate(fixture_csvExtractor[1]):
|
||||
for i, elem in enumerate(fixture_csvExtractor[1]):
|
||||
assert mapped[i].__dict__ == elem
|
||||
|
||||
|
||||
def test_extractPersonFromRow():
|
||||
row = worker.ResultRow('Max', 'Mustermann', 'TSC Entenhausen', '2', 'Kin', 'Adv.', 'Rumba', '2', '2', 'Kin.', 'Beg./Adv.')
|
||||
row = worker.ResultRow(
|
||||
"Max",
|
||||
"Mustermann",
|
||||
"TSC Entenhausen",
|
||||
"2",
|
||||
"Kin",
|
||||
"Adv.",
|
||||
"Rumba",
|
||||
"2",
|
||||
"2",
|
||||
"Kin.",
|
||||
"Beg./Adv.",
|
||||
)
|
||||
person = worker.ResultPerson.extractFromResultRow(row)
|
||||
expected = {
|
||||
'firstName': 'Max',
|
||||
'lastName': 'Mustermann',
|
||||
'name': 'Max Mustermann',
|
||||
'club': 'TSC Entenhausen',
|
||||
'id': None,
|
||||
'group': None
|
||||
"firstName": "Max",
|
||||
"lastName": "Mustermann",
|
||||
"name": "Max Mustermann",
|
||||
"club": "TSC Entenhausen",
|
||||
"id": None,
|
||||
"group": None,
|
||||
}
|
||||
assert person.__dict__ == expected
|
||||
|
||||
|
||||
def test_extractCompetitionFromRow():
|
||||
row = worker.ResultRow('Max', 'Mustermann', 'TSC Entenhausen', '2', 'Kin', 'Adv.', 'Rumba', '2', '2', 'Kin.', 'Beg./Adv.')
|
||||
row = worker.ResultRow(
|
||||
"Max",
|
||||
"Mustermann",
|
||||
"TSC Entenhausen",
|
||||
"2",
|
||||
"Kin",
|
||||
"Adv.",
|
||||
"Rumba",
|
||||
"2",
|
||||
"2",
|
||||
"Kin.",
|
||||
"Beg./Adv.",
|
||||
)
|
||||
competition = worker.CompetitionResult.extractFromResultRow(row)
|
||||
expected = {
|
||||
'dance': 'Rumba',
|
||||
'class_': 'Adv.',
|
||||
'group': 'Kin',
|
||||
'place': '2',
|
||||
'placeTo': '2',
|
||||
'id': 2,
|
||||
'finalist': None,
|
||||
'competitionGroup': 'Kin.',
|
||||
'competitionClass': 'Beg./Adv.'
|
||||
"dance": "Rumba",
|
||||
"class_": "Adv.",
|
||||
"group": "Kin",
|
||||
"place": "2",
|
||||
"placeTo": "2",
|
||||
"id": 2,
|
||||
"finalist": None,
|
||||
"competitionGroup": "Kin.",
|
||||
"competitionClass": "Beg./Adv.",
|
||||
}
|
||||
assert competition.__dict__ == expected
|
||||
|
||||
|
||||
def test_combineRowsByPerson():
|
||||
rows = [
|
||||
worker.ResultRow('Max', 'Mustermann', 'TSC Entenhausen', '2', 'Kin', 'Adv.', 'Cha Cha', '-', '-', 'Kin.', 'Adv.'),
|
||||
worker.ResultRow('Max', 'Mustermann', 'TSC Entenhausen', '2', 'Kin', 'Adv.', 'Rumba', '2', '2', 'Kin.', 'Adv.'),
|
||||
worker.ResultRow('Max', 'Mustermann', 'TSC Entenhausen', '2', 'Kin', 'Beg.', 'Jive', '1', '1', 'Kin.', 'Beg.'),
|
||||
worker.ResultRow('Maxime', 'Musterfrau', '1. SC Entenhausen', '1', 'Kin', 'Adv.', 'Rumba', '1', '1', 'Kin.', 'Adv.')
|
||||
worker.ResultRow(
|
||||
"Max",
|
||||
"Mustermann",
|
||||
"TSC Entenhausen",
|
||||
"2",
|
||||
"Kin",
|
||||
"Adv.",
|
||||
"Cha Cha",
|
||||
"-",
|
||||
"-",
|
||||
"Kin.",
|
||||
"Adv.",
|
||||
),
|
||||
worker.ResultRow(
|
||||
"Max",
|
||||
"Mustermann",
|
||||
"TSC Entenhausen",
|
||||
"2",
|
||||
"Kin",
|
||||
"Adv.",
|
||||
"Rumba",
|
||||
"2",
|
||||
"2",
|
||||
"Kin.",
|
||||
"Adv.",
|
||||
),
|
||||
worker.ResultRow(
|
||||
"Max",
|
||||
"Mustermann",
|
||||
"TSC Entenhausen",
|
||||
"2",
|
||||
"Kin",
|
||||
"Beg.",
|
||||
"Jive",
|
||||
"1",
|
||||
"1",
|
||||
"Kin.",
|
||||
"Beg.",
|
||||
),
|
||||
worker.ResultRow(
|
||||
"Maxime",
|
||||
"Musterfrau",
|
||||
"1. SC Entenhausen",
|
||||
"1",
|
||||
"Kin",
|
||||
"Adv.",
|
||||
"Rumba",
|
||||
"1",
|
||||
"1",
|
||||
"Kin.",
|
||||
"Adv.",
|
||||
),
|
||||
]
|
||||
dataWorker = worker.DataWorker()
|
||||
result = dataWorker.combineRowsByPerson(rows)
|
||||
expected = {
|
||||
worker.ResultPerson('Max', 'Mustermann', 'TSC Entenhausen'): [
|
||||
worker.CompetitionResult('Rumba', 'Kin', 'Adv.', '2', '2', '2', 'Kin.', 'Adv.'),
|
||||
worker.CompetitionResult('Jive', 'Kin', 'Beg.', '1', '1', '2', 'Kin.', 'Beg.')
|
||||
worker.ResultPerson("Max", "Mustermann", "TSC Entenhausen"): [
|
||||
worker.CompetitionResult(
|
||||
"Rumba", "Kin", "Adv.", "2", "2", "2", "Kin.", "Adv."
|
||||
),
|
||||
worker.CompetitionResult(
|
||||
"Jive", "Kin", "Beg.", "1", "1", "2", "Kin.", "Beg."
|
||||
),
|
||||
],
|
||||
worker.ResultPerson("Maxime", "Musterfrau", "1. SC Entenhausen"): [
|
||||
worker.CompetitionResult(
|
||||
"Rumba", "Kin", "Adv.", "1", "1", "1", "Kin.", "Adv."
|
||||
)
|
||||
],
|
||||
worker.ResultPerson('Maxime', 'Musterfrau', '1. SC Entenhausen'): [
|
||||
worker.CompetitionResult('Rumba', 'Kin', 'Adv.', '1', '1', '1', 'Kin.', 'Adv.')
|
||||
]
|
||||
}
|
||||
assert result == expected
|
||||
|
||||
|
||||
def test_checkUniqueIds_True():
|
||||
person1 = worker.ResultPerson('Max', 'Mustermann', 'TSC Entenhausen')
|
||||
person2 = worker.ResultPerson('Maxime', 'Musterfrau', '1. SC Entenhausen')
|
||||
person1 = worker.ResultPerson("Max", "Mustermann", "TSC Entenhausen")
|
||||
person2 = worker.ResultPerson("Maxime", "Musterfrau", "1. SC Entenhausen")
|
||||
data = {
|
||||
person1: [
|
||||
worker.CompetitionResult('Rumba', 'Kin', 'Adv.', '2', '2', 2, 'Kin.', 'Adv.'),
|
||||
worker.CompetitionResult('Jive', 'Kin', 'Beg.', '1', '1', 2, 'Kin.', 'Beg.')
|
||||
worker.CompetitionResult(
|
||||
"Rumba", "Kin", "Adv.", "2", "2", 2, "Kin.", "Adv."
|
||||
),
|
||||
worker.CompetitionResult(
|
||||
"Jive", "Kin", "Beg.", "1", "1", 2, "Kin.", "Beg."
|
||||
),
|
||||
],
|
||||
person2: [
|
||||
worker.CompetitionResult('Rumba', 'Kin', 'Adv.', '1', '1', 1, 'Kin.', 'Adv.')
|
||||
]
|
||||
worker.CompetitionResult(
|
||||
"Rumba", "Kin", "Adv.", "1", "1", 1, "Kin.", "Adv."
|
||||
)
|
||||
],
|
||||
}
|
||||
dataWorker = worker.DataWorker()
|
||||
assert dataWorker.checkUniqueIds(data) == True
|
||||
assert person1.id == 2
|
||||
assert person2.id == 1
|
||||
|
||||
|
||||
def test_checkUniqueIds_False():
|
||||
person1 = worker.ResultPerson('Max', 'Mustermann', 'TSC Entenhausen')
|
||||
person2 = worker.ResultPerson('Maxime', 'Musterfrau', '1. SC Entenhausen')
|
||||
person1 = worker.ResultPerson("Max", "Mustermann", "TSC Entenhausen")
|
||||
person2 = worker.ResultPerson("Maxime", "Musterfrau", "1. SC Entenhausen")
|
||||
data = {
|
||||
person1: [
|
||||
worker.CompetitionResult('Rumba', 'Kin', 'Adv.', '2', '2', 2, 'Kin.', 'Adv.'),
|
||||
worker.CompetitionResult('Jive', 'Kin', 'Beg.', '1', '1', 3, 'Kin.', 'Beg.')
|
||||
worker.CompetitionResult(
|
||||
"Rumba", "Kin", "Adv.", "2", "2", 2, "Kin.", "Adv."
|
||||
),
|
||||
worker.CompetitionResult(
|
||||
"Jive", "Kin", "Beg.", "1", "1", 3, "Kin.", "Beg."
|
||||
),
|
||||
],
|
||||
person2: [
|
||||
worker.CompetitionResult('Rumba', 'Kin', 'Adv.', '1', '1', 1, 'Kin.', 'Adv.')
|
||||
]
|
||||
worker.CompetitionResult(
|
||||
"Rumba", "Kin", "Adv.", "1", "1", 1, "Kin.", "Adv."
|
||||
)
|
||||
],
|
||||
}
|
||||
dataWorker = worker.DataWorker()
|
||||
assert dataWorker.checkUniqueIds(data) == False
|
||||
assert person1.id == None
|
||||
assert person2.id == 1
|
||||
|
||||
|
||||
@pytest.fixture(params=range(5))
|
||||
def fixture_consolidateGroups(request):
|
||||
person1 = worker.ResultPerson('Max 1', 'Mustermann', 'TSC Entenhausen')
|
||||
person2 = worker.ResultPerson('Max 2', 'Mustermann', 'TSC Entenhausen')
|
||||
person3 = worker.ResultPerson('Max 3', 'Mustermann', 'TSC Entenhausen')
|
||||
person4 = worker.ResultPerson('Max 4', 'Mustermann', 'TSC Entenhausen')
|
||||
person1 = worker.ResultPerson("Max 1", "Mustermann", "TSC Entenhausen")
|
||||
person2 = worker.ResultPerson("Max 2", "Mustermann", "TSC Entenhausen")
|
||||
person3 = worker.ResultPerson("Max 3", "Mustermann", "TSC Entenhausen")
|
||||
person4 = worker.ResultPerson("Max 4", "Mustermann", "TSC Entenhausen")
|
||||
# persons = (person1, person2, person3, person4)
|
||||
|
||||
dict1 = {
|
||||
person1: [
|
||||
worker.CompetitionResult('Rumba', 'Kin.', 'Adv.', '2', '2', 2, 'Kin.', 'Adv.'),
|
||||
worker.CompetitionResult('Jive', 'Kin.', 'Beg.', '1', '1', 3, 'Kin.', 'Beg.')
|
||||
worker.CompetitionResult(
|
||||
"Rumba", "Kin.", "Adv.", "2", "2", 2, "Kin.", "Adv."
|
||||
),
|
||||
worker.CompetitionResult(
|
||||
"Jive", "Kin.", "Beg.", "1", "1", 3, "Kin.", "Beg."
|
||||
),
|
||||
]
|
||||
}
|
||||
dict2 = {
|
||||
person2: [
|
||||
worker.CompetitionResult('Rumba', 'Kin.', 'Adv.', '2', '2', 2, 'Kin.', 'Adv.'),
|
||||
worker.CompetitionResult('Jive', 'Kin./Jun.', 'Beg.', '1', '1', 3, 'Kin./Jun.', 'Beg.')
|
||||
worker.CompetitionResult(
|
||||
"Rumba", "Kin.", "Adv.", "2", "2", 2, "Kin.", "Adv."
|
||||
),
|
||||
worker.CompetitionResult(
|
||||
"Jive", "Kin./Jun.", "Beg.", "1", "1", 3, "Kin./Jun.", "Beg."
|
||||
),
|
||||
]
|
||||
}
|
||||
dict3 = {
|
||||
person3: [
|
||||
worker.CompetitionResult('Rumba', 'Kin.', 'Adv.', '2', '2', 2, 'Kin.', 'Adv.')
|
||||
worker.CompetitionResult(
|
||||
"Rumba", "Kin.", "Adv.", "2", "2", 2, "Kin.", "Adv."
|
||||
)
|
||||
]
|
||||
}
|
||||
dict4 = {
|
||||
person4: [
|
||||
worker.CompetitionResult('Rumba', 'Kin./Jun.', 'Adv.', '2', '2', 2, 'Kin./Jun.', 'Adv.')
|
||||
worker.CompetitionResult(
|
||||
"Rumba", "Kin./Jun.", "Adv.", "2", "2", 2, "Kin./Jun.", "Adv."
|
||||
)
|
||||
]
|
||||
}
|
||||
dict5 = {
|
||||
person4: [
|
||||
worker.CompetitionResult('Rumba', 'Kin./Jun.', 'Adv.', '2', '2', 2, 'Kin./Jun.', 'Adv.'),
|
||||
worker.CompetitionResult('Cha Cha', 'Jun./Jug.', 'Beg.', '3', '4', 2, 'Jun./Jug.', 'Beg.')
|
||||
worker.CompetitionResult(
|
||||
"Rumba", "Kin./Jun.", "Adv.", "2", "2", 2, "Kin./Jun.", "Adv."
|
||||
),
|
||||
worker.CompetitionResult(
|
||||
"Cha Cha", "Jun./Jug.", "Beg.", "3", "4", 2, "Jun./Jug.", "Beg."
|
||||
),
|
||||
]
|
||||
}
|
||||
|
||||
cases = (
|
||||
(dict1|dict3, (True, False), {}),
|
||||
(dict1|dict2|dict3, (True, True), {}),
|
||||
(dict4, (False, False), {person4: 'Kin./Jun.'}),
|
||||
(dict1|dict2|dict3|dict4, (False, True), {person4: 'Kin./Jun.'}),
|
||||
(dict5, (True, True), {person4: 'Jun.'}),
|
||||
(dict1 | dict3, (True, False), {}),
|
||||
(dict1 | dict2 | dict3, (True, True), {}),
|
||||
(dict4, (False, False), {person4: "Kin./Jun."}),
|
||||
(dict1 | dict2 | dict3 | dict4, (False, True), {person4: "Kin./Jun."}),
|
||||
(dict5, (True, True), {person4: "Jun."}),
|
||||
)
|
||||
return cases[request.param]
|
||||
|
||||
|
||||
@pytest.fixture(params=range(2))
|
||||
def fixture_consolidateGroups_fail(request, fixture_consolidateGroups):
|
||||
person = worker.ResultPerson('Max 5', 'Mustermann', 'TSC Entenhausen')
|
||||
person = worker.ResultPerson("Max 5", "Mustermann", "TSC Entenhausen")
|
||||
|
||||
dict1 = {
|
||||
person: [
|
||||
worker.CompetitionResult('Rumba', 'Kin.', 'Adv.', '2', '2', 2, 'Kin.', 'Adv.'),
|
||||
worker.CompetitionResult('Jive', 'Jun.', 'Beg.', '1', '1', 3, 'Jun.', 'Adv.')
|
||||
worker.CompetitionResult(
|
||||
"Rumba", "Kin.", "Adv.", "2", "2", 2, "Kin.", "Adv."
|
||||
),
|
||||
worker.CompetitionResult(
|
||||
"Jive", "Jun.", "Beg.", "1", "1", 3, "Jun.", "Adv."
|
||||
),
|
||||
]
|
||||
}
|
||||
|
||||
dict2 = {
|
||||
person: [
|
||||
worker.CompetitionResult('Rumba', 'Kin.', 'Adv.', '2', '2', 2, 'Kin.', 'Adv.'),
|
||||
worker.CompetitionResult('Jive', 'Hgr', 'Beg.', '1', '1', 3, 'Hgr', 'Adv.')
|
||||
worker.CompetitionResult(
|
||||
"Rumba", "Kin.", "Adv.", "2", "2", 2, "Kin.", "Adv."
|
||||
),
|
||||
worker.CompetitionResult("Jive", "Hgr", "Beg.", "1", "1", 3, "Hgr", "Adv."),
|
||||
]
|
||||
}
|
||||
|
||||
cases = (
|
||||
dict1 | fixture_consolidateGroups[0],
|
||||
dict2 | fixture_consolidateGroups[0]
|
||||
)
|
||||
cases = (dict1 | fixture_consolidateGroups[0], dict2 | fixture_consolidateGroups[0])
|
||||
return cases[request.param]
|
||||
|
||||
|
||||
def test_consolidateGroups(fixture_consolidateGroups):
|
||||
data = fixture_consolidateGroups[0]
|
||||
dataWorker = worker.DataWorker()
|
||||
@@ -183,7 +303,8 @@ def test_consolidateGroups(fixture_consolidateGroups):
|
||||
assert dataWorker.consolidateGroups(data) == fixture_consolidateGroups[1]
|
||||
|
||||
for person in data:
|
||||
assert person.group == fixture_consolidateGroups[2].get(person, 'Kin.')
|
||||
assert person.group == fixture_consolidateGroups[2].get(person, "Kin.")
|
||||
|
||||
|
||||
def test_consolidateGroups_failing(fixture_consolidateGroups_fail):
|
||||
data = fixture_consolidateGroups_fail
|
||||
@@ -192,105 +313,143 @@ def test_consolidateGroups_failing(fixture_consolidateGroups_fail):
|
||||
with pytest.raises(Exception):
|
||||
dataWorker.consolidateGroups(data)
|
||||
|
||||
|
||||
def test_createHtmlLUT(mocker):
|
||||
mock = mocker.patch('solo_turnier.html_parser.HtmlParser.guessDataFromHtmlTitle')
|
||||
mock.side_effect= [
|
||||
{'group': 'group1', 'class_': 'class1', 'dance': 'dance1'},
|
||||
{'group': 'group2', 'class_': 'class2', 'dance': 'dance2'},
|
||||
{'group': 'group3', 'class_': 'class3', 'dance': 'dance3'},
|
||||
mock = mocker.patch("solo_turnier.html_parser.HtmlParser.guessDataFromHtmlTitle")
|
||||
mock.side_effect = [
|
||||
{"group": "group1", "class_": "class1", "dance": "dance1"},
|
||||
{"group": "group2", "class_": "class2", "dance": "dance2"},
|
||||
{"group": "group3", "class_": "class3", "dance": "dance3"},
|
||||
]
|
||||
|
||||
importMock1 = mocker.patch('solo_turnier.html_parser.HtmlImport')
|
||||
importMock2 = mocker.patch('solo_turnier.html_parser.HtmlImport')
|
||||
importMock3 = mocker.patch('solo_turnier.html_parser.HtmlImport')
|
||||
importMock1.title = 'Fake title 1'
|
||||
importMock2.title = 'Fake title 2'
|
||||
importMock3.title = 'Fake title 3'
|
||||
|
||||
importMock1 = mocker.patch("solo_turnier.html_parser.HtmlImport")
|
||||
importMock2 = mocker.patch("solo_turnier.html_parser.HtmlImport")
|
||||
importMock3 = mocker.patch("solo_turnier.html_parser.HtmlImport")
|
||||
importMock1.title = "Fake title 1"
|
||||
importMock2.title = "Fake title 2"
|
||||
importMock3.title = "Fake title 3"
|
||||
|
||||
dataWorker = worker.DataWorker()
|
||||
structure = dataWorker._createHtmlLUT([importMock1, importMock2, importMock3])
|
||||
|
||||
expected = {
|
||||
('group1', 'class1', 'dance1'): importMock1,
|
||||
('group2', 'class2', 'dance2'): importMock2,
|
||||
('group3', 'class3', 'dance3'): importMock3,
|
||||
("group1", "class1", "dance1"): importMock1,
|
||||
("group2", "class2", "dance2"): importMock2,
|
||||
("group3", "class3", "dance3"): importMock3,
|
||||
}
|
||||
assert expected == structure
|
||||
|
||||
|
||||
def test_mergeHtmlData(mocker):
|
||||
person1 = worker.ResultPerson('Max 1', 'Mustermann', 'TSC Entenhausen')
|
||||
person2 = worker.ResultPerson('Max 2', 'Mustermann', 'TSC Entenhausen')
|
||||
person3 = worker.ResultPerson('Max 3', 'Mustermann', 'TSC Entenhausen')
|
||||
person4 = worker.ResultPerson('Max 4', 'Mustermann', 'TSC Entenhausen')
|
||||
person1 = worker.ResultPerson("Max 1", "Mustermann", "TSC Entenhausen")
|
||||
person2 = worker.ResultPerson("Max 2", "Mustermann", "TSC Entenhausen")
|
||||
person3 = worker.ResultPerson("Max 3", "Mustermann", "TSC Entenhausen")
|
||||
person4 = worker.ResultPerson("Max 4", "Mustermann", "TSC Entenhausen")
|
||||
|
||||
data = {
|
||||
person1: [
|
||||
worker.CompetitionResult('Rumba', 'Kin.', 'Beg.', '1', '1', 1, 'Kin./Jun.', 'Beg.'),
|
||||
worker.CompetitionResult('Cha Cha', 'Kin.', 'Adv.', '1', '1', 1, 'Kin.', 'Adv.'),
|
||||
worker.CompetitionResult('Jive', 'Kin.', 'Beg.', '1', '2', 1, 'Kin.', 'Beg.'),
|
||||
worker.CompetitionResult('Langs. Walzer', 'Kin.', 'Beg.', '1', '1', 1, 'Kin.', 'Newc./Beg.'),
|
||||
worker.CompetitionResult(
|
||||
"Rumba", "Kin.", "Beg.", "1", "1", 1, "Kin./Jun.", "Beg."
|
||||
),
|
||||
worker.CompetitionResult(
|
||||
"Cha Cha", "Kin.", "Adv.", "1", "1", 1, "Kin.", "Adv."
|
||||
),
|
||||
worker.CompetitionResult(
|
||||
"Jive", "Kin.", "Beg.", "1", "2", 1, "Kin.", "Beg."
|
||||
),
|
||||
worker.CompetitionResult(
|
||||
"Langs. Walzer", "Kin.", "Beg.", "1", "1", 1, "Kin.", "Newc./Beg."
|
||||
),
|
||||
],
|
||||
person2: [
|
||||
worker.CompetitionResult('Rumba', 'Kin.', 'Beg.', '2', '2', 2, 'Kin./Jun.', 'Beg.'),
|
||||
worker.CompetitionResult('Cha Cha', 'Kin.', 'Adv.', '2', '2', 2, 'Kin.', 'Adv.'),
|
||||
worker.CompetitionResult('Jive', 'Kin.', 'Beg.', '1', '2', 2, 'Kin.', 'Beg.'),
|
||||
worker.CompetitionResult('Langs. Walzer', 'Kin.', 'Newc.', '1', '1', 2, 'Kin.', 'Newc./Beg.'),
|
||||
worker.CompetitionResult(
|
||||
"Rumba", "Kin.", "Beg.", "2", "2", 2, "Kin./Jun.", "Beg."
|
||||
),
|
||||
worker.CompetitionResult(
|
||||
"Cha Cha", "Kin.", "Adv.", "2", "2", 2, "Kin.", "Adv."
|
||||
),
|
||||
worker.CompetitionResult(
|
||||
"Jive", "Kin.", "Beg.", "1", "2", 2, "Kin.", "Beg."
|
||||
),
|
||||
worker.CompetitionResult(
|
||||
"Langs. Walzer", "Kin.", "Newc.", "1", "1", 2, "Kin.", "Newc./Beg."
|
||||
),
|
||||
],
|
||||
person3: [
|
||||
worker.CompetitionResult('Rumba', 'Jun.', 'Beg.', '1', '1', 3, 'Kin./Jun.', 'Beg.'),
|
||||
worker.CompetitionResult(
|
||||
"Rumba", "Jun.", "Beg.", "1", "1", 3, "Kin./Jun.", "Beg."
|
||||
),
|
||||
# worker.CompetitionResult('Cha Cha', 'Jun.', 'Adv.', '1', '1', 3, 'Kin.', 'Adv.'),
|
||||
# worker.CompetitionResult('Jive', 'Jun.', 'Beg.', '2', '2', 3, 'Kin.', 'Beg.'),
|
||||
# worker.CompetitionResult('Langs. Walzer', 'Jun.', 'Newc./Beg.', '1', '1', 3, 'Kin.', 'Beg.'),
|
||||
],
|
||||
person4: [
|
||||
worker.CompetitionResult('Rumba', 'Kin.', 'Beg.', '3', '3', 4, 'Kin./Jun.', 'Beg.'),
|
||||
worker.CompetitionResult(
|
||||
"Rumba", "Kin.", "Beg.", "3", "3", 4, "Kin./Jun.", "Beg."
|
||||
),
|
||||
# worker.CompetitionResult('Cha Cha', 'Kin.', 'Adv.', '1', '1', 4, 'Kin.', 'Adv.'),
|
||||
# worker.CompetitionResult('Jive', 'Kin.', 'Beg.', '2', '2', 4, 'Kin.', 'Beg.'),
|
||||
# worker.CompetitionResult('Langs. Walzer', 'Kin.', 'Newc./Beg.', '1', '1', 4, 'Kin.', 'Beg.'),
|
||||
],
|
||||
}
|
||||
|
||||
htmlParticipant1Dance1 = html_parser.HtmlParticipant('Max 1 Mustermann', '1.', True)
|
||||
htmlParticipant1Dance2 = html_parser.HtmlParticipant('Max 1 Mustermann', '1.', True)
|
||||
htmlParticipant1Dance3 = html_parser.HtmlParticipant('Max 1 Mustermann', '1.-2.', True)
|
||||
htmlParticipant1Dance4 = html_parser.HtmlParticipant('Max 1 Mustermann', '1.', True)
|
||||
|
||||
htmlParticipant2Dance1 = html_parser.HtmlParticipant('Max 2 Mustermann', '2.', True)
|
||||
htmlParticipant2Dance2 = html_parser.HtmlParticipant('Max 2 Mustermann', '2.', True)
|
||||
htmlParticipant2Dance3 = html_parser.HtmlParticipant('Max 2 Mustermann', '1.-2.', True)
|
||||
htmlParticipant2Dance4 = html_parser.HtmlParticipant('Max 2 Mustermann', '1.', True)
|
||||
|
||||
htmlParticipant3Dance1 = html_parser.HtmlParticipant('Max 3 Mustermann', '1.', True)
|
||||
htmlParticipant1Dance1 = html_parser.HtmlParticipant("Max 1 Mustermann", "1.", True)
|
||||
htmlParticipant1Dance2 = html_parser.HtmlParticipant("Max 1 Mustermann", "1.", True)
|
||||
htmlParticipant1Dance3 = html_parser.HtmlParticipant(
|
||||
"Max 1 Mustermann", "1.-2.", True
|
||||
)
|
||||
htmlParticipant1Dance4 = html_parser.HtmlParticipant("Max 1 Mustermann", "1.", True)
|
||||
|
||||
htmlParticipant4Dance1 = html_parser.HtmlParticipant('Max 4 Mustermann', '3.', False)
|
||||
htmlParticipant2Dance1 = html_parser.HtmlParticipant("Max 2 Mustermann", "2.", True)
|
||||
htmlParticipant2Dance2 = html_parser.HtmlParticipant("Max 2 Mustermann", "2.", True)
|
||||
htmlParticipant2Dance3 = html_parser.HtmlParticipant(
|
||||
"Max 2 Mustermann", "1.-2.", True
|
||||
)
|
||||
htmlParticipant2Dance4 = html_parser.HtmlParticipant("Max 2 Mustermann", "1.", True)
|
||||
|
||||
htmlParticipant3Dance1 = html_parser.HtmlParticipant("Max 3 Mustermann", "1.", True)
|
||||
|
||||
htmlParticipant4Dance1 = html_parser.HtmlParticipant(
|
||||
"Max 4 Mustermann", "3.", False
|
||||
)
|
||||
|
||||
htmlParticipantsDance1 = {
|
||||
'1': htmlParticipant1Dance1,
|
||||
'2': htmlParticipant2Dance1,
|
||||
'3': htmlParticipant3Dance1,
|
||||
'4': htmlParticipant4Dance1
|
||||
"1": htmlParticipant1Dance1,
|
||||
"2": htmlParticipant2Dance1,
|
||||
"3": htmlParticipant3Dance1,
|
||||
"4": htmlParticipant4Dance1,
|
||||
}
|
||||
htmlParticipantsDance2 = {
|
||||
'1': htmlParticipant1Dance2,
|
||||
'2': htmlParticipant2Dance2,
|
||||
"1": htmlParticipant1Dance2,
|
||||
"2": htmlParticipant2Dance2,
|
||||
}
|
||||
htmlParticipantsDance3 = {
|
||||
'1': htmlParticipant1Dance3,
|
||||
'2': htmlParticipant2Dance3,
|
||||
"1": htmlParticipant1Dance3,
|
||||
"2": htmlParticipant2Dance3,
|
||||
}
|
||||
htmlParticipantsDance4 = {
|
||||
'1': htmlParticipant1Dance4,
|
||||
'2': htmlParticipant2Dance4,
|
||||
"1": htmlParticipant1Dance4,
|
||||
"2": htmlParticipant2Dance4,
|
||||
}
|
||||
|
||||
htmlCompetition1 = html_parser.HtmlImport('ETW, Solos Kin./Jun. Beginner Rumba', htmlParticipantsDance1)
|
||||
htmlCompetition2 = html_parser.HtmlImport('ETW, Solos Kin. Advanced Cha Cha', htmlParticipantsDance2)
|
||||
htmlCompetition3 = html_parser.HtmlImport('ETW, Solos Kinder Beginner Jive', htmlParticipantsDance3)
|
||||
htmlCompetition4 = html_parser.HtmlImport('ETW, Solos Kin. Newc./Beg. Langs. Walzer', htmlParticipantsDance4)
|
||||
|
||||
htmlCompetition1 = html_parser.HtmlImport(
|
||||
"ETW, Solos Kin./Jun. Beginner Rumba", htmlParticipantsDance1
|
||||
)
|
||||
htmlCompetition2 = html_parser.HtmlImport(
|
||||
"ETW, Solos Kin. Advanced Cha Cha", htmlParticipantsDance2
|
||||
)
|
||||
htmlCompetition3 = html_parser.HtmlImport(
|
||||
"ETW, Solos Kinder Beginner Jive", htmlParticipantsDance3
|
||||
)
|
||||
htmlCompetition4 = html_parser.HtmlImport(
|
||||
"ETW, Solos Kin. Newc./Beg. Langs. Walzer", htmlParticipantsDance4
|
||||
)
|
||||
|
||||
dataWorker = worker.DataWorker()
|
||||
|
||||
dataWorker.mergeHtmlData(data, [htmlCompetition1, htmlCompetition2, htmlCompetition3, htmlCompetition4])
|
||||
dataWorker.mergeHtmlData(
|
||||
data, [htmlCompetition1, htmlCompetition2, htmlCompetition3, htmlCompetition4]
|
||||
)
|
||||
|
||||
person1Finalist = [c.finalist for c in data[person1]]
|
||||
person2Finalist = [c.finalist for c in data[person2]]
|
||||
@@ -306,33 +465,59 @@ def test_mergeHtmlData(mocker):
|
||||
person1: [True, True, True, True],
|
||||
person2: [True, True, True, True],
|
||||
person3: [True],
|
||||
person4: [False],
|
||||
person4: [False],
|
||||
}
|
||||
|
||||
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')
|
||||
return mocker.patch("solo_turnier.worker.ResultPerson")
|
||||
|
||||
def mockDances(dances):
|
||||
def mockDance(name):
|
||||
mock = mocker.patch('solo_turnier.worker.CompetitionResult')
|
||||
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'])
|
||||
([["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]
|
||||
@@ -340,57 +525,76 @@ def test_getAllDancesInCompetitions(fixture_getAllDancesInCompetition):
|
||||
ret = dataWorker.getAllDancesInCompetitions(data)
|
||||
assert ret == fixture_getAllDancesInCompetition[1]
|
||||
|
||||
|
||||
def test_collectPersonsInGroups(mocker):
|
||||
def mockPerson(group):
|
||||
mock = mocker.patch('solo_turnier.worker.ResultPerson')
|
||||
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.')
|
||||
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]]
|
||||
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]]
|
||||
|
||||
|
||||
def test_sortPersons_withId(mocker):
|
||||
def mockPerson(id):
|
||||
mock = mocker.patch('solo_turnier.worker.ResultPerson')
|
||||
mock = mocker.patch("solo_turnier.worker.ResultPerson")
|
||||
mock.id = id
|
||||
return mock
|
||||
|
||||
persons = [mockPerson(2), mockPerson(1), mockPerson(5), mockPerson(3)]
|
||||
dataWorker = worker.DataWorker()
|
||||
sorted, showIds = dataWorker.sortPersonsInGroup(persons)
|
||||
assert sorted == [persons[1], persons[0], persons[3], persons[2]]
|
||||
assert showIds == True
|
||||
|
||||
|
||||
def test_sortPersons_withoutId(mocker):
|
||||
def mockPerson(name):
|
||||
mock = mocker.patch('solo_turnier.worker.ResultPerson')
|
||||
mock = mocker.patch("solo_turnier.worker.ResultPerson")
|
||||
mock.id = 3
|
||||
mock.name = name
|
||||
mock.club = 'TSC Entenhausen'
|
||||
mock.club = "TSC Entenhausen"
|
||||
return mock
|
||||
persons = [mockPerson('Max'), mockPerson('Isabel'), mockPerson('Reimund'), mockPerson('Anna')]
|
||||
|
||||
persons = [
|
||||
mockPerson("Max"),
|
||||
mockPerson("Isabel"),
|
||||
mockPerson("Reimund"),
|
||||
mockPerson("Anna"),
|
||||
]
|
||||
persons[2].id = None
|
||||
dataWorker = worker.DataWorker()
|
||||
sorted, showIds = dataWorker.sortPersonsInGroup(persons)
|
||||
assert sorted == [persons[3], persons[1], persons[0], persons[2]]
|
||||
assert showIds == False
|
||||
|
||||
|
||||
def test_mapPersonResultsToDanceList(mocker):
|
||||
def mockResult(dance):
|
||||
mock = mocker.patch('solo_turnier.worker.CompetitionResult')
|
||||
mock = mocker.patch("solo_turnier.worker.CompetitionResult")
|
||||
mock.dance = dance
|
||||
return mock
|
||||
dances = ['Cha Cha', 'Rumba', 'Langs. Walzer', 'Quickstep']
|
||||
results = [mockResult('Rumba'), mockResult('Quickstep'), mockResult('Cha Cha')]
|
||||
|
||||
dances = ["Cha Cha", "Rumba", "Langs. Walzer", "Quickstep"]
|
||||
results = [mockResult("Rumba"), mockResult("Quickstep"), mockResult("Cha Cha")]
|
||||
dataWorker = worker.DataWorker()
|
||||
mappedResults = dataWorker.mapPersonResultsToDanceList(results, dances)
|
||||
assert mappedResults == [results[2], results[0], None, results[1]]
|
||||
|
||||
Reference in New Issue
Block a user