from django.test import TestCase
from models import Content, Review
from django.core.urlresolvers import reverse
from fiber.models import Page

def create_django_page_tree():
    mainmenu=Page(title='mainmenu')
    mainmenu.save()
    home=Page(title='home', parent=mainmenu, url='home', template_name='base/home.html')
    home.save()
    join=Page(title='join', parent=home, url='join', template_name='base/join.html')
    join.save()
    members=Page(title='members', parent=home, url='members', template_name='base/members')
    members.save()
    meetings = Page(title='meetings', parent=mainmenu, url='meetings', template_name='')
    meetings.save()
    journal = Page(title='journal', parent=mainmenu, url='journal')
    journal.save()
    Volumes = Page(title='Volumes', parent=journal, url='volumes')
    Volumes.save()
    #years = []
    #for y in range(2003, 2016): years.append(y)
    #for y in years:
    #    Page.objects.create(title=str(y), url=str(y), parent=Volumes)


class ContentMethodTests(TestCase):
    def test_content_create_method(self):
        """
        Tests the journal content constructor methods.
        """
        # Create a meeting
        #calgary_2014 = Meeting(year=2014, title='Calgary 2014', location='Calgary', associated_with='AAPA')
        #calgary_2014.save()
        # Create a default page tree
        create_django_page_tree()
        initial_object_count = Content.objects.count()
        Content.objects.create(title='Test', year=2014)
        self.assertEqual(Content.objects.count(), initial_object_count+1)
        response = self.client.get('/journal')
        self.assertEqual(response.status_code, 301)
        response = self.client.get('/journal/volumes')
        self.assertEqual(response.status_code, 301)
