Skip to content
Open
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@
**/.terraform.lock.hcl
**/*.tfstate
**/*.tfstate.backup
__pycache__/
1 change: 0 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import datetime
from http import HTTPStatus
from tabnanny import check
from typing import Annotated

import uvicorn
Expand Down
2 changes: 1 addition & 1 deletion projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
34 changes: 34 additions & 0 deletions tests/python/unit_tests/test_auth_functions.py
Original file line number Diff line number Diff line change
@@ -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.
Empty file.
Loading