Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/htmx 2 #45

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 30 additions & 19 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ loguru = "^0.7.2"
uvicorn = { extras = ["standard"], version = "^0.23.2" }
httpx = "^0.25.0"
pydantic = "^2.4.2"
pytailwindcss = "^0.2.0"

[tool.poetry.group.dev.dependencies]
pytest = "^7.4.3"
Expand Down
13 changes: 10 additions & 3 deletions src/main.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from fastapi import FastAPI, File, Form, UploadFile
from jinja2_fragments.fastapi import Jinja2Blocks
from starlette.requests import Request
from starlette.staticfiles import StaticFiles
from starlette.templating import Jinja2Templates
Expand All @@ -20,14 +21,20 @@
)

app.mount("/static", StaticFiles(directory="src/static"), name="static")
templates = Jinja2Templates(directory="src//static/templates")
templates = Jinja2Templates(directory="src/static/templates")
templates_fragments = Jinja2Blocks(directory="src/static/templates")


@app.get("/")
async def root(request: Request):
return templates.TemplateResponse("home.html", {"request": request})


@app.get("/info/supported_battlescribe_versions")
async def supported_battlescribe_versions():
return 2.03


@app.post("/files/")
async def upload_roster(
request: Request,
Expand All @@ -45,11 +52,11 @@ async def upload_roster(
data = get_parser_type_and_parse(roster=upload_contents, summary_page=summary_page)

parsed_roster = data.get("roster")
template = data.get("template")
template: str = data.get("template", "")
rules_summary = data.get("rules_summary")

if use_icons:
template = "icons_" + template
template = f"icons_{template}"

return templates.TemplateResponse(
template,
Expand Down
13 changes: 13 additions & 0 deletions src/parsers/heresy/heresy.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,19 @@ def create_parsed_list(list_of_squads):


def sort_units_by_statline(squads):
"""
Sorts a list of squads by their statline type (toughness, armored, or hybrid).

Args:
squads (list): A list of squads to be sorted.

Returns:
tuple: A tuple containing the sorted squads in the following order:
- armored (list): Squads with an 'armored' statline type.
- hybrid (list): Squads with a 'hybrid' statline type.
- parsed_squads (list): All squads, parsed into a standardized format.
- toughness (list): Squads with a 'toughness' statline type.
"""
toughness = []
armored = []
hybrid = []
Expand Down
74 changes: 74 additions & 0 deletions src/parsers/heresy/heresy_parsing_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
from os import listdir
from pathlib import Path

from src.models.heresy_unit import HeresyUnit
from src.parsers.heresy.heresy_constants import TOUGHNESS
from src.utils.test_utils import fetch_and_parse_roster

base_path = Path.cwd() / "test_rosters" / "horus_heresy"


def test__heresy_loop_through_test_folder_and_parse():
"""method: fetch_and_parse_roster(horus heresy)
prerequisite: given an unzipped roster file it will parse without errors
expected: successfully parses all roster files in the test folder.
"""
parsed_rosters = []
list_of_rosters = [file for file in listdir(str(base_path)) if Path.is_file(base_path / file)]

for roster in list_of_rosters:
parsed_roster = fetch_and_parse_roster(roster_file=base_path / roster)
parsed_rosters.append(parsed_roster)

assert bool(parsed_rosters)


def test__stat_type_finder():
"""method: get_stat_type
pre-req: should find the correct stat line for a unit
expected: should return the toughness stat line.
"""
test_unit_type = "infantry"
stat_type = HeresyUnit.get_stat_type(test_unit_type)
assert stat_type == TOUGHNESS.get("name")


def test_legion_zm_list():
"""
Test a basic 1000 points night lords list
contains and HQ with a command squad + a contemptor + several infantry units
"""
hhv2_night_lords_zm = base_path / "hhv2.nightlords_zm.ros"
parsed_roster = fetch_and_parse_roster(roster_file=hhv2_night_lords_zm)

assert bool(parsed_roster) is True


def test_solar_aux_zm_list():
"""

"""
hhv2_solar_aux_zm = base_path / "hhv2.solar_aux_zm.ros"
parsed_roster = fetch_and_parse_roster(roster_file=hhv2_solar_aux_zm)

assert bool(parsed_roster) is True


def test_mechanicum_zm_list():
"""

"""
hhv2_mechanicum_zm = base_path / "hhv2.mechanicum_zm.ros"
parsed_roster = fetch_and_parse_roster(roster_file=hhv2_mechanicum_zm)

assert bool(parsed_roster) is True


def test_custodes_zm_list():
"""

"""
hhv2_custodes_zm = base_path / "hhv2.custodes_zm.ros"
parsed_roster = fetch_and_parse_roster(roster_file=hhv2_custodes_zm)

assert bool(parsed_roster) is True
74 changes: 2 additions & 72 deletions src/parsers/heresy/heresy_test.py
Original file line number Diff line number Diff line change
@@ -1,74 +1,4 @@
from os import listdir
from pathlib import Path

from src.models.heresy_unit import HeresyUnit
from src.parsers.heresy.heresy_constants import TOUGHNESS
from src.utils.test_utils import fetch_and_parse_roster

base_path = Path.cwd() / "test_rosters" / "horus_heresy"


def test__heresy_loop_through_test_folder_and_parse():
"""method: fetch_and_parse_roster(horus heresy)
prerequisite: given an unzipped roster file it will parse without errors
expected: successfully parses all roster files in the test folder.
"""
parsed_rosters = []
list_of_rosters = [file for file in listdir(str(base_path)) if Path.is_file(base_path / file)]

for roster in list_of_rosters:
parsed_roster = fetch_and_parse_roster(roster_file=base_path / roster)
parsed_rosters.append(parsed_roster)

assert bool(parsed_rosters)


def test__stat_type_finder():
"""method: get_stat_type
pre-req: should find the correct stat line for a unit
expected: should return the toughness stat line.
"""
test_unit_type = "infantry"
stat_type = HeresyUnit.get_stat_type(test_unit_type)
assert stat_type == TOUGHNESS.get("name")


def test_legion_zm_list():
"""
Test a basic 1000 points night lords list
contains and HQ with a command squad + a contemptor + several infantry units
"""
hhv2_night_lords_zm = base_path / "hhv2.nightlords_zm.ros"
parsed_roster = fetch_and_parse_roster(roster_file=hhv2_night_lords_zm)

assert bool(parsed_roster) is True


def test_solar_aux_zm_list():
"""

"""
hhv2_solar_aux_zm = base_path / "hhv2.solar_aux_zm.ros"
parsed_roster = fetch_and_parse_roster(roster_file=hhv2_solar_aux_zm)

assert bool(parsed_roster) is True


def test_mechanicum_zm_list():
"""

"""
hhv2_mechanicum_zm = base_path / "hhv2.mechanicum_zm.ros"
parsed_roster = fetch_and_parse_roster(roster_file=hhv2_mechanicum_zm)

assert bool(parsed_roster) is True


def test_custodes_zm_list():
"""

"""
hhv2_custodes_zm = base_path / "hhv2.custodes_zm.ros"
parsed_roster = fetch_and_parse_roster(roster_file=hhv2_custodes_zm)

assert bool(parsed_roster) is True
def test_sort_units_by_statline():
pass
Loading