초기 커밋
This commit is contained in:
0
tests/unit/__init__.py
Normal file
0
tests/unit/__init__.py
Normal file
25
tests/unit/test_permissions.py
Normal file
25
tests/unit/test_permissions.py
Normal file
@@ -0,0 +1,25 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from app.core.constants import Role
|
||||
from app.core.permissions import can_manage_user, is_admin, is_management
|
||||
|
||||
|
||||
def test_is_admin() -> None:
|
||||
assert is_admin(Role.SUPERADMIN)
|
||||
assert is_admin(Role.ADMIN)
|
||||
assert not is_admin(Role.MANAGER)
|
||||
assert not is_admin(Role.USER)
|
||||
|
||||
|
||||
def test_is_management() -> None:
|
||||
assert is_management(Role.SUPERADMIN)
|
||||
assert is_management(Role.ADMIN)
|
||||
assert is_management(Role.MANAGER)
|
||||
assert not is_management(Role.USER)
|
||||
|
||||
|
||||
def test_can_manage_user() -> None:
|
||||
assert can_manage_user(Role.SUPERADMIN, Role.ADMIN)
|
||||
assert can_manage_user(Role.ADMIN, Role.USER)
|
||||
assert not can_manage_user(Role.USER, Role.ADMIN)
|
||||
assert not can_manage_user(Role.ADMIN, Role.ADMIN)
|
||||
40
tests/unit/test_security.py
Normal file
40
tests/unit/test_security.py
Normal file
@@ -0,0 +1,40 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from app.core.constants import TokenType
|
||||
from app.core.security import (
|
||||
create_access_token,
|
||||
create_refresh_token,
|
||||
decode_token,
|
||||
hash_password,
|
||||
verify_password,
|
||||
)
|
||||
|
||||
|
||||
def test_password_hash_and_verify() -> None:
|
||||
password = "securepassword123"
|
||||
hashed = hash_password(password)
|
||||
assert hashed != password
|
||||
assert verify_password(password, hashed)
|
||||
assert not verify_password("wrongpassword", hashed)
|
||||
|
||||
|
||||
def test_create_access_token() -> None:
|
||||
token = create_access_token(subject=1, role="admin")
|
||||
payload = decode_token(token)
|
||||
assert payload is not None
|
||||
assert payload["sub"] == "1"
|
||||
assert payload["role"] == "admin"
|
||||
assert payload["type"] == TokenType.ACCESS
|
||||
|
||||
|
||||
def test_create_refresh_token() -> None:
|
||||
token = create_refresh_token(subject=1)
|
||||
payload = decode_token(token)
|
||||
assert payload is not None
|
||||
assert payload["sub"] == "1"
|
||||
assert payload["type"] == TokenType.REFRESH
|
||||
|
||||
|
||||
def test_decode_invalid_token() -> None:
|
||||
result = decode_token("invalid.token.string")
|
||||
assert result is None
|
||||
30
tests/unit/test_statistics.py
Normal file
30
tests/unit/test_statistics.py
Normal file
@@ -0,0 +1,30 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from app.processing.utils.statistics import detect_anomalies, moving_average, percentile_stats
|
||||
|
||||
|
||||
def test_moving_average() -> None:
|
||||
values = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0]
|
||||
result = moving_average(values, window=3)
|
||||
assert len(result) == 5
|
||||
assert abs(result[0] - 2.0) < 0.001
|
||||
|
||||
|
||||
def test_moving_average_short_input() -> None:
|
||||
values = [1.0, 2.0]
|
||||
result = moving_average(values, window=5)
|
||||
assert result == values
|
||||
|
||||
|
||||
def test_detect_anomalies() -> None:
|
||||
values = [10.0, 10.1, 9.9, 10.0, 50.0, 10.0, 9.8]
|
||||
anomalies = detect_anomalies(values, threshold=2.0)
|
||||
assert len(anomalies) >= 1
|
||||
assert any(a["value"] == 50.0 for a in anomalies)
|
||||
|
||||
|
||||
def test_percentile_stats() -> None:
|
||||
values = list(range(1, 101))
|
||||
stats = percentile_stats([float(v) for v in values])
|
||||
assert abs(stats["p50"] - 50.5) < 1.0
|
||||
assert stats["p99"] > stats["p95"]
|
||||
18
tests/unit/test_validators.py
Normal file
18
tests/unit/test_validators.py
Normal file
@@ -0,0 +1,18 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from app.utils.validators import is_valid_device_uid, is_valid_email
|
||||
|
||||
|
||||
def test_valid_device_uid() -> None:
|
||||
assert is_valid_device_uid("device-001")
|
||||
assert is_valid_device_uid("SENSOR_ABC_123")
|
||||
assert not is_valid_device_uid("ab") # too short
|
||||
assert not is_valid_device_uid("device uid") # space
|
||||
assert not is_valid_device_uid("")
|
||||
|
||||
|
||||
def test_valid_email() -> None:
|
||||
assert is_valid_email("user@example.com")
|
||||
assert is_valid_email("test.user+tag@domain.co.kr")
|
||||
assert not is_valid_email("not-an-email")
|
||||
assert not is_valid_email("@domain.com")
|
||||
Reference in New Issue
Block a user