# 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: materials/serializers.py
# class MaterialSerializer(serializers.ModelSerializer):
#     title = serializers.CharField(required=False, min_length=3, max_length=150, allow_blank=True)
#     section = serializers.CharField(required=False, min_length=3, max_length=150, allow_blank=True)
#     content = serializers.CharField(allow_blank=False)
#     subject = SubjectSerializer(read_only=True)
#     video_url = serializers.URLField(required=False, allow_blank=True)
# 
#     class Meta:
#         model = Material
#         fields = (
#             'id', 'title', 'section', 'content', 'class_number', 'subject', 'video_url', 'author'
#         )
#         depth = 1
# 
#     def create(self, validated_data):
#         request = self.context['request']
#         subject = self.context['subject']
# 
#         author = request.user.teacher
# 
#         return Material.objects.create(subject=subject, author=author, **validated_data)
# 
# Path: materials/models.py
# class Material(models.Model):
#     title = models.CharField(max_length=150, blank=True)
#     section = models.CharField(max_length=150, blank=True)
#     content = models.TextField(blank=False)
#     class_number = models.IntegerField(
#         choices=Class.CLASS_NUMBERS,
#         validators=[Class.CLASS_NUMBER_VALIDATORS]
#     )
#     subject = models.ForeignKey(Subject, related_name='materials', on_delete=models.CASCADE)
#     video_url = models.URLField(blank=True)
#     author = models.ForeignKey(Teacher, null=True, on_delete=models.CASCADE)
# 
#     def __str__(self):
#         return '{} - {} ({} class) posted by {}'.format(
#             self.title, self.subject, self.class_number, self.author
#         )


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 MaterialSerializer
from .models import Material





class MaterialsViewSetTestCase(APITestCase):
    def setUp(self):
        self.client = APIClient()
        self.list_view_name = 'materials:nested_materials-list'
        self.detail_view_name = 'materials:nested_materials-detail'
        self.serializer_class = MaterialSerializer

        self.clazz = Class.objects.create(number=10, letter='A')

# 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: materials/serializers.py
# class MaterialSerializer(serializers.ModelSerializer):
#     title = serializers.CharField(required=False, min_length=3, max_length=150, allow_blank=True)
#     section = serializers.CharField(required=False, min_length=3, max_length=150, allow_blank=True)
#     content = serializers.CharField(allow_blank=False)
#     subject = SubjectSerializer(read_only=True)
#     video_url = serializers.URLField(required=False, allow_blank=True)
# 
#     class Meta:
#         model = Material
#         fields = (
#             'id', 'title', 'section', 'content', 'class_number', 'subject', 'video_url', 'author'
#         )
#         depth = 1
# 
#     def create(self, validated_data):
#         request = self.context['request']
#         subject = self.context['subject']
# 
#         author = request.user.teacher
# 
#         return Material.objects.create(subject=subject, author=author, **validated_data)
# 
# Path: materials/models.py
# class Material(models.Model):
#     title = models.CharField(max_length=150, blank=True)
#     section = models.CharField(max_length=150, blank=True)
#     content = models.TextField(blank=False)
#     class_number = models.IntegerField(
#         choices=Class.CLASS_NUMBERS,
#         validators=[Class.CLASS_NUMBER_VALIDATORS]
#     )
#     subject = models.ForeignKey(Subject, related_name='materials', on_delete=models.CASCADE)
#     video_url = models.URLField(blank=True)
#     author = models.ForeignKey(Teacher, null=True, on_delete=models.CASCADE)
# 
#     def __str__(self):
#         return '{} - {} ({} class) posted by {}'.format(
#             self.title, self.subject, self.class_number, self.author
#         )


# Path: materials/tests.py
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 MaterialSerializer
from .models import Material






class MaterialsViewSetTestCase(APITestCase):
    def setUp(self):
        self.client = APIClient()
        self.list_view_name = 'materials:nested_materials-list'
        self.detail_view_name = 'materials:nested_materials-detail'
        self.serializer_class = MaterialSerializer

        self.clazz = Class.objects.create(number=10, letter='A')

        self.subject = Subject.objects.create(title='test_subject')