<s> from datetime import timedelta <EOL> from mptt . models import TreeForeignKey <EOL> from django . db import IntegrityError <EOL> from django . test import TestCase <EOL> from django . db import models <EOL> from django . core . exceptions import ValidationError <EOL> from django . contrib . sites . models import Site <EOL> from django . contrib . auth import get_user_model <EOL> from django . utils import timezone <EOL> from django . utils . translation import ugettext_lazy as _ <EOL> from opps . channels . models import Channel <EOL> class ChannelFields ( TestCase ) : <EOL> def test_name ( self ) : <EOL> field = Channel . _meta . get_field_by_name ( '<STR_LIT:name>' ) [ <NUM_LIT:0> ] <EOL> self . assertEqual ( field . __class__ , models . CharField ) <EOL> self . assertEqual ( field . max_length , <NUM_LIT> ) <EOL> def test_long_slug ( self ) : <EOL> field = Channel . _meta . get_field_by_name ( '<STR_LIT>' ) [ <NUM_LIT:0> ] <EOL> self . assertEqual ( field . __class__ , models . SlugField ) <EOL> self . assertEqual ( field . max_length , <NUM_LIT> ) <EOL> self . assertTrue ( field . db_index ) <EOL> def test_layout ( self ) : <EOL> field = Channel . _meta . get_field_by_name ( '<STR_LIT>' ) [ <NUM_LIT:0> ] <EOL> self . assertEqual ( field . __class__ , models . CharField ) <EOL> self . assertEqual ( field . max_length , <NUM_LIT> ) <EOL> self . assertTrue ( field . db_index ) <EOL> self . assertEqual ( field . default , u"<STR_LIT:default>" ) <EOL> def test_description ( self ) : <EOL> field = Channel . _meta . get_field_by_name ( '<STR_LIT:description>' ) [ <NUM_LIT:0> ] <EOL> self . assertEqual ( field . __class__ , models . CharField ) <EOL> self . assertEqual ( field . max_length , <NUM_LIT:255> ) <EOL> self . assertTrue ( field . null ) <EOL> self . assertTrue ( field . blank ) <EOL> def test_show_in_menu ( self ) : <EOL> field = Channel . _meta . get_field_by_name ( '<STR_LIT>' ) [ <NUM_LIT:0> ] <EOL> self . assertEqual ( field . __class__ , models . BooleanField ) <EOL> self . assertFalse ( field . default ) <EOL> def test_include_in_main_rss ( self ) : <EOL> field = Channel . _meta . get_field_by_name ( '<STR_LIT>' ) [ <NUM_LIT:0> ] <EOL> self . assertEqual ( field . __class__ , models . BooleanField ) <EOL> self . assertTrue ( field . default ) <EOL> def test_homepage ( self ) : <EOL> field = Channel . _meta . get_field_by_name ( '<STR_LIT>' ) [ <NUM_LIT:0> ] <EOL> self . assertEqual ( field . __class__ , models . BooleanField ) <EOL> self . assertFalse ( field . default ) <EOL> self . assertEqual ( field . help_text , <EOL> u'<STR_LIT>' <EOL> u'<STR_LIT>' ) <EOL> def test_group ( self ) : <EOL> field = Channel . _meta . get_field_by_name ( '<STR_LIT>' ) [ <NUM_LIT:0> ] <EOL> self . assertEqual ( field . __class__ , models . BooleanField ) <EOL> self . assertFalse ( field . default ) <EOL> def test_order ( self ) : <EOL> field = Channel . _meta . get_field_by_name ( '<STR_LIT>' ) [ <NUM_LIT:0> ] <EOL> self . assertEqual ( field . __class__ , models . IntegerField ) <EOL> self . assertEqual ( field . default , <NUM_LIT:0> ) <EOL> def test_parent ( self ) : <EOL> field = Channel . _meta . get_field_by_name ( '<STR_LIT>' ) [ <NUM_LIT:0> ] <EOL> self . assertEqual ( field . __class__ , TreeForeignKey ) <EOL> self . assertTrue ( field . null ) <EOL> self . assertTrue ( field . blank ) <EOL> class ChannelModelTest ( TestCase ) : <EOL> def setUp ( self ) : <EOL> User = get_user_model ( ) <EOL> self . user = User . objects . create ( username = u'<STR_LIT:test>' , password = '<STR_LIT:test>' ) <EOL> self . site = Site . objects . filter ( name = u'<STR_LIT>' ) . get ( ) <EOL> self . parent = Channel . objects . create ( name = u'<STR_LIT>' , slug = u'<STR_LIT>' , <EOL> description = u'<STR_LIT>' , <EOL> site = self . site , user = self . user ) <EOL> def test_check_create_home ( self ) : <EOL> """<STR_LIT>""" <EOL> home = Channel . objects . filter ( slug = u'<STR_LIT>' ) . get ( ) <EOL> self . assertTrue ( home ) <EOL> self . assertEqual ( home , self . parent ) <EOL> def test_not_is_published ( self ) : <EOL> """<STR_LIT>""" <EOL> home = Channel . objects . filter ( slug = u'<STR_LIT>' ) . get ( ) <EOL> self . assertFalse ( home . is_published ( ) ) <EOL> self . assertEqual ( home . is_published ( ) , home . published ) <EOL> def test_is_published ( self ) : <EOL> """<STR_LIT>""" <EOL> self . parent . published = True <EOL> self . parent . date_available = timezone . now ( ) - timedelta ( hours = <NUM_LIT:1> ) <EOL> self . parent . save ( ) <EOL> home = Channel . objects . filter ( slug = u'<STR_LIT>' ) . get ( ) <EOL> self . assertTrue ( home . is_published ( ) ) <EOL> self . assertEqual ( home . is_published ( ) , home . published ) <EOL> def test_create_sub_channel_home ( self ) : <EOL> channel = Channel . objects . create ( name = u'<STR_LIT>' , slug = u'<STR_LIT>' , <EOL> description = u'<STR_LIT>' , <EOL> site = self . site , parent = self . parent , <EOL> user = self . user ) <EOL> self . assertTrue ( channel ) <EOL> self . assertEqual ( channel . parent , self . parent ) <EOL> def test_not_is_published_sub_channel ( self ) : <EOL> """<STR_LIT>""" <EOL> subchannel = Channel . objects . create ( name = u'<STR_LIT>' , slug = u'<STR_LIT>' , <EOL> description = u'<STR_LIT>' , <EOL> site = self . site , user = self . user , <EOL> parent = self . parent ) <EOL> subhome = Channel . objects . filter ( slug = u'<STR_LIT>' ) . get ( ) <EOL> self . assertFalse ( subhome . is_published ( ) ) <EOL> self . assertEqual ( subhome . is_published ( ) , subhome . published ) <EOL> self . assertEqual ( subhome . is_published ( ) , subchannel . is_published ( ) ) <EOL> def test_is_published_sub_channel ( self ) : <EOL> """<STR_LIT>""" <EOL> subchannel = Channel . objects . create ( name = u'<STR_LIT>' , slug = u'<STR_LIT>' , <EOL> description = u'<STR_LIT>' , <EOL> site = self . site , user = self . user , <EOL> parent = self . parent ) <EOL> subchannel . published = True <EOL> subchannel . date_available = timezone . now ( ) - timedelta ( hours = <NUM_LIT:1> ) <EOL> subchannel . save ( ) <EOL> subhome = Channel . objects . filter ( slug = u'<STR_LIT>' ) . get ( ) <EOL> self . assertTrue ( subhome . is_published ( ) ) <EOL> self . assertEqual ( subhome . is_published ( ) , subhome . published ) <EOL> self . assertEqual ( subhome . is_published ( ) , subhome . is_published ( ) ) <EOL> def test_duplicate_channel_name ( self ) : <EOL> """<STR_LIT>""" <EOL> Channel . objects . create ( name = u'<STR_LIT>' , slug = u'<STR_LIT>' , <EOL> description = u'<STR_LIT>' , site = self . site , <EOL> parent = self . parent , user = self . user ) <EOL> self . assertRaises ( IntegrityError , Channel . objects . create , <EOL> name = u'<STR_LIT>' , slug = u'<STR_LIT>' , <EOL> description = u'<STR_LIT>' , site = self . site , <EOL> parent = self . parent ) <EOL> def test_channel_is_homepage ( self ) : <EOL> """<STR_LIT>""" <EOL> self . parent . homepage = True <EOL> self . parent . published = True <EOL> self . parent . save ( ) <EOL> channel = Channel . objects . get_homepage ( site = self . parent . site ) <EOL> self . assertTrue ( channel ) <EOL> self . assertEqual ( channel . slug , self . parent . slug ) <EOL> def test_not_set_homepage ( self ) : <EOL> """<STR_LIT>""" <EOL> channel = Channel . objects . get_homepage ( site = self . parent . site ) <EOL> self . assertEqual ( None , channel ) <EOL> self . assertFalse ( channel ) <EOL> def test_get_thumb ( self ) : <EOL> self . assertIsNone ( self . parent . get_thumb ( ) ) <EOL> def test_search_category ( self ) : <EOL> self . assertEqual ( _ ( u'<STR_LIT>' ) , Channel ( ) . search_category ) <EOL> def test_title ( self ) : <EOL> self . assertEqual ( self . parent . title , self . parent . name ) <EOL> def test_root ( self ) : <EOL> self . assertEqual ( self . parent , self . parent . root ) <EOL> subchannel = Channel . objects . create ( name = u'<STR_LIT>' , slug = u'<STR_LIT>' , <EOL> description = u'<STR_LIT>' , <EOL> site = self . site , user = self . user , <EOL> parent = self . parent ) <EOL> self . assertEqual ( self . parent , subchannel . root ) <EOL> def test_clean_slug_exist_in_domain ( self ) : <EOL> invalid = Channel ( name = u'<STR_LIT>' , slug = u'<STR_LIT>' , description = u'<STR_LIT>' , <EOL> site = self . site , user = self . user ) <EOL> self . assertRaises ( ValidationError , invalid . full_clean ) <EOL> def test_clean_slug_exist_homepage ( self ) : <EOL> Channel . objects . create ( name = u'<STR_LIT>' , slug = u'<STR_LIT>' , <EOL> homepage = True , site = self . site , <EOL> user = self . user , published = True ) <EOL> invalid = Channel . objects . create ( name = u'<STR_LIT>' , slug = u'<STR_LIT>' , <EOL> homepage = True , site = self . site , <EOL> user = self . user ) <EOL> self . assertRaises ( ValidationError , invalid . full_clean ) <EOL> def test_clean ( self ) : <EOL> valid = Channel . objects . create ( name = u'<STR_LIT>' , slug = u'<STR_LIT>' , <EOL> homepage = True , site = self . site , <EOL> user = self . user , published = True ) <EOL> valid . full_clean ( ) <EOL> def test_long_slug ( self ) : <EOL> channel1 = Channel . objects . create ( name = u'<STR_LIT>' , slug = u'<STR_LIT>' , <EOL> parent = self . parent , <EOL> description = u'<STR_LIT>' , <EOL> site = self . site , user = self . user ) <EOL> channel2 = Channel . objects . create ( name = u'<STR_LIT>' , slug = u'<STR_LIT>' , <EOL> parent = channel1 , <EOL> description = u'<STR_LIT>' , <EOL> site = self . site , user = self . user ) <EOL> self . assertEqual ( self . parent . long_slug , '<STR_LIT>' ) <EOL> self . assertEqual ( channel1 . long_slug , '<STR_LIT>' ) <EOL> self . assertEqual ( channel2 . long_slug , '<STR_LIT>' ) <EOL> def test_unicode ( self ) : <EOL> channel1 = Channel . objects . create ( name = u'<STR_LIT>' , slug = u'<STR_LIT>' , <EOL> parent = self . parent , <EOL> description = u'<STR_LIT>' , <EOL> site = self . site , user = self . user ) <EOL> channel2 = Channel . objects . create ( name = u'<STR_LIT>' , slug = u'<STR_LIT>' , <EOL> parent = channel1 , <EOL> description = u'<STR_LIT>' , <EOL> site = self . site , user = self . user ) <EOL> self . assertEqual ( self . parent . __unicode__ ( ) , '<STR_LIT>' ) <EOL> self . assertEqual ( channel1 . __unicode__ ( ) , '<STR_LIT>' ) <EOL> self . assertEqual ( channel2 . __unicode__ ( ) , '<STR_LIT>' ) <EOL> def test_get_absolute_url ( self ) : <EOL> self . test_unicode ( ) </s>
