Testing
This commit is contained in:
4
.flake8
Normal file
4
.flake8
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
[flake8]
|
||||||
|
#ignore = E226,E302,E41
|
||||||
|
max-line-length = 130
|
||||||
|
max-complexity = 10
|
||||||
8
.github/workflows/linters.yml
vendored
8
.github/workflows/linters.yml
vendored
@@ -5,7 +5,7 @@ on:
|
|||||||
branches:
|
branches:
|
||||||
- Development
|
- Development
|
||||||
jobs:
|
jobs:
|
||||||
on-success:
|
check:
|
||||||
if: ${{ github.event.workflow_run.conclusion == 'success' }}
|
if: ${{ github.event.workflow_run.conclusion == 'success' }}
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
@@ -27,9 +27,3 @@ jobs:
|
|||||||
|
|
||||||
- name: Run pylint
|
- name: Run pylint
|
||||||
run: pylint frontend services utils
|
run: pylint frontend services utils
|
||||||
|
|
||||||
on-failure:
|
|
||||||
if: ${{ github.event.workflow_run.conclusion == 'failure' }}
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- run: echo 'The Review workflow failed'
|
|
||||||
|
|||||||
8
.github/workflows/unit-test.yml
vendored
8
.github/workflows/unit-test.yml
vendored
@@ -6,7 +6,7 @@ on:
|
|||||||
- main
|
- main
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
on-success:
|
Unit-Test:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
|
|
||||||
@@ -29,9 +29,3 @@ jobs:
|
|||||||
# 6. Run unit tests
|
# 6. Run unit tests
|
||||||
- name: Run pytest
|
- name: Run pytest
|
||||||
run: pytest
|
run: pytest
|
||||||
|
|
||||||
on-failure:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
if: ${{ github.event.workflow_run.conclusion == 'failure' }}
|
|
||||||
steps:
|
|
||||||
- run: echo 'The triggering workflow failed'
|
|
||||||
|
|||||||
BIN
config/__pycache__/database.cpython-312.pyc
Normal file
BIN
config/__pycache__/database.cpython-312.pyc
Normal file
Binary file not shown.
BIN
database/__pycache__/__init__.cpython-312.pyc
Normal file
BIN
database/__pycache__/__init__.cpython-312.pyc
Normal file
Binary file not shown.
BIN
database/__pycache__/flask_integration.cpython-312.pyc
Normal file
BIN
database/__pycache__/flask_integration.cpython-312.pyc
Normal file
Binary file not shown.
BIN
database/__pycache__/interface.cpython-312.pyc
Normal file
BIN
database/__pycache__/interface.cpython-312.pyc
Normal file
Binary file not shown.
BIN
database/__pycache__/sqlite_db.cpython-312.pyc
Normal file
BIN
database/__pycache__/sqlite_db.cpython-312.pyc
Normal file
Binary file not shown.
@@ -1,6 +1,6 @@
|
|||||||
import logging
|
import logging
|
||||||
|
|
||||||
from flask import current_app, g
|
from flask import g
|
||||||
|
|
||||||
from .interface import DatabaseInterface
|
from .interface import DatabaseInterface
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
from abc import ABC, abstractmethod
|
from abc import ABC, abstractmethod
|
||||||
from typing import Any, Dict, List, Optional
|
from typing import Any, Dict, Optional
|
||||||
|
|
||||||
|
|
||||||
class DatabaseInterface(ABC):
|
class DatabaseInterface(ABC):
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ class SQLiteDatabase(DatabaseInterface):
|
|||||||
self._local.connection.execute("PRAGMA synchronous=NORMAL")
|
self._local.connection.execute("PRAGMA synchronous=NORMAL")
|
||||||
self._local.connection.execute("PRAGMA cache_size=1000")
|
self._local.connection.execute("PRAGMA cache_size=1000")
|
||||||
self._local.connection.execute("PRAGMA temp_store=MEMORY")
|
self._local.connection.execute("PRAGMA temp_store=MEMORY")
|
||||||
logger.debug(f"New SQLite connection created for thread")
|
logger.debug("New SQLite connection created for thread")
|
||||||
|
|
||||||
return self._local.connection
|
return self._local.connection
|
||||||
|
|
||||||
@@ -61,14 +61,14 @@ class SQLiteDatabase(DatabaseInterface):
|
|||||||
try:
|
try:
|
||||||
cursor.execute(
|
cursor.execute(
|
||||||
"""
|
"""
|
||||||
CREATE TABLE IF NOT EXISTS users
|
CREATE TABLE IF NOT EXISTS users
|
||||||
(
|
(
|
||||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
username TEXT NOT NULL UNIQUE,
|
username TEXT NOT NULL UNIQUE,
|
||||||
email TEXT NOT NULL UNIQUE,
|
email TEXT NOT NULL UNIQUE,
|
||||||
password_hash TEXT NOT NULL,
|
password_hash TEXT NOT NULL,
|
||||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP )
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP )
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
conn.commit()
|
conn.commit()
|
||||||
logger.info("User table created/verified")
|
logger.info("User table created/verified")
|
||||||
|
|||||||
BIN
frontend/__pycache__/app.cpython-312.pyc
Normal file
BIN
frontend/__pycache__/app.cpython-312.pyc
Normal file
Binary file not shown.
BIN
services/__pycache__/__init__.cpython-312.pyc
Normal file
BIN
services/__pycache__/__init__.cpython-312.pyc
Normal file
Binary file not shown.
BIN
services/__pycache__/auth_service.cpython-312.pyc
Normal file
BIN
services/__pycache__/auth_service.cpython-312.pyc
Normal file
Binary file not shown.
BIN
services/__pycache__/user_service.cpython-312.pyc
Normal file
BIN
services/__pycache__/user_service.cpython-312.pyc
Normal file
Binary file not shown.
@@ -12,39 +12,38 @@ class UserService:
|
|||||||
def __init__(self, database: DatabaseInterface):
|
def __init__(self, database: DatabaseInterface):
|
||||||
self.db = database
|
self.db = database
|
||||||
|
|
||||||
def create_user(
|
def create_user(self, username: str, email: str, password: str) -> tuple[bool, list[str]]:
|
||||||
self, username: str, email: str, password: str
|
errors = self._validate_user_inputs(username, email, password)
|
||||||
) -> tuple[bool, list[str]]:
|
if errors:
|
||||||
errors = []
|
return False, errors
|
||||||
|
|
||||||
# Validierung
|
errors = self._check_user_existence(username, email)
|
||||||
|
if errors:
|
||||||
|
return False, errors
|
||||||
|
|
||||||
|
password_hash = PasswordUtils.hash_password_simple(password)
|
||||||
|
return self._attempt_user_creation(username, email, password_hash)
|
||||||
|
|
||||||
|
def _validate_user_inputs(self, username: str, email: str, password: str) -> list[str]:
|
||||||
|
errors = []
|
||||||
if not ValidationUtils.validate_username(username):
|
if not ValidationUtils.validate_username(username):
|
||||||
errors.append("Invalid username format")
|
errors.append("Invalid username format")
|
||||||
|
|
||||||
if not ValidationUtils.validate_email(email):
|
if not ValidationUtils.validate_email(email):
|
||||||
errors.append("Invalid email format")
|
errors.append("Invalid email format")
|
||||||
|
|
||||||
password_valid, password_errors = ValidationUtils.validate_password(password)
|
password_valid, password_errors = ValidationUtils.validate_password(password)
|
||||||
if not password_valid:
|
if not password_valid:
|
||||||
errors.extend(password_errors)
|
errors.extend(password_errors)
|
||||||
|
return errors
|
||||||
|
|
||||||
if errors:
|
def _check_user_existence(self, username: str, email: str) -> list[str]:
|
||||||
return False, errors
|
errors = []
|
||||||
|
|
||||||
# Prüfe auf existierende User
|
|
||||||
if self.get_user_by_email(email):
|
if self.get_user_by_email(email):
|
||||||
errors.append("Email already registered")
|
errors.append("Email already registered")
|
||||||
|
|
||||||
if self.get_user_by_username(username):
|
if self.get_user_by_username(username):
|
||||||
errors.append("Username already taken")
|
errors.append("Username already taken")
|
||||||
|
return errors
|
||||||
|
|
||||||
if errors:
|
def _attempt_user_creation(self, username: str, email: str, password_hash: str) -> tuple[bool, list[str]]:
|
||||||
return False, errors
|
|
||||||
|
|
||||||
# Passwort hashen
|
|
||||||
password_hash = PasswordUtils.hash_password_simple(password)
|
|
||||||
|
|
||||||
# User erstellen
|
|
||||||
try:
|
try:
|
||||||
success = self.db.create_user(username, email.lower(), password_hash)
|
success = self.db.create_user(username, email.lower(), password_hash)
|
||||||
if success:
|
if success:
|
||||||
|
|||||||
BIN
utils/__pycache__/__init__.cpython-312.pyc
Normal file
BIN
utils/__pycache__/__init__.cpython-312.pyc
Normal file
Binary file not shown.
BIN
utils/__pycache__/auth_decorators.cpython-312.pyc
Normal file
BIN
utils/__pycache__/auth_decorators.cpython-312.pyc
Normal file
Binary file not shown.
BIN
utils/__pycache__/password_utils.cpython-312.pyc
Normal file
BIN
utils/__pycache__/password_utils.cpython-312.pyc
Normal file
Binary file not shown.
BIN
utils/__pycache__/validation.cpython-312.pyc
Normal file
BIN
utils/__pycache__/validation.cpython-312.pyc
Normal file
Binary file not shown.
Reference in New Issue
Block a user