Skip to content

Commit 373fcb5

Browse files
authored
Update all the things (#213)
* maint: updating all the things, adding more testing, more debug information
1 parent 83d4b57 commit 373fcb5

17 files changed

Lines changed: 430 additions & 77 deletions

File tree

.github/workflows/mypy.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,10 @@ jobs:
1212
runs-on: ubuntu-latest
1313
steps:
1414
- uses: actions/checkout@v5
15-
with:
16-
fetch-depth: 0 # Fetch all history for .GitInfo and .Lastmod
1715
- name: Set up Python
1816
uses: actions/setup-python@v6
1917
with:
20-
python-version: '3.12'
18+
python-version: "3.13"
2119
- name: Running mypy
2220
run: |
2321
python -m pip install --quiet --no-cache-dir --upgrade uv

.github/workflows/pylint.yml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,11 @@ jobs:
1212
runs-on: ubuntu-latest
1313
steps:
1414
- uses: actions/checkout@v5
15-
with:
16-
fetch-depth: 0 # Fetch all history for .GitInfo and .Lastmod
1715
- name: Set up Python
1816
uses: actions/setup-python@v6
1917
with:
20-
python-version: '3.12'
18+
python-version: "3.13"
2119
- name: Running tests
2220
run: |
23-
python -m pip install --quiet --no-cache-dir --upgrade uv
24-
uv run ruff check $(basename $(pwd) | sed -E 's/-/_/g') tests/
21+
python -m pip install --quiet --no-cache-dir --upgrade uv
22+
uv run ruff check $(basename $(pwd) | sed -E 's/-/_/g') tests/

.github/workflows/pytest.yml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,15 @@ jobs:
1212
runs-on: ubuntu-latest
1313
steps:
1414
- uses: actions/checkout@v5
15-
with:
16-
fetch-depth: 0 # Fetch all history for .GitInfo and .Lastmod
1715
- name: Set up Python
1816
uses: actions/setup-python@v6
1917
with:
20-
python-version: '3.12'
18+
python-version: "3.13"
2119
- name: Running pytest
20+
env:
21+
COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }}
2222
run: |
23-
python --version
2423
python -m pip install --quiet --no-cache-dir --upgrade uv
25-
uv pytest
24+
uv run pytest
25+
uv run coverage run --source=thin_controller -m pytest
26+
uv run coveralls

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,4 @@ terraform/local.tf
2424
terraform/.terraform/
2525
terraform/thin_controller_layer/
2626
terraform/*.zip
27+
.coverage

.python-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3.13

justfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ default:
44
check: lint types test
55

66
coverage:
7-
uv run coverage run -m pytest
7+
uv run coverage run --source=thin_controller -m pytest
88
uv run coveralls
99

1010

pyproject.toml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ dev = [
2727
"pytest>=8.3.5,<9.0.0",
2828
"types-boto3>=1.37.36,<2.0.0",
2929
"pyright>=1.1.400",
30+
"coverage>=7.10.7",
31+
"coveralls>=4.0.1",
32+
"pytest-cov>=7.0.0",
33+
"httpx>=0.28.1",
3034
]
3135

3236

@@ -37,6 +41,7 @@ thin-controller = "thin_controller.__main__:cli"
3741

3842
[tool.pylint.MASTER]
3943
max-line-length = 200
44+
load-plugins = "pylint_pytest"
4045

4146
[tool.pytest.ini_options]
4247
testpaths = ["tests"]
@@ -48,4 +53,8 @@ plugins = "pydantic.mypy"
4853
exclude = ["terraform", ".venv"]
4954

5055
[tool.coverage.run]
51-
omit = ["tests/*", "terraform/*"]
56+
omit = [
57+
"tests/*", # don't test the tests
58+
"terraform/*", # no python here
59+
"thin_controller/handler.py", # only a stub for the Lambda handler
60+
]

terraform/main.tf

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ resource "terraform_data" "thin_controller_layer" {
77
triggers_replace = data.archive_file.thin_controller_layer
88

99
provisioner "local-exec" {
10-
command = "python3.12 -m pip install --upgrade -t ./thin_controller_layer/ ../"
10+
command = "python3.13 -m pip install --upgrade -t ./thin_controller_layer/ ../"
1111
}
1212

1313
}
@@ -22,7 +22,7 @@ resource "aws_lambda_layer_version" "thin_controller" {
2222
layer_name = "thin_controller"
2323

2424
compatible_runtimes = [
25-
"python3.12"
25+
"python3.13"
2626
]
2727
}
2828

@@ -32,7 +32,7 @@ module "thin_controller_module" {
3232

3333
function_name = "thin_controller"
3434
lambda_handler = "handler.handler"
35-
lambda_runtime = "python3.12"
35+
lambda_runtime = "python3.13"
3636

3737
aws_region = var.aws_region
3838
aws_profile = var.aws_profile
@@ -99,4 +99,4 @@ module "thin_controller_module" {
9999
# }
100100
# }
101101

102-
# }
102+
# }

tests/test_api.py

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
"""test API things"""
2+
3+
import os
4+
import sys
5+
6+
from fastapi.testclient import TestClient
7+
import pytest
8+
from loguru import logger
9+
from thin_controller import app
10+
11+
logger.remove()
12+
logger.add(sys.stderr, level="DEBUG")
13+
14+
15+
@pytest.fixture(scope="function")
16+
def client() -> TestClient:
17+
"""Create a test client for the FastAPI app."""
18+
return TestClient(app)
19+
20+
21+
def test_index(client: TestClient) -> None:
22+
"""Test the main endpoint."""
23+
24+
response = client.get("/")
25+
assert response.status_code == 200
26+
assert "Thin Controller" in response.content.decode()
27+
28+
29+
def test_css(client: TestClient) -> None:
30+
"""Test the main endpoint."""
31+
32+
for url in ["/css/styles.css", "/css/simple.min.css"]:
33+
response = client.get(url)
34+
assert response.status_code == 200
35+
36+
assert client.get("/css/doesnotexist.css").status_code == 404
37+
38+
39+
def test_favicon(client: TestClient) -> None:
40+
"""Test the favicon endpoint."""
41+
42+
response = client.get("/img/favicon.png")
43+
assert response.status_code == 200
44+
45+
assert client.get("/img/doesnotexist.png").status_code == 404
46+
47+
48+
def test_api_config(client: TestClient) -> None:
49+
"""Test the config endpoint."""
50+
51+
response = client.get("/api/config")
52+
assert response.status_code == 200
53+
assert "regions" in response.json()
54+
55+
56+
def test_read_instance(client: TestClient) -> None:
57+
"""Test the instance read endpoint."""
58+
59+
response = client.get("/api/instances")
60+
print(response.content)
61+
if os.getenv("AWS_ACCESS_KEY_ID") is None:
62+
assert response.status_code == 500
63+
else:
64+
assert response.status_code == 200
65+
assert isinstance(response.json(), dict)

tests/test_main.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
"""testing the main func"""
2+
3+
from thin_controller.__main__ import cli
4+
5+
6+
def test_cli_help() -> None:
7+
"""Test that the CLI help command works."""
8+
result = cli(["--help"], standalone_mode=False)
9+
assert result == 0

0 commit comments

Comments
 (0)