-
Notifications
You must be signed in to change notification settings - Fork 0
Added unit tests for client & API #2
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
Merged
Merged
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
b2d7c3d
feat: Added empty seed raise Exception
spuerta10 094286c
chore: Added init modules
spuerta10 79df9dd
chore: Added no cover to __name__ == __main__
spuerta10 85ea219
feat: Added tests for client application
spuerta10 5734217
chore: Added tests dependencies
spuerta10 0cc9d06
feat: Added install dependencies step to pipeline
spuerta10 bde206d
fix: Pass --system to uv dependencies install
spuerta10 dab5cdc
fix: Created venv since runners dont allow system package modifications
spuerta10 a9e22d1
fix: Fixed env vars for DB user, password and name
spuerta10 4b9824d
fix: Fixed API execution with fixed imports
spuerta10 68144bf
fix: Fixed imports to work with pytest
spuerta10 b146078
chore: Added python version file
spuerta10 a3367dd
chore: Added pytest path resolve file
spuerta10 527f937
chore: Added init modules for API tests
spuerta10 457c60d
chore: Added empty file for testing ticket repository
spuerta10 5c4e718
feat: Added unit tests for ticket repository
spuerta10 210f3be
feat: Added unit tests for ticket repository
spuerta10 bcec13e
chore: Added option explanation comment
spuerta10 d69dad0
feat: Added unit test for ticket service
spuerta10 19b30e0
chore: Added init module
spuerta10 2be6e07
chore: Added pytest asyncio to dependencies
spuerta10 5fe1dad
feat: Added unit tests for user repository
spuerta10 0b4163a
chore: Added tools cache folders to ignore
spuerta10 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,7 @@ | ||
| __pycache__* | ||
| *.env* | ||
| *.env* | ||
| .mypy_cache/ | ||
| .pytest_cache/ | ||
| .ruff_cache/ | ||
| .venv/ | ||
| venv/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| 3.11 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| [pytest] | ||
| pythonpath = src | ||
| testpaths = tests | ||
| # avoid marking each async test | ||
| asyncio_mode = auto |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,3 @@ | ||
| from controllers.tickets_controller import TicketsController | ||
| from register_ticket_api.controllers.tickets_controller import TicketsController | ||
|
|
||
| __all__ = ["TicketsController"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| from entities.attedance_log import AttendanceLog | ||
| from entities.ticket import Ticket | ||
| from entities.user import User | ||
| from register_ticket_api.entities.attedance_log import AttendanceLog | ||
| from register_ticket_api.entities.ticket import Ticket | ||
| from register_ticket_api.entities.user import User | ||
|
|
||
| __all__ = ["AttendanceLog", "Ticket", "User"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,4 @@ | ||
| from exceptions.app_validation_exception import AppValidationException | ||
|
|
||
| from .db_operation_exception import DbOperationException | ||
| from register_ticket_api.exceptions.app_validation_exception import AppValidationException | ||
| from register_ticket_api.exceptions.db_operation_exception import DbOperationException | ||
|
|
||
| __all__ = ["AppValidationException", "DbOperationException"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,3 @@ | ||
| from infraestructure.postgresql_db_context import PostgreSQLDbContext | ||
| from register_ticket_api.infraestructure.postgresql_db_context import PostgreSQLDbContext | ||
|
|
||
| __all__ = ["PostgreSQLDbContext"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| from interfaces.i_ticket_repository import ITicketRepository | ||
| from interfaces.i_user_repository import IUserRepository | ||
| from register_ticket_api.interfaces.i_ticket_repository import ITicketRepository | ||
| from register_ticket_api.interfaces.i_user_repository import IUserRepository | ||
|
|
||
| __all__ = ["ITicketRepository", "IUserRepository"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| from repositories.ticket_repository import TicketRepository | ||
| from repositories.user_repository import UserRepository | ||
| from register_ticket_api.repositories.ticket_repository import TicketRepository | ||
| from register_ticket_api.repositories.user_repository import UserRepository | ||
|
|
||
| __all__ = ["TicketRepository", "UserRepository"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| from services.ticket_service import TicketService | ||
| from services.user_service import UserService | ||
| from register_ticket_api.services.ticket_service import TicketService | ||
| from register_ticket_api.services.user_service import UserService | ||
|
|
||
| __all__ = ["TicketService", "UserService"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Empty file.
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| from base64 import b64encode | ||
| from datetime import datetime, timezone | ||
| from unittest.mock import patch | ||
|
|
||
| import pytest | ||
| from pyotp import TOTP | ||
|
|
||
| from src.client.totp_generator import TOTPGenerator | ||
|
|
||
| VALID_SEED_BYTES: bytes = b"test_secret_key_" | ||
| VALID_SEED_BASE64: str = b64encode(VALID_SEED_BYTES).decode("utf-8") | ||
| INVALID_BASE_64_SEED: str = "invalid!@#$" | ||
| EXPECTED_CODE_LENGTH: int = 6 | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def totp_generator() -> TOTPGenerator: | ||
| return TOTPGenerator(seed_base64=VALID_SEED_BASE64) | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def base_time() -> datetime: | ||
| """Fixed base time for tests.""" | ||
| return datetime(2024, 1, 1, 12, 0, 0, tzinfo=timezone.utc) | ||
|
|
||
|
|
||
| def test_init_with_valid_base64() -> None: | ||
| """Test TOTPGenerator initialization with valid seed.""" | ||
| gen = TOTPGenerator(seed_base64=VALID_SEED_BASE64) | ||
|
|
||
| assert gen._TOTPGenerator__totp is not None # type: ignore[attr-defined] | ||
| assert isinstance(gen._TOTPGenerator__totp, TOTP) # type: ignore[attr-defined] | ||
|
|
||
|
|
||
| def test_init_with_invalid_base64() -> None: | ||
| """Test TOTPGenerator initialization with invalid base64 seed raises exception.""" | ||
| with pytest.raises(ValueError): # b64decode raises binascii.Error | ||
| TOTPGenerator(seed_base64=INVALID_BASE_64_SEED) | ||
|
|
||
|
|
||
| def test_empty_seed_raises_error() -> None: | ||
| """Test that empty seed raises an error.""" | ||
| with pytest.raises(ValueError): | ||
| TOTPGenerator(seed_base64="") | ||
|
|
||
|
|
||
| def test_generate_code_returns_string(totp_generator: TOTPGenerator) -> None: | ||
| """Test that generate_code returns a string.""" | ||
| code: str = totp_generator.generate_code() | ||
|
|
||
| assert isinstance(code, str) | ||
| assert len(code) == EXPECTED_CODE_LENGTH | ||
| assert code.isdigit() | ||
|
|
||
|
|
||
| def test_generate_code_changes_over_time( | ||
| base_time: datetime, totp_generator: TOTPGenerator | ||
| ) -> None: | ||
| """Test that code changes at the exact interval boundary.""" | ||
| with patch("pyotp.totp.datetime") as mock_time: | ||
| from datetime import timedelta | ||
|
|
||
| # first code at time 0 | ||
| mock_time.datetime.now.return_value = base_time | ||
| code1 = totp_generator.generate_code() | ||
|
|
||
| # second code at t=TOTP_INTERVAL_SECONDS | ||
| mock_time.datetime.now.return_value = base_time + timedelta( | ||
| seconds=totp_generator.TOTP_INTERVAL_SECONDS | ||
| ) | ||
| code2 = totp_generator.generate_code() | ||
|
|
||
| assert code1 != code2 |
Empty file.
Empty file.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: Return type annotation is now less specific; consider restoring type clarity.
If the function always returns a boolean, please annotate the return type as 'bool' for better maintainability and static analysis.