# Path: emaula/school/views.py
# def home_page(request):
#     return render(request, 'school/index.html')
# 
# def colaborate(request):
#     return render(request, 'school/colaborate.html')
# 
# def team(request):
#     return render(request, 'school/team.html')
# 
# def about_project(request):
#     return render(request, 'school/about.html')
# 
# def tos(request):
#     return render(request, 'school/tos.html')
# 
# Path: emaula/school/models.py
# class Year(models.Model):
# 
#     """ Modelo para o ano ou série à qual a aula pertence. """
# 
#     year = models.CharField(max_length=20,
#                             help_text='Série ou ano. Ex: 1º ano',
#                             blank=True)
# 
#     def __str__(self):
#         return self.year
# 
# class Subject(models.Model):
# 
#     """ Modelo para disciplina(s) ou cadeira(s) à qual a aula pertence. """
# 
#     subject = models.CharField(max_length=255,
#                                help_text='Disciplina ou cadeira',
#                                blank=True,
#                                null=True)
# 
#     def __str__(self):
#         return self.subject
# 
# Path: emaula/school/models.py
# class Classroom(models.Model):
# 
#     """ Modelo com os conteúdos da aula, como textos, links, imagens, etc. """
# 
#     # TODO: Opção de deixar ou não pública a aula
#     subject = models.ManyToManyField(Subject,
#                                      help_text='Disciplina')
#     title = models.CharField(max_length=255,
#                              help_text='Tema ou título da aula',
#                              blank=True)
#     year = models.ManyToManyField(Year,
#                                   help_text='Selecione \
#                                   um ano ou série para esta aula')
#     summary = models.TextField(max_length=1000,
#                                help_text='Escreva um breve sumário da aula.',
#                                blank=True)
# 
#     author = models.ForeignKey('Professor',
#                                related_name='classroom',
#                                blank=True,
#                                on_delete=models.SET_NULL,
#                                null=True)
#     created_date = models.DateField(default=timezone.now,
#                                     help_text='Data de criação')
#     published_date = models.DateField(blank=True,
#                                       null=True,
#                                       help_text='Data de publicação')
#     views = models.IntegerField(default=0, help_text='Visitas')
# 
#     def __str__(self):
#         return '{0}'.format(self.title)
# 
#     def publish(self):
#         """ Método para tornar pública uma aula. """
#         self.published_date = timezone.now()
#         self.save()
# 
#     def get_absolute_url(self):
#         """ Acessa uma aula específica através da interface administrativa. """
#         return reverse('school:classroom_detail', args=[str(self.id)])
# 
#     def display_subject(self):
#         return ', '.join(
#             [subject.subject for subject in self.subject.all()])
# 
#     def display_year(self):
#         return ', '.join(
#             [year.year for year in self.year.all()[:3]])
# 
#     def display_author(self):
#         return ', '.join(
#             [author.author for author in self.author.all()[:3]])
# 
#     def display_text(self):
#         object_texts = dict()
#         for text in self.text.all():
#             object_texts['title'] = text.title
#             object_texts['text'] = text.text
#             object_texts['source'] = text.source
#         return object_texts
# 
#     def display_link(self):
#         return ', '.join(
#             [link.link for link in self.objects.link.all()])
# 
#     def display_image(self):
#         object_images = dict()
#         for image in self.image.all():
#             object_images['image_path'] = image.image_path
#             object_images['alt'] = image.alt
#         return object_images
# 
#     display_author.short_description = 'Author'
#     display_subject.short_description = 'Subject'
#     display_year.short_description = 'Year'
#     display_text.short_description = 'Text'
#     display_link.short_description = 'Link'
#     display_link.short_description = 'Image'


from django.urls import resolve
from django.test import TestCase
from django.http import HttpRequest
from .views import home_page, colaborate, team, about_project, tos
from .models import Year, Subject
from .models import Classroom
from django.contrib.auth.models import User
from django.template.loader import render_to_string


class HomePageTest(TestCase):
    def test_root_url_resolves_to_home_page_view(self):
        found = resolve('/school/')
        self.assertEqual(found.func, home_page)

    def test_home_page_returns_correct_html(self):
        request = HttpRequest()
        response = home_page(request)
        self.assertTrue(response.content.startswith(b'<!DOCTYPE html>'))
        self.assertIn(
            b'<title>EmAula.xyz | Planeje e compartilhe suas aulas!</title>',
            response.content)
        self.assertTrue(response.content.strip().endswith(b'</html>'))


class TeamPageTest(TestCase):
    def test_team_url_resolves_to_team_page_view(self):
        found = resolve('/school/team/')
        self.assertEqual(found.func, team)

    def test_team_page_returns_correct_html(self):
        request = HttpRequest()

# Path: emaula/school/views.py
# def home_page(request):
#     return render(request, 'school/index.html')
# 
# def colaborate(request):
#     return render(request, 'school/colaborate.html')
# 
# def team(request):
#     return render(request, 'school/team.html')
# 
# def about_project(request):
#     return render(request, 'school/about.html')
# 
# def tos(request):
#     return render(request, 'school/tos.html')
# 
# Path: emaula/school/models.py
# class Year(models.Model):
# 
#     """ Modelo para o ano ou série à qual a aula pertence. """
# 
#     year = models.CharField(max_length=20,
#                             help_text='Série ou ano. Ex: 1º ano',
#                             blank=True)
# 
#     def __str__(self):
#         return self.year
# 
# class Subject(models.Model):
# 
#     """ Modelo para disciplina(s) ou cadeira(s) à qual a aula pertence. """
# 
#     subject = models.CharField(max_length=255,
#                                help_text='Disciplina ou cadeira',
#                                blank=True,
#                                null=True)
# 
#     def __str__(self):
#         return self.subject
# 
# Path: emaula/school/models.py
# class Classroom(models.Model):
# 
#     """ Modelo com os conteúdos da aula, como textos, links, imagens, etc. """
# 
#     # TODO: Opção de deixar ou não pública a aula
#     subject = models.ManyToManyField(Subject,
#                                      help_text='Disciplina')
#     title = models.CharField(max_length=255,
#                              help_text='Tema ou título da aula',
#                              blank=True)
#     year = models.ManyToManyField(Year,
#                                   help_text='Selecione \
#                                   um ano ou série para esta aula')
#     summary = models.TextField(max_length=1000,
#                                help_text='Escreva um breve sumário da aula.',
#                                blank=True)
# 
#     author = models.ForeignKey('Professor',
#                                related_name='classroom',
#                                blank=True,
#                                on_delete=models.SET_NULL,
#                                null=True)
#     created_date = models.DateField(default=timezone.now,
#                                     help_text='Data de criação')
#     published_date = models.DateField(blank=True,
#                                       null=True,
#                                       help_text='Data de publicação')
#     views = models.IntegerField(default=0, help_text='Visitas')
# 
#     def __str__(self):
#         return '{0}'.format(self.title)
# 
#     def publish(self):
#         """ Método para tornar pública uma aula. """
#         self.published_date = timezone.now()
#         self.save()
# 
#     def get_absolute_url(self):
#         """ Acessa uma aula específica através da interface administrativa. """
#         return reverse('school:classroom_detail', args=[str(self.id)])
# 
#     def display_subject(self):
#         return ', '.join(
#             [subject.subject for subject in self.subject.all()])
# 
#     def display_year(self):
#         return ', '.join(
#             [year.year for year in self.year.all()[:3]])
# 
#     def display_author(self):
#         return ', '.join(
#             [author.author for author in self.author.all()[:3]])
# 
#     def display_text(self):
#         object_texts = dict()
#         for text in self.text.all():
#             object_texts['title'] = text.title
#             object_texts['text'] = text.text
#             object_texts['source'] = text.source
#         return object_texts
# 
#     def display_link(self):
#         return ', '.join(
#             [link.link for link in self.objects.link.all()])
# 
#     def display_image(self):
#         object_images = dict()
#         for image in self.image.all():
#             object_images['image_path'] = image.image_path
#             object_images['alt'] = image.alt
#         return object_images
# 
#     display_author.short_description = 'Author'
#     display_subject.short_description = 'Subject'
#     display_year.short_description = 'Year'
#     display_text.short_description = 'Text'
#     display_link.short_description = 'Link'
#     display_link.short_description = 'Image'


# Path: emaula/school/tests.py
from django.urls import resolve
from django.test import TestCase
from django.http import HttpRequest
from .views import home_page, colaborate, team, about_project, tos
from .models import Year, Subject
from .models import Classroom
from django.contrib.auth.models import User
from django.template.loader import render_to_string



class HomePageTest(TestCase):
    def test_root_url_resolves_to_home_page_view(self):
        found = resolve('/school/')
        self.assertEqual(found.func, home_page)

    def test_home_page_returns_correct_html(self):
        request = HttpRequest()
        response = home_page(request)
        self.assertTrue(response.content.startswith(b'<!DOCTYPE html>'))
        self.assertIn(
            b'<title>EmAula.xyz | Planeje e compartilhe suas aulas!</title>',
            response.content)
        self.assertTrue(response.content.strip().endswith(b'</html>'))


class TeamPageTest(TestCase):
    def test_team_url_resolves_to_team_page_view(self):
        found = resolve('/school/team/')
        self.assertEqual(found.func, team)

    def test_team_page_returns_correct_html(self):
        request = HttpRequest()

        response = team(request)