diff --git a/.gitignore b/.gitignore index c1491a0..613d039 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ **/.terraform.lock.hcl **/*.tfstate **/*.tfstate.backup +__pycache__/ \ No newline at end of file diff --git a/main.py b/main.py index 6ebc046..974797e 100644 --- a/main.py +++ b/main.py @@ -1,6 +1,5 @@ import datetime from http import HTTPStatus -from tabnanny import check from typing import Annotated import uvicorn diff --git a/projects.py b/projects.py index 60fc82e..236d196 100644 --- a/projects.py +++ b/projects.py @@ -140,7 +140,7 @@ def add_team_to_project(team_id: str, project_id: str) -> None: if team_id not in team_ids: cur.execute(""" - INSERT INTO project_teams VALUES (2, %s, %s)""", + INSERT INTO project_teams(team_id, project_id) VALUES (%s, %s)""", (team_id, project_id)) except Exception as e: logger.error(e) diff --git a/tests/python/unit_tests/test_auth_functions.py b/tests/python/unit_tests/test_auth_functions.py new file mode 100644 index 0000000..c68d627 --- /dev/null +++ b/tests/python/unit_tests/test_auth_functions.py @@ -0,0 +1,34 @@ +import pytest +import time +from unittest.mock import patch, MagicMock +from backend.auth_functions import ( + decode_token, get_user, get_authenticated_user, + user_exists, register_user, update_user_token, disable_user +) +from backend.user import User + +@pytest.fixture +def mock_db_conn(monkeypatch): + mock_conn = MagicMock() + mock_cursor = MagicMock() + mock_conn.__enter__.return_value = mock_conn + mock_conn.cursor.return_value.__enter__.return_value = mock_cursor + monkeypatch.setattr('backend.auth_functions.get_db_connection', lambda: mock_conn) + return mock_cursor + +def test_user_exists_true(monkeypatch): + monkeypatch.setattr('backend.auth_functions.get_user', lambda username: User(username='user', sha512_hash='hash', salt='salt')) + assert user_exists(User(username='user', sha512_hash='hash', salt='salt')) + +def test_user_exists_false(monkeypatch): + monkeypatch.setattr('backend.auth_functions.get_user', lambda username: None) + assert not user_exists(User(username='nouser', sha512_hash='hash', salt='salt')) + +def test_register_user_success(mock_db_conn): + user = User(username='user', sha512_hash='hash', salt='salt') + try: + register_user(user) + except Exception: + pytest.fail('register_user raised Exception unexpectedly!') + +# Ajoute d'autres tests pour update_user_token, disable_user, etc. diff --git a/tests/python/unit_tests/unit_tests.py b/tests/python/unit_tests/unit_tests.py new file mode 100644 index 0000000..e69de29