<s> from datetime import datetime , timedelta <EOL> from nose . tools import eq_ <EOL> from kitsune . announcements . models import Announcement <EOL> from kitsune . announcements . tests import AnnouncementFactory <EOL> from kitsune . sumo . tests import TestCase <EOL> from kitsune . users . tests import UserFactory , GroupFactory <EOL> from kitsune . wiki . tests import LocaleFactory <EOL> class AnnouncementModelTests ( TestCase ) : <EOL> def setUp ( self ) : <EOL> super ( AnnouncementModelTests , self ) . setUp ( ) <EOL> self . creator = UserFactory ( ) <EOL> self . group = GroupFactory ( ) <EOL> self . locale = LocaleFactory ( locale = '<STR_LIT>' ) <EOL> self . creator . groups . add ( self . group ) <EOL> def test_active ( self ) : <EOL> """<STR_LIT>""" <EOL> AnnouncementFactory ( <EOL> show_after = datetime . now ( ) - timedelta ( days = <NUM_LIT:2> ) , <EOL> show_until = datetime . now ( ) + timedelta ( days = <NUM_LIT:2> ) ) <EOL> eq_ ( <NUM_LIT:1> , Announcement . get_site_wide ( ) . count ( ) ) <EOL> def test_always_visible ( self ) : <EOL> """<STR_LIT>""" <EOL> AnnouncementFactory ( show_after = datetime . now ( ) + timedelta ( days = <NUM_LIT:2> ) ) <EOL> AnnouncementFactory ( <EOL> show_after = datetime . now ( ) - timedelta ( days = <NUM_LIT:2> ) , <EOL> content = '<STR_LIT>' ) <EOL> site_wide = Announcement . get_site_wide ( ) <EOL> eq_ ( <NUM_LIT:1> , site_wide . count ( ) ) <EOL> eq_ ( '<STR_LIT>' , site_wide [ <NUM_LIT:0> ] . content ) <EOL> def test_group_excluded ( self ) : <EOL> """<STR_LIT>""" <EOL> AnnouncementFactory ( group = self . group ) <EOL> eq_ ( <NUM_LIT:0> , Announcement . get_site_wide ( ) . count ( ) ) <EOL> def test_get_for_group_id ( self ) : <EOL> """<STR_LIT>""" <EOL> AnnouncementFactory ( ) <EOL> a = AnnouncementFactory ( group = self . group ) <EOL> group_ann = Announcement . get_for_group_id ( self . group . id ) <EOL> eq_ ( <NUM_LIT:1> , len ( group_ann ) ) <EOL> eq_ ( a , group_ann [ <NUM_LIT:0> ] ) <EOL> def test_get_for_locale_name ( self ) : <EOL> """<STR_LIT>""" <EOL> AnnouncementFactory ( ) <EOL> a = AnnouncementFactory ( locale = self . locale ) <EOL> locale_ann = Announcement . get_for_locale_name ( self . locale . locale ) <EOL> eq_ ( <NUM_LIT:1> , locale_ann . count ( ) ) <EOL> eq_ ( a , locale_ann [ <NUM_LIT:0> ] ) </s>
