"""
Unit тесты для моделей материалов.
"""
import pytest
from apps.materials.models import Material, MaterialFolder, StorageQuota


@pytest.mark.django_db
@pytest.mark.unit
class TestMaterialModel:
    """Тесты модели Material."""
    
    def test_create_material(self, mentor_user):
        """Тест создания материала."""
        material = Material.objects.create(
            owner=mentor_user,
            title='Учебник по математике',
            description='Основы алгебры',
            material_type='document',
            file_name='math_textbook.pdf',
            file_size=1024000  # 1 MB
        )
        
        assert material.owner == mentor_user
        assert material.title == 'Учебник по математике'
        assert material.material_type == 'document'
        assert material.file_size == 1024000
    
    def test_material_soft_delete(self, mentor_user):
        """Тест мягкого удаления материала."""
        material = Material.objects.create(
            owner=mentor_user,
            title='Тест',
            material_type='document'
        )
        
        material.soft_delete()
        
        assert material.is_deleted is True
        assert Material.objects.filter(id=material.id).exists() is False
        assert Material.all_objects.filter(id=material.id).exists() is True


@pytest.mark.django_db
@pytest.mark.unit
class TestStorageQuotaModel:
    """Тесты модели StorageQuota."""
    
    def test_create_storage_quota(self, mentor_user):
        """Тест создания квоты хранилища."""
        quota = StorageQuota.objects.create(
            user=mentor_user,
            total_storage_mb=1024,  # 1 GB
            used_storage_mb=512
        )
        
        assert quota.user == mentor_user
        assert quota.total_storage_mb == 1024
        assert quota.used_storage_mb == 512
        assert quota.available_storage_mb == 512
    
    def test_quota_exceeded(self, mentor_user):
        """Тест проверки превышения квоты."""
        quota = StorageQuota.objects.create(
            user=mentor_user,
            total_storage_mb=100,
            used_storage_mb=150
        )
        
        assert quota.is_exceeded() is True
        assert quota.available_storage_mb < 0

