<s> import datetime <EOL> import random <EOL> import xml . etree . ElementTree <EOL> import models <EOL> import settings <EOL> from test_api import StashboardTest <EOL> class RSSFeedTest ( StashboardTest ) : <EOL> def setUp ( self ) : <EOL> super ( RSSFeedTest , self ) . setUp ( ) <EOL> self . services = [ ] <EOL> self . statuses = [ ] <EOL> for name in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] : <EOL> service = models . Service ( name = name . title ( ) , <EOL> slug = name , <EOL> description = "<STR_LIT>" ) <EOL> service . put ( ) <EOL> self . services . append ( service ) <EOL> for name in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] : <EOL> status = models . Status ( name = name . title ( ) , <EOL> slug = name , <EOL> description = "<STR_LIT>" , <EOL> image = "<STR_LIT>" ) <EOL> status . put ( ) <EOL> self . statuses . append ( status ) <EOL> def test_empty_feed ( self ) : <EOL> response = self . get ( "<STR_LIT>" ) <EOL> self . assertTrue ( "<STR_LIT>" in response . headers [ "<STR_LIT:Content-Type>" ] ) <EOL> self . assertEquals ( response . status_code , <NUM_LIT:200> ) <EOL> def test_feed_with_events ( self ) : <EOL> event = models . Event ( start = datetime . datetime . now ( ) , message = "<STR_LIT>" , <EOL> service = random . choice ( self . services ) , <EOL> status = random . choice ( self . statuses ) ) <EOL> event . put ( ) <EOL> response = self . get ( "<STR_LIT>" ) <EOL> self . assertTrue ( "<STR_LIT>" in response . headers [ "<STR_LIT:Content-Type>" ] ) <EOL> self . assertEquals ( response . status_code , <NUM_LIT:200> ) <EOL> result = xml . etree . ElementTree . fromstring ( response . content ) <EOL> self . assertEquals ( len ( result ) , <NUM_LIT:1> ) <EOL> self . assertEquals ( result [ <NUM_LIT:0> ] . tag , '<STR_LIT>' ) <EOL> channel = result [ <NUM_LIT:0> ] <EOL> self . assertEquals ( len ( channel . findall ( '<STR_LIT>' ) ) , <NUM_LIT:1> ) <EOL> for tag in [ '<STR_LIT:title>' , '<STR_LIT:description>' , '<STR_LIT>' ] : <EOL> self . assertEquals ( len ( channel . findall ( tag ) ) , <NUM_LIT:1> ) <EOL> item = channel . find ( '<STR_LIT>' ) <EOL> for tag in [ '<STR_LIT:title>' , '<STR_LIT:description>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] : <EOL> self . assertEquals ( len ( item . findall ( tag ) ) , <NUM_LIT:1> ) <EOL> def test_feed_does_not_exceed_max ( self ) : <EOL> for _ in xrange ( settings . RSS_NUM_EVENTS_TO_FETCH + <NUM_LIT:20> ) : <EOL> event = models . Event ( start = datetime . datetime . now ( ) , message = "<STR_LIT>" , <EOL> service = random . choice ( self . services ) , <EOL> status = random . choice ( self . statuses ) ) <EOL> event . put ( ) <EOL> response = self . get ( "<STR_LIT>" ) <EOL> self . assertTrue ( "<STR_LIT>" in response . headers [ "<STR_LIT:Content-Type>" ] ) <EOL> self . assertEquals ( response . status_code , <NUM_LIT:200> ) <EOL> result = xml . etree . ElementTree . fromstring ( response . content ) <EOL> self . assertEquals ( len ( result ) , <NUM_LIT:1> ) <EOL> self . assertEquals ( result [ <NUM_LIT:0> ] . tag , '<STR_LIT>' ) <EOL> channel = result [ <NUM_LIT:0> ] <EOL> self . assertEquals ( len ( channel . findall ( '<STR_LIT>' ) ) , settings . RSS_NUM_EVENTS_TO_FETCH ) </s>
