<s> import pytest <EOL> from sqlalchemy . exc import IntegrityError <EOL> from hermes import exc <EOL> from hermes . models import Host , EventType , Labor , Event <EOL> from . fixtures import db_engine , session , sample_data1 <EOL> def test_creation ( session ) : <EOL> Host . create ( session , "<STR_LIT>" ) <EOL> session . commit ( ) <EOL> hosts = session . query ( Host ) . all ( ) <EOL> assert len ( hosts ) == <NUM_LIT:1> <EOL> assert hosts [ <NUM_LIT:0> ] . id == <NUM_LIT:1> <EOL> assert hosts [ <NUM_LIT:0> ] . hostname == "<STR_LIT>" <EOL> host = Host . get_host ( session , "<STR_LIT>" ) <EOL> assert host . id == <NUM_LIT:1> <EOL> assert host . hostname == "<STR_LIT>" <EOL> def test_duplicate ( session ) : <EOL> Host . create ( session , "<STR_LIT>" ) <EOL> with pytest . raises ( IntegrityError ) : <EOL> Host . create ( session , "<STR_LIT>" ) <EOL> Host . create ( session , "<STR_LIT>" ) <EOL> def test_required ( session ) : <EOL> Host . create ( session , "<STR_LIT>" ) <EOL> with pytest . raises ( exc . ValidationError ) : <EOL> Host . create ( session , None ) <EOL> def test_get_latest_events ( sample_data1 ) : <EOL> host = Host . get_host ( sample_data1 , "<STR_LIT>" ) <EOL> assert host . id == <NUM_LIT:1> <EOL> assert host . hostname == "<STR_LIT>" <EOL> events = host . get_latest_events ( ) . all ( ) <EOL> assert len ( events ) == <NUM_LIT:2> <EOL> assert events [ <NUM_LIT:0> ] . note == "<STR_LIT>" <EOL> def test_get_labors ( sample_data1 ) : <EOL> host = Host . get_host ( sample_data1 , "<STR_LIT>" ) <EOL> assert host . id == <NUM_LIT:1> <EOL> assert len ( host . labors ) == <NUM_LIT:0> <EOL> event_type1 = sample_data1 . query ( EventType ) . get ( <NUM_LIT:1> ) <EOL> event_type3 = sample_data1 . query ( EventType ) . get ( <NUM_LIT:3> ) <EOL> event_type4 = sample_data1 . query ( EventType ) . get ( <NUM_LIT:4> ) <EOL> print "<STR_LIT>" <EOL> Event . create ( sample_data1 , host , "<STR_LIT>" , event_type1 ) <EOL> print "<STR_LIT>" <EOL> Event . create ( sample_data1 , host , "<STR_LIT>" , event_type3 ) <EOL> print "<STR_LIT>" <EOL> closing_event = Event . create ( sample_data1 , host , "<STR_LIT>" , event_type4 ) <EOL> print "<STR_LIT>" <EOL> all_labors = host . get_labors ( ) . all ( ) <EOL> open_labors = host . get_open_labors ( ) . all ( ) <EOL> assert len ( all_labors ) == <NUM_LIT:3> <EOL> assert len ( host . labors ) == <NUM_LIT:3> <EOL> assert len ( open_labors ) == <NUM_LIT:1> <EOL> assert all_labors [ <NUM_LIT:0> ] . completion_time is None <EOL> assert all_labors [ <NUM_LIT:0> ] . completion_event is None <EOL> assert all_labors [ <NUM_LIT:1> ] . completion_time is not None <EOL> assert all_labors [ <NUM_LIT:1> ] . completion_event == closing_event <EOL> assert all_labors [ <NUM_LIT:0> ] . creation_event == closing_event </s>
