Слишком переусложненная структура - но оставим для будущего

This commit is contained in:
ki.sagidullin
2026-04-05 10:05:03 +05:00
parent 018e2a860e
commit f916d764c0
48 changed files with 2222 additions and 5 deletions

1
tests/__init__.py Normal file
View File

@@ -0,0 +1 @@
"""Tests package."""

View File

@@ -0,0 +1 @@
"""Integration tests package."""

137
tests/test_models.py Normal file
View File

@@ -0,0 +1,137 @@
"""Тест моделей данных для операторов и смен"""
import sys
sys.path.insert(0, 'src')
from datetime import date, datetime
from domains.models.operator import Operator, ShiftType
from domains.models.shift import Shift, ShiftTypeEnum
from domains.models.preference import OperatorPreferences, Preference
def test_operator():
"""Тест модели оператора"""
print("=" * 60)
print("TEST: Model Operator")
print("=" * 60)
# Создание оператора
operator = Operator(
id="OP001",
name="Иванов Иван Иванович",
department="Склад",
email="ivanov@company.com",
skills=["Morning", "Afternoon", "Evening"],
preferred_days=[1, 2, 3, 4, 5],
max_shifts_per_week=4,
max_weekly_hours=32
)
print(f"\nOperator: {operator}")
print(f"ID: {operator.id}")
print(f"Name: {operator.name}")
print(f"Department: {operator.department}")
print(f"Skills: {operator.skills}")
print(f"Preferred days: {operator.preferred_days}")
print(f"Can work 'Night' shift: {operator.can_work_shift(ShiftType.NIGHT)}")
# Проверка доступности
availability = operator.get_availability()
print(f"\nAvailability info:")
print(f" Total shifts assigned: {availability['total_shifts_assigned']}")
print(f" Available for assignment: {availability['available_for_assignment']}")
def test_shift():
"""Тест модели смены"""
print("\n" + "=" * 60)
print("TEST: Model Shift")
print("=" * 60)
# Создание смены
shift_date = date(2024, 12, 9) # Пятница
shift = Shift(
date=shift_date, # Используем datetime.date объект
shift_type=ShiftTypeEnum.AFTERNOON,
start_time="14:00",
end_time="22:00",
department_required="Склад",
required_skills=["Evening"],
min_operators=2,
max_operators=4,
description="Вечерняя смена на складе"
)
print(f"\nShift: {shift}")
print(f"Date: {shift.date}")
print(f"Type: {shift.shift_type}")
print(f"Start time: {shift.start_time}")
print(f"End time: {shift.end_time}")
print(f"Duration (hours): {shift.duration_hours}")
# Проверка совместимости
op = Operator(
id="OP001",
name="Иванов",
skills=["Afternoon"]
)
is_available = shift.is_available(op)
print(f"\nOperator {op.name} available for this shift: {is_available}")
def test_preferences():
"""Тест модели предпочтений"""
print("\n" + "=" * 60)
print("TEST: Model Preferences")
print("=" * 60)
# Создание предпочтений
prefs = OperatorPreferences(
operator_id="OP001",
shift_preferences=[],
day_preferences=[],
time_preferences=[],
rest_preferences=[],
sequence_preferences=[]
)
# Добавление предпочтений
prefs.add_shift_preference(
ShiftType.MORNING,
strength=80,
reason="Хочу работать утром"
)
prefs.add_day_preference(
{1, 2, 3}, # Пн-Ср
strength=70,
reason="Лучше работать в начале недели"
)
prefs.add_time_preference(
ShiftType.MORNING,
strength=75,
reason="Вечерная работа - не хочу"
)
print(f"\nNumber of shift preferences: {len(prefs.shift_preferences)}")
print(f"Number of day preferences: {len(prefs.day_preferences)}")
# Получение лучших предпочтений
best_shift = prefs.get_best_shift_type()
best_days = prefs.get_best_days()
print(f"Best shift type: {best_shift}")
print(f"Best days: {best_days}")
def test_all():
"""Запуск всех тестов"""
test_operator()
test_shift()
test_preferences()
print("\n" + "=" * 60)
print("All tests passed! ✓")
print("=" * 60)
if __name__ == "__main__":
test_all()

1
tests/unit/__init__.py Normal file
View File

@@ -0,0 +1 @@
"""Unit tests package."""