"""
API тесты для домашних заданий.
"""
import pytest
from rest_framework import status
from apps.homework.models import Homework, HomeworkSubmission


@pytest.mark.django_db
@pytest.mark.api
class TestHomeworkAPI:
    """Тесты API домашних заданий."""
    
    def test_list_homeworks(self, authenticated_client, mentor_user):
        """Тест получения списка домашних заданий."""
        Homework.objects.create(
            mentor=mentor_user,
            title='Задание 1',
            description='Описание',
            status='published'
        )
        
        response = authenticated_client.get('/api/homework/homeworks/')
        
        assert response.status_code == status.HTTP_200_OK
        assert len(response.data['results']) > 0
    
    def test_create_homework(self, authenticated_client, mentor_user):
        """Тест создания домашнего задания."""
        data = {
            'title': 'Новое задание',
            'description': 'Описание задания',
            'max_score': 100
        }
        
        response = authenticated_client.post('/api/homework/homeworks/', data)
        
        assert response.status_code == status.HTTP_201_CREATED
        assert response.data['title'] == 'Новое задание'
    
    def test_submit_homework(self, authenticated_client_user, mentor_user, client_user):
        """Тест отправки решения домашнего задания."""
        homework = Homework.objects.create(
            mentor=mentor_user,
            title='Задание',
            description='Описание',
            status='published'
        )
        
        data = {
            'homework': homework.id,
            'text': 'Мое решение'
        }
        
        response = authenticated_client_user.post('/api/homework/submissions/', data)
        
        assert response.status_code == status.HTTP_201_CREATED
        assert response.data['text'] == 'Мое решение'

