<s> from datetime import datetime <EOL> from datetime import date <EOL> from datetime import timedelta <EOL> from base import TestbedTest <EOL> from models import Event <EOL> from models import Service <EOL> from models import Status <EOL> class HistoryTest ( TestbedTest ) : <EOL> def setUp ( self ) : <EOL> super ( HistoryTest , self ) . setUp ( ) <EOL> Status . load_defaults ( ) <EOL> self . service = Service ( slug = "<STR_LIT>" , name = "<STR_LIT>" , <EOL> description = "<STR_LIT>" ) <EOL> self . service . put ( ) <EOL> def test_history_order ( self ) : <EOL> start = date ( <NUM_LIT> , <NUM_LIT:4> , <NUM_LIT> ) <EOL> up = Status . get_by_slug ( "<STR_LIT>" ) <EOL> history = self . service . history ( <NUM_LIT:5> , up , start = start ) <EOL> self . assertEquals ( len ( history ) , <NUM_LIT:5> ) <EOL> history_days = [ h [ "<STR_LIT>" ] for h in history ] <EOL> expected = [ <EOL> date ( <NUM_LIT> , <NUM_LIT:4> , <NUM_LIT:12> ) , <EOL> date ( <NUM_LIT> , <NUM_LIT:4> , <NUM_LIT:11> ) , <EOL> date ( <NUM_LIT> , <NUM_LIT:4> , <NUM_LIT:10> ) , <EOL> date ( <NUM_LIT> , <NUM_LIT:4> , <NUM_LIT:9> ) , <EOL> date ( <NUM_LIT> , <NUM_LIT:4> , <NUM_LIT:8> ) , <EOL> ] <EOL> self . assertEquals ( history_days , expected ) <EOL> def test_history_order_early_month ( self ) : <EOL> start = date ( <NUM_LIT> , <NUM_LIT:4> , <NUM_LIT:2> ) <EOL> up = Status . get_by_slug ( "<STR_LIT>" ) <EOL> history = self . service . history ( <NUM_LIT:5> , up , start = start ) <EOL> history_days = [ h [ "<STR_LIT>" ] for h in history ] <EOL> expected = [ <EOL> date ( <NUM_LIT> , <NUM_LIT:4> , <NUM_LIT:1> ) , <EOL> date ( <NUM_LIT> , <NUM_LIT:3> , <NUM_LIT> ) , <EOL> date ( <NUM_LIT> , <NUM_LIT:3> , <NUM_LIT:30> ) , <EOL> date ( <NUM_LIT> , <NUM_LIT:3> , <NUM_LIT> ) , <EOL> date ( <NUM_LIT> , <NUM_LIT:3> , <NUM_LIT> ) , <EOL> ] <EOL> self . assertEquals ( history_days , expected ) <EOL> for h in history : <EOL> self . assertFalse ( h [ "<STR_LIT>" ] ) <EOL> def test_history_order_late_month ( self ) : <EOL> start = date ( <NUM_LIT> , <NUM_LIT:4> , <NUM_LIT:5> ) <EOL> up = Status . get_by_slug ( "<STR_LIT>" ) <EOL> history = self . service . history ( <NUM_LIT:5> , up , start = start ) <EOL> history_days = [ h [ "<STR_LIT>" ] for h in history ] <EOL> expected = [ <EOL> date ( <NUM_LIT> , <NUM_LIT:4> , <NUM_LIT:4> ) , <EOL> date ( <NUM_LIT> , <NUM_LIT:4> , <NUM_LIT:3> ) , <EOL> date ( <NUM_LIT> , <NUM_LIT:4> , <NUM_LIT:2> ) , <EOL> date ( <NUM_LIT> , <NUM_LIT:4> , <NUM_LIT:1> ) , <EOL> date ( <NUM_LIT> , <NUM_LIT:3> , <NUM_LIT> ) , <EOL> ] <EOL> self . assertEquals ( history_days , expected ) <EOL> def test_history_no_errors_boundary ( self ) : <EOL> down = Status . get_by_slug ( "<STR_LIT>" ) <EOL> up = Status . get_by_slug ( "<STR_LIT>" ) <EOL> now = datetime ( <NUM_LIT> , <NUM_LIT:4> , <NUM_LIT:5> ) <EOL> event = Event ( status = down , service = self . service , start = now , message = "<STR_LIT>" ) <EOL> event . put ( ) <EOL> history = self . service . history ( <NUM_LIT:5> , up , start = date ( <NUM_LIT> , <NUM_LIT:4> , <NUM_LIT:5> ) ) <EOL> self . assertEquals ( history [ <NUM_LIT:0> ] [ "<STR_LIT>" ] , False ) <EOL> def test_history_one_error ( self ) : <EOL> down = Status . get_by_slug ( "<STR_LIT>" ) <EOL> up = Status . get_by_slug ( "<STR_LIT>" ) <EOL> now = datetime ( <NUM_LIT> , <NUM_LIT:4> , <NUM_LIT:4> , <NUM_LIT:12> ) <EOL> event = Event ( status = down , service = self . service , start = now , message = "<STR_LIT>" ) <EOL> event . put ( ) <EOL> history = self . service . history ( <NUM_LIT:5> , up , start = date ( <NUM_LIT> , <NUM_LIT:4> , <NUM_LIT:5> ) ) <EOL> self . assertEquals ( history [ <NUM_LIT:0> ] [ "<STR_LIT>" ] , True ) <EOL> self . assertEquals ( history [ <NUM_LIT:0> ] [ "<STR_LIT:name>" ] , "<STR_LIT>" ) <EOL> def test_history_one_error_boundary ( self ) : <EOL> down = Status . get_by_slug ( "<STR_LIT>" ) <EOL> up = Status . get_by_slug ( "<STR_LIT>" ) <EOL> now = datetime ( <NUM_LIT> , <NUM_LIT:3> , <NUM_LIT> ) <EOL> event = Event ( status = down , service = self . service , start = now , message = "<STR_LIT>" ) <EOL> event . put ( ) <EOL> history = self . service . history ( <NUM_LIT:5> , up , start = date ( <NUM_LIT> , <NUM_LIT:4> , <NUM_LIT:5> ) ) <EOL> self . assertEquals ( history [ <NUM_LIT:4> ] [ "<STR_LIT>" ] , True ) <EOL> self . assertEquals ( history [ <NUM_LIT:4> ] [ "<STR_LIT:name>" ] , "<STR_LIT>" ) <EOL> def test_history_count ( self ) : <EOL> up = Status . get_by_slug ( "<STR_LIT>" ) <EOL> history = self . service . history ( <NUM_LIT:10> , up , start = date ( <NUM_LIT> , <NUM_LIT:4> , <NUM_LIT:5> ) ) <EOL> self . assertEquals ( len ( history ) , <NUM_LIT:10> ) <EOL> def test_history_current_status ( self ) : <EOL> down = Status . get_by_slug ( "<STR_LIT>" ) <EOL> up = Status . get_by_slug ( "<STR_LIT>" ) <EOL> now = datetime ( <NUM_LIT> , <NUM_LIT:4> , <NUM_LIT:4> , <NUM_LIT:12> , <NUM_LIT> ) <EOL> event = Event ( status = down , service = self . service , start = now , message = "<STR_LIT>" ) <EOL> event . put ( ) <EOL> history , = self . service . history ( <NUM_LIT:1> , up , start = date ( <NUM_LIT> , <NUM_LIT:4> , <NUM_LIT:5> ) ) <EOL> self . assertEquals ( history [ "<STR_LIT>" ] , True ) </s>
