# Path: students/models.py
# class Class(models.Model):
#     CLASS_NUMBERS = (
#         (8, 8),
#         (9, 9),
#         (10, 10),
#         (11, 11),
#         (12, 12),
#     )
#     CLASS_NUMBER_VALIDATORS = [MinValueValidator(8), MaxValueValidator(12)]
# 
#     CLASS_LETTERS = (
#         ('A', 'A'),
#         ('B', 'B'),
#         ('V', 'V'),
#         ('G', 'G'),
#     )
# 
#     number = models.IntegerField(validators=CLASS_NUMBER_VALIDATORS, choices=CLASS_NUMBERS)
#     letter = models.CharField(max_length=1, choices=CLASS_LETTERS)
# 
#     def __str__(self):
#         return '{}{}'.format(self.number, self.letter)
# 
#     class Meta:
#         ordering = ['number', 'letter']
#         verbose_name_plural = 'classes'
# 
# class Subject(models.Model):
#     title = models.CharField(unique=True, max_length=50)
# 
#     def __str__(self):
#         return self.title
# 
#     class Meta:
#         ordering = ['title']
# 
# class Student(Account):
#     clazz = models.ForeignKey(Class, related_name='students', on_delete=models.CASCADE)
# 
#     def __str__(self):
#         return '{} ({})'.format(self.user.username, self.clazz)
# 
# class Teacher(Account):
#     subject = models.ForeignKey(Subject, related_name='teachers', on_delete=models.CASCADE)
# 
#     def __str__(self):
#         return '{} ({})'.format(self.user.username, self.subject)
# 
# Path: homeworks/serializers.py
# class HomeworkSerializer(serializers.ModelSerializer):
#     details = serializers.CharField(max_length=256, allow_blank=True)
# 
#     class Meta:
#         model = Homework
#         fields = ('id', 'topic', 'subject', 'clazz', 'deadline', 'details', 'author')
#         depth = 1
# 
#     def create(self, validated_data):
#         request = self.context['request']
# 
#         author = request.user.teacher
#         subject = author.subject
#         clazz = self.context['clazz']
# 
#         homework = Homework.objects.create(
#             subject=subject,
#             author=author,
#             clazz=clazz,
#             **validated_data
#         )
# 
#         recipient_list = User.objects.filter(student__clazz=clazz)
#         for user in recipient_list:
#             send_creation_email(user, model=homework)
# 
#         return homework
# 
# class SubmissionSerializer(serializers.ModelSerializer):
#     content = serializers.CharField(max_length=2048, allow_blank=False)
#     solution_url = serializers.URLField(required=False, allow_blank=True)
# 
#     class Meta:
#         model = Submission
#         fields = ('id', 'homework', 'student', 'content', 'solution_url', 'checked')
#         depth = 1
# 
#     def create(self, validated_data):
#         homework = self.context['homework']
#         request = self.context['request']
# 
#         student = request.user.student
# 
#         return Submission.objects.create(homework=homework, student=student, **validated_data)
# 
# Path: homeworks/models.py
# class Homework(models.Model):
#     topic = models.CharField(default='Homework', max_length=50)
#     subject = models.ForeignKey(Subject, on_delete=models.CASCADE)
#     clazz = models.ForeignKey(Class, on_delete=models.CASCADE)
#     deadline = models.DateField(auto_now=False)
#     details = models.TextField(max_length=256, blank=True)
#     author = models.ForeignKey(Teacher, null=True, related_name='homeworks', on_delete=models.CASCADE)
# 
#     def __str__(self):
#         return '{} ({}) - {}'.format(self.topic, self.subject, self.clazz)
# 
#     class Meta:
#         ordering = ['deadline', 'clazz', 'subject']
# 
# class Submission(BaseAbstractPost):
#     homework = models.ForeignKey(Homework, related_name='submissions', on_delete=models.CASCADE)
#     student = models.ForeignKey(Student, related_name='submissions', on_delete=models.CASCADE)
#     content = models.TextField(max_length=2048)
#     solution_url = models.URLField(blank=True)
#     checked = models.BooleanField(default=False)
# 
#     def __str__(self):
#         return '{} - {} ({})'.format(self.student, self.homework, self.posted_on)
# 
#     class Meta:
#         ordering = ['-posted_on', '-last_edited_on']


from datetime import datetime, timedelta
from django.contrib.auth.models import User
from rest_framework.test import APITestCase, APIClient
from rest_framework.reverse import reverse
from rest_framework import status
from students.models import Class, Subject, Student, Teacher
from .serializers import HomeworkSerializer, SubmissionSerializer
from .models import Homework, Submission
        self.assertEqual(Homework.objects.count(), 0)
        self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)


class SubmissionsViewSetTestCase(APITestCase):
    def setUp(self):
        self.client = APIClient()
        self.list_view_name = 'homeworks:submissions-list'
        self.detail_view_name = 'homeworks:submissions-detail'
        self.serializer_class = SubmissionSerializer

        self.clazz = Class.objects.create(number=10, letter='A')
        self.subject = Subject.objects.create(title='test_subject')

        self.student_user1 = User.objects.create(username='test', password='pass')
        self.student_user2 = User.objects.create(username='test1', password='password')
        self.teacher_user = User.objects.create(username='author', password='pass123')

        self.teacher = Teacher.objects.create(user=self.teacher_user, subject=self.subject)
        self.student1 = Student.objects.create(user=self.student_user1, clazz=self.clazz)
        self.student2 = Student.objects.create(user=self.student_user2, clazz=self.clazz)

        self.homework = Homework.objects.create(
            subject=self.subject,
            clazz=self.clazz,
            deadline=datetime.now().date(),
            details='detailed explanation',
            author=self.teacher
        )


# Path: students/models.py
# class Class(models.Model):
#     CLASS_NUMBERS = (
#         (8, 8),
#         (9, 9),
#         (10, 10),
#         (11, 11),
#         (12, 12),
#     )
#     CLASS_NUMBER_VALIDATORS = [MinValueValidator(8), MaxValueValidator(12)]
# 
#     CLASS_LETTERS = (
#         ('A', 'A'),
#         ('B', 'B'),
#         ('V', 'V'),
#         ('G', 'G'),
#     )
# 
#     number = models.IntegerField(validators=CLASS_NUMBER_VALIDATORS, choices=CLASS_NUMBERS)
#     letter = models.CharField(max_length=1, choices=CLASS_LETTERS)
# 
#     def __str__(self):
#         return '{}{}'.format(self.number, self.letter)
# 
#     class Meta:
#         ordering = ['number', 'letter']
#         verbose_name_plural = 'classes'
# 
# class Subject(models.Model):
#     title = models.CharField(unique=True, max_length=50)
# 
#     def __str__(self):
#         return self.title
# 
#     class Meta:
#         ordering = ['title']
# 
# class Student(Account):
#     clazz = models.ForeignKey(Class, related_name='students', on_delete=models.CASCADE)
# 
#     def __str__(self):
#         return '{} ({})'.format(self.user.username, self.clazz)
# 
# class Teacher(Account):
#     subject = models.ForeignKey(Subject, related_name='teachers', on_delete=models.CASCADE)
# 
#     def __str__(self):
#         return '{} ({})'.format(self.user.username, self.subject)
# 
# Path: homeworks/serializers.py
# class HomeworkSerializer(serializers.ModelSerializer):
#     details = serializers.CharField(max_length=256, allow_blank=True)
# 
#     class Meta:
#         model = Homework
#         fields = ('id', 'topic', 'subject', 'clazz', 'deadline', 'details', 'author')
#         depth = 1
# 
#     def create(self, validated_data):
#         request = self.context['request']
# 
#         author = request.user.teacher
#         subject = author.subject
#         clazz = self.context['clazz']
# 
#         homework = Homework.objects.create(
#             subject=subject,
#             author=author,
#             clazz=clazz,
#             **validated_data
#         )
# 
#         recipient_list = User.objects.filter(student__clazz=clazz)
#         for user in recipient_list:
#             send_creation_email(user, model=homework)
# 
#         return homework
# 
# class SubmissionSerializer(serializers.ModelSerializer):
#     content = serializers.CharField(max_length=2048, allow_blank=False)
#     solution_url = serializers.URLField(required=False, allow_blank=True)
# 
#     class Meta:
#         model = Submission
#         fields = ('id', 'homework', 'student', 'content', 'solution_url', 'checked')
#         depth = 1
# 
#     def create(self, validated_data):
#         homework = self.context['homework']
#         request = self.context['request']
# 
#         student = request.user.student
# 
#         return Submission.objects.create(homework=homework, student=student, **validated_data)
# 
# Path: homeworks/models.py
# class Homework(models.Model):
#     topic = models.CharField(default='Homework', max_length=50)
#     subject = models.ForeignKey(Subject, on_delete=models.CASCADE)
#     clazz = models.ForeignKey(Class, on_delete=models.CASCADE)
#     deadline = models.DateField(auto_now=False)
#     details = models.TextField(max_length=256, blank=True)
#     author = models.ForeignKey(Teacher, null=True, related_name='homeworks', on_delete=models.CASCADE)
# 
#     def __str__(self):
#         return '{} ({}) - {}'.format(self.topic, self.subject, self.clazz)
# 
#     class Meta:
#         ordering = ['deadline', 'clazz', 'subject']
# 
# class Submission(BaseAbstractPost):
#     homework = models.ForeignKey(Homework, related_name='submissions', on_delete=models.CASCADE)
#     student = models.ForeignKey(Student, related_name='submissions', on_delete=models.CASCADE)
#     content = models.TextField(max_length=2048)
#     solution_url = models.URLField(blank=True)
#     checked = models.BooleanField(default=False)
# 
#     def __str__(self):
#         return '{} - {} ({})'.format(self.student, self.homework, self.posted_on)
# 
#     class Meta:
#         ordering = ['-posted_on', '-last_edited_on']


# Path: homeworks/tests.py
from datetime import datetime, timedelta
from django.contrib.auth.models import User
from rest_framework.test import APITestCase, APIClient
from rest_framework.reverse import reverse
from rest_framework import status
from students.models import Class, Subject, Student, Teacher
from .serializers import HomeworkSerializer, SubmissionSerializer
from .models import Homework, Submission

        self.assertEqual(Homework.objects.count(), 0)
        self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)


class SubmissionsViewSetTestCase(APITestCase):
    def setUp(self):
        self.client = APIClient()
        self.list_view_name = 'homeworks:submissions-list'
        self.detail_view_name = 'homeworks:submissions-detail'
        self.serializer_class = SubmissionSerializer

        self.clazz = Class.objects.create(number=10, letter='A')
        self.subject = Subject.objects.create(title='test_subject')

        self.student_user1 = User.objects.create(username='test', password='pass')
        self.student_user2 = User.objects.create(username='test1', password='password')
        self.teacher_user = User.objects.create(username='author', password='pass123')

        self.teacher = Teacher.objects.create(user=self.teacher_user, subject=self.subject)
        self.student1 = Student.objects.create(user=self.student_user1, clazz=self.clazz)
        self.student2 = Student.objects.create(user=self.student_user2, clazz=self.clazz)

        self.homework = Homework.objects.create(
            subject=self.subject,
            clazz=self.clazz,
            deadline=datetime.now().date(),
            details='detailed explanation',
            author=self.teacher
        )


        self.student1_submission = Submission.objects.create(