#!/usr/bin/env python
# -*- coding: utf-8 -*-

from datetime import datetime

from django.test import TestCase
from django.contrib.sites.models import Site

from opps.core.models.channel import Channel


class ChannelModelTest(TestCase):

    def setUp(self):
        self.site = Site.objects.filter(name=u'example.com').get()
        self.channel = Channel.objects.create(name=u'Home', slug=u'home',
                description=u'home page', site=self.site)

    def test_check_create_home(self):
        """
        Check exist channel home, create on setup class
        """
        home = Channel.objects.filter(slug=u'home').get()
        self.assertTrue(home)
        self.assertEqual(home, self.channel)

    def test_not_is_published(self):
        """
        is_published false on home channel
        """
        home = Channel.objects.filter(slug=u'home').get()
        self.assertFalse(home.is_published())
        self.assertEqual(home.is_published(), home.published)

    def test_is_published(self):
        """
        is_published true on home channel
        """
        self.channel.published = True
        self.channel.date_available = datetime(2013, 01, 01)
        self.channel.save()

        home = Channel.objects.filter(slug=u'home').get()
        self.assertTrue(home.is_published())
        self.assertEqual(home.is_published(), home.published)

@@ -1348,28 +1348,340 @@
 ublished(), home.published)%0A
+%0A    def test_create_sub_channel_home(self):%0A        channel = Channel.objects.create(name=u'Sub Home', slug=u'sub-home',%0A                description=u'sub home page', site=self.site,%0A                channel=self.channel)%0A%0A        self.assertTrue(channel)%0A        self.assertEqual(channel.channel, self.channel)%0A

write test create sub channel home not published