Skip to content

Commit

Permalink
Support all age classes from iSonen
Browse files Browse the repository at this point in the history
Fixes #147

Signed-off-by: Stig B. Dørmænen <stigbd@gmail.com>
  • Loading branch information
stigbd committed Jan 3, 2024
1 parent 43343f6 commit 29ca601
Show file tree
Hide file tree
Showing 16 changed files with 434 additions and 301 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ In future versions:
% curl -H "Content-Type: multipart/form-data" \
-H "Authorization: Bearer $ACCESS" \
-X POST \
-F "data=@tests/files/contestants_all.csv; type=text/csv" \
-F "data=@tests/files/contestants_iSonen.csv; type=text/csv" \
http://localhost:8080/events/<event-id/contestants
% curl \
-H "Authorization: Bearer $ACCESS" \
Expand Down
7 changes: 5 additions & 2 deletions event_service/services/contestants_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,8 @@ async def validate_ageclass(ageclass: str) -> None:
regex_JGMK = r"([JGMK]\s\d*\/?\d+?\s?(år)?)"
regex_Gutter = r"(Gutter\s\d*\/?\d+?\s?(år)?)"
regex_Jenter = r"(Jenter\s\d*\/?\d+?\s?(år)?)"
regex_Kvinner_Menn = r"((Kvinner|Menn) (junior|senior))"
regex_junior = r"((Kvinner|Menn)\s\d*\/?\d+?\s?(år)?)"
regex_senior = r"((Kvinner|Menn) senior)"
regex_Felles = r"((Felles))"
regex_Para = r"((Para))"
pattern = re.compile(
Expand All @@ -550,7 +551,9 @@ async def validate_ageclass(ageclass: str) -> None:
+ "|"
+ regex_Jenter
+ "|"
+ regex_Kvinner_Menn
+ regex_junior
+ "|"
+ regex_senior
+ "|"
+ regex_Felles
+ "|"
Expand Down
18 changes: 11 additions & 7 deletions tests/contract/test_assign_bibs.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ async def test_assign_bibs(

# Then we add contestants to event:
url = f"{http_service}/events/{event_id}/contestants"
files = {"file": open("tests/files/contestants_all.csv", "rb")}
files = {"file": open("tests/files/contestants_iSonen.csv", "rb")}
async with session.post(url, headers=headers, data=files) as response:
assert response.status == 200

Expand All @@ -139,11 +139,11 @@ async def test_assign_bibs(
await _print_raceclasses(raceclasses)

# We assign ageclasses "G 16 år" and "G 15 år" to the same new raceclass "G15/16":
raceclass_G16 = await _get_raceclass_by_ageclass(raceclasses, "G 16 år")
raceclass_G15 = await _get_raceclass_by_ageclass(raceclasses, "G 15 år")
raceclass_G16 = await _get_raceclass_by_ageclass(raceclasses, "Gutter 16")
raceclass_G15 = await _get_raceclass_by_ageclass(raceclasses, "Gutter 15")
raceclass_G15_16: Dict = {
"event_id": event_id,
"name": "G15/16",
"name": "G15-16",
"ageclasses": raceclass_G15["ageclasses"] + raceclass_G16["ageclasses"],
"no_of_contestants": raceclass_G15["no_of_contestants"]
+ raceclass_G16["no_of_contestants"],
Expand Down Expand Up @@ -242,10 +242,14 @@ async def _get_raceclass_by_ageclass(raceclasses: List[Dict], ageclass: str) ->
async def _decide_group_order_and_ranking( # noqa: C901
raceclass: dict,
) -> Tuple[int, int, bool]:
if raceclass["name"] == "M19/20":
if raceclass["name"] == "KS":
return (1, 1, True)
elif raceclass["name"] == "K19/20":
elif raceclass["name"] == "MS":
return (1, 2, True)
elif raceclass["name"] == "M19-20":
return (1, 3, True)
elif raceclass["name"] == "K19-20":
return (1, 4, True)
elif raceclass["name"] == "M18":
return (2, 1, True)
elif raceclass["name"] == "K18":
Expand All @@ -254,7 +258,7 @@ async def _decide_group_order_and_ranking( # noqa: C901
return (3, 1, True)
elif raceclass["name"] == "K17":
return (3, 2, True)
elif raceclass["name"] == "G15/16":
elif raceclass["name"] == "G15-16":
return (4, 1, True)
elif raceclass["name"] == "J16":
return (4, 2, True)
Expand Down
28 changes: 12 additions & 16 deletions tests/contract/test_contestants_i_sonen.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ async def test_get_all_contestants_in_given_event_by_raceclass(
async with session.post(url, headers=headers) as response:
assert response.status == 201

raceclass_parameter = "J12"
raceclass_parameter = "J13"
url = f"{http_service}/events/{event_id}/contestants?raceclass={raceclass_parameter}"

async with session.get(url) as response:
Expand All @@ -301,9 +301,9 @@ async def test_get_all_contestants_in_given_event_by_raceclass(
assert response.status == 200, response
assert "application/json" in response.headers[hdrs.CONTENT_TYPE]
assert type(contestants) is list
assert len(contestants) == 1
assert len(contestants) == 3
for contestant in contestants:
assert contestant["ageclass"] == "Jenter 12"
assert contestant["ageclass"] == "Jenter 13"


@pytest.mark.contract
Expand All @@ -316,17 +316,17 @@ async def test_get_all_contestants_in_given_event_by_ageclass(
hdrs.AUTHORIZATION: f"Bearer {token}",
}
async with ClientSession() as session:
query_param = f'ageclass={quote("Jenter 12")}'
query_param = f'ageclass={quote("Jenter 13")}'
url = f"{http_service}/events/{event_id}/contestants"
async with session.get(f"{url}?{query_param}", headers=headers) as response:
contestants = await response.json()

assert response.status == 200
assert "application/json" in response.headers[hdrs.CONTENT_TYPE]
assert type(contestants) is list
assert len(contestants) == 1
assert len(contestants) == 3
for contestant in contestants:
assert contestant["ageclass"] == "Jenter 12"
assert contestant["ageclass"] == "Jenter 13"


@pytest.mark.contract
Expand Down Expand Up @@ -431,10 +431,14 @@ async def test_delete_all_contestant(
async def _decide_group_order_and_ranking( # noqa: C901
raceclass: dict,
) -> Tuple[int, int, bool]:
if raceclass["name"] == "M19/20":
if raceclass["name"] == "KS":
return (1, 1, True)
elif raceclass["name"] == "K19/20":
elif raceclass["name"] == "MS":
return (1, 2, True)
elif raceclass["name"] == "M19-20":
return (1, 3, True)
elif raceclass["name"] == "K19-20":
return (1, 4, True)
elif raceclass["name"] == "M18":
return (2, 1, True)
elif raceclass["name"] == "K18":
Expand Down Expand Up @@ -475,12 +479,4 @@ async def _decide_group_order_and_ranking( # noqa: C901
return (8, 1, False)
elif raceclass["name"] == "J9":
return (8, 2, False)
elif raceclass["name"] == "KJ":
return (9, 1, False)
elif raceclass["name"] == "KS":
return (9, 2, False)
elif raceclass["name"] == "MJ":
return (10, 1, False)
elif raceclass["name"] == "MS":
return (10, 2, False)
return (0, 0, True) # should not reach this point
24 changes: 14 additions & 10 deletions tests/contract/test_contestants_sportsadmin.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ async def test_create_many_contestants_as_csv_file(
}

# Send csv-file in request:
files = {"file": open("tests/files/contestants_all.csv", "rb")}
files = {"file": open("tests/files/contestants_Sportsadmin.csv", "rb")}
async with ClientSession() as session:
async with session.delete(url) as response:
pass
Expand All @@ -251,8 +251,8 @@ async def test_create_many_contestants_as_csv_file(
assert len(body) > 0

assert body["total"] == 670
assert body["created"] == 668
assert len(body["updated"]) == 2
assert body["created"] == 670
assert len(body["updated"]) == 0
assert len(body["failures"]) == 0
assert body["total"] == body["created"] + len(body["updated"]) + len(
body["failures"]
Expand All @@ -273,7 +273,7 @@ async def test_update_many_existing_contestants_as_csv_file(
}

# Send csv-file in request:
files = {"file": open("tests/files/contestants_G11.csv", "rb")}
files = {"file": open("tests/files/contestants_G11_Sportsadmin.csv", "rb")}
async with ClientSession() as session:
async with session.post(url, headers=headers, data=files) as response:
status = response.status
Expand Down Expand Up @@ -308,7 +308,7 @@ async def test_get_all_contestants_in_given_event(
assert response.status == 200
assert "application/json" in response.headers[hdrs.CONTENT_TYPE]
assert type(contestants) is list
assert len(contestants) == 668
assert len(contestants) == 670


@pytest.mark.contract
Expand All @@ -335,7 +335,7 @@ async def test_get_all_contestants_in_given_event_by_raceclass(
assert response.status == 200, response
assert "application/json" in response.headers[hdrs.CONTENT_TYPE]
assert type(contestants) is list
assert len(contestants) == 26
assert len(contestants) == 28
for contestant in contestants:
assert contestant["ageclass"] == "J 15 år"

Expand All @@ -358,7 +358,7 @@ async def test_get_all_contestants_in_given_event_by_ageclass(
assert response.status == 200
assert "application/json" in response.headers[hdrs.CONTENT_TYPE]
assert type(contestants) is list
assert len(contestants) == 26
assert len(contestants) == 28
for contestant in contestants:
assert contestant["ageclass"] == "J 15 år"

Expand Down Expand Up @@ -437,7 +437,7 @@ async def test_search_contestant_by_name(
assert response.status == 200, body
contestants = await response.json()

assert len(contestants) == 2
assert len(contestants) == 3


@pytest.mark.contract
Expand Down Expand Up @@ -465,10 +465,14 @@ async def test_delete_all_contestant(
async def _decide_group_order_and_ranking( # noqa: C901
raceclass: dict,
) -> Tuple[int, int, bool]:
if raceclass["name"] == "M19/20":
if raceclass["name"] == "MS":
return (1, 1, True)
elif raceclass["name"] == "K19/20":
elif raceclass["name"] == "KS":
return (1, 2, True)
elif raceclass["name"] == "M19/20":
return (1, 3, True)
elif raceclass["name"] == "K19/20":
return (1, 4, True)
elif raceclass["name"] == "M18":
return (2, 1, True)
elif raceclass["name"] == "K18":
Expand Down
Loading

0 comments on commit 29ca601

Please sign in to comment.