Skip to content

Commit a0c4af4

Browse files
authored
Merge pull request #2 from spuerta10/feat/unit-tests
Added unit tests for client & API
2 parents 64ce8c9 + 0b4163a commit a0c4af4

36 files changed

Lines changed: 791 additions & 46 deletions

.github/workflows/static-code-analysis.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ jobs:
2020
- name: Run Static Code Analysis
2121
run: uvx pre-commit run --all-files --show-diff-on-failure --color=always
2222

23+
- name: Install dependencies
24+
run: |
25+
uv venv
26+
uv pip install -r requirements.txt
27+
2328
- name: Run unit tests (with coverage report)
2429
if: ${{ inputs.coverage_artifact }}
2530
run: uv run pytest --cov=./src --cov-report=xml --cov-report=term

.gitignore

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,7 @@
11
__pycache__*
2-
*.env*
2+
*.env*
3+
.mypy_cache/
4+
.pytest_cache/
5+
.ruff_cache/
6+
.venv/
7+
venv/

.python-version

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

docker/Dockerfile.register-ticket-api

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ COPY requirements.txt .
77

88
RUN pip install --no-cache-dir -r requirements.txt
99

10-
COPY src/register_ticket_api/ ./register_tickets_api/
10+
COPY src/register_ticket_api/ ./register_ticket_api/
1111

12-
CMD ["python", "register_tickets_api/main.py"]
12+
CMD ["python", "-m", "register_ticket_api.main"]

docker/docker-compose.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1+
# docker compose -f docker/docker-compose.yml --env-file .env up --build
2+
13
version: '3.9'
24
services:
35
postgres:
46
image: postgres:latest
57
environment:
6-
POSTGRES_USER: {POSTGRES_USER}
7-
POSTGRES_PASSWORD: {POSTGRES_PASSWORD} # define in execution time
8-
POSTGRES_DB: {POSTGRES_DB}
8+
POSTGRES_USER: ${DB_USER}
9+
POSTGRES_PASSWORD: ${DB_PASSWORD} # define in execution time
10+
POSTGRES_DB: ${DB_NAME}
911
volumes:
1012
- ../src/db/scripts:/docker-entrypoint-initdb.d
1113
ports:

pytest.ini

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[pytest]
2+
pythonpath = src
3+
testpaths = tests
4+
# avoid marking each async test
5+
asyncio_mode = auto

requirements.txt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,41 @@ annotated-types==0.7.0
22
anyio==4.11.0
33
asyncpg==0.30.0
44
certifi==2025.8.3
5+
cfgv==3.4.0
56
click==8.3.0
7+
coverage==7.10.7
8+
distlib==0.4.0
69
dotenv==0.9.9
710
elastic-transport==9.1.0
811
elasticsearch==9.1.1
912
fastapi==0.117.1
13+
filelock==3.20.0
1014
h11==0.16.0
15+
identify==2.6.15
1116
idna==3.10
17+
iniconfig==2.1.0
1218
loguru==0.7.3
19+
nodeenv==1.9.1
20+
packaging==25.0
21+
platformdirs==4.5.0
22+
pluggy==1.6.0
23+
pre-commit==4.3.0
1324
pydantic==2.11.9
1425
pydantic-core==2.33.2
1526
pydantic-settings==2.10.1
27+
pygments==2.19.2
1628
pyotp==2.9.0
29+
pytest==8.4.2
30+
pytest-asyncio==1.2.0
31+
pytest-cov==7.0.0
1732
python-dateutil==2.9.0.post0
1833
python-dotenv==1.1.1
34+
pyyaml==6.0.3
1935
six==1.17.0
2036
sniffio==1.3.1
2137
starlette==0.48.0
2238
typing-extensions==4.15.0
2339
typing-inspection==0.4.1
2440
urllib3==2.5.0
2541
uvicorn==0.37.0
42+
virtualenv==20.35.3

src/__init__.py

Whitespace-only changes.

src/client/__init__.py

Whitespace-only changes.

src/client/totp_generator.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ class TOTPGenerator:
99
TOTP_INTERVAL_SECONDS: ClassVar[int] = 60
1010

1111
def __init__(self, seed_base64: str) -> None:
12+
if not seed_base64:
13+
raise ValueError("Seed cannot be empty")
1214
bytes_seed: bytes = b64decode(seed_base64)
1315
seed_base32 = b32encode(bytes_seed).decode("utf-8")
1416
self.__totp = TOTP(seed_base32, interval=self.TOTP_INTERVAL_SECONDS)
@@ -17,7 +19,7 @@ def generate_code(self) -> str:
1719
return str(self.__totp.now())
1820

1921

20-
if __name__ == "__main__":
22+
if __name__ == "__main__": # pragma: no cover
2123
parser = ArgumentParser(description="Genera un código TOTP desde una semilla hexadecimal")
2224
parser.add_argument("seed", type=str, help="Seed en hexadecimal (sin 0x)")
2325
args = parser.parse_args()

0 commit comments

Comments
 (0)