<s> import os <EOL> from mock import MagicMock <EOL> from serf_master import SerfHandler , SerfHandlerProxy <EOL> class TestSerfHandler : <EOL> def setup ( self ) : <EOL> os . environ = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> self . load_handler ( ) <EOL> def load_handler ( self ) : <EOL> self . handler = SerfHandler ( ) <EOL> def test_name_set_from_env ( self ) : <EOL> assert self . handler . name == '<STR_LIT>' <EOL> def test_role_set_from_env ( self ) : <EOL> assert self . handler . role == '<STR_LIT>' <EOL> def test_event_set_from_env ( self ) : <EOL> assert self . handler . event == '<STR_LIT>' <EOL> def test_custom_event ( self ) : <EOL> os . environ [ '<STR_LIT>' ] = '<STR_LIT:user>' <EOL> self . load_handler ( ) <EOL> assert self . handler . event == '<STR_LIT>' <EOL> def test_query ( self ) : <EOL> os . environ [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> self . load_handler ( ) <EOL> assert self . handler . event == '<STR_LIT>' <EOL> class TestSerfHandlerTags : <EOL> def setup ( self ) : <EOL> os . environ = { <EOL> '<STR_LIT>' : '<STR_LIT:null>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:null>' , <EOL> } <EOL> self . handler = SerfHandlerProxy ( ) <EOL> self . handler . log = MagicMock ( return_value = True ) <EOL> assert len ( self . handler . handlers ) == <NUM_LIT:0> <EOL> def test_role_set_from_env ( self ) : <EOL> assert self . handler . role == '<STR_LIT>' <EOL> class TestSerfHandlerRoleOverloading : <EOL> def setup ( self ) : <EOL> os . environ = { <EOL> '<STR_LIT>' : '<STR_LIT:null>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:null>' , <EOL> } <EOL> self . handler = SerfHandlerProxy ( ) <EOL> self . handler . log = MagicMock ( return_value = True ) <EOL> assert len ( self . handler . handlers ) == <NUM_LIT:0> <EOL> def test_role_set_from_env ( self ) : <EOL> assert self . handler . role == '<STR_LIT>' <EOL> class TestSerfHandlerNegativeCases : <EOL> def setup ( self ) : <EOL> os . environ = { <EOL> '<STR_LIT>' : '<STR_LIT:null>' , <EOL> '<STR_LIT>' : '<STR_LIT:null>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> self . handler = SerfHandlerProxy ( ) <EOL> self . handler . log = MagicMock ( return_value = True ) <EOL> assert len ( self . handler . handlers ) == <NUM_LIT:0> <EOL> def test_no_handler ( self ) : <EOL> self . handler . run ( ) <EOL> self . handler . log . assert_called_with ( "<STR_LIT>" ) <EOL> def test_no_method_implemented ( self ) : <EOL> self . handler . register ( '<STR_LIT:default>' , SerfHandler ( ) ) <EOL> assert len ( self . handler . handlers ) == <NUM_LIT:1> <EOL> self . handler . run ( ) <EOL> self . handler . log . assert_called_with ( "<STR_LIT>" ) <EOL> class TestSerfHandlerProxyCustomEvent : <EOL> def test_method_implemented ( self ) : <EOL> os . environ = { <EOL> '<STR_LIT>' : '<STR_LIT:null>' , <EOL> '<STR_LIT>' : '<STR_LIT:null>' , <EOL> '<STR_LIT>' : '<STR_LIT:user>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> handler = SerfHandlerProxy ( ) <EOL> sample = SerfHandler ( ) <EOL> sample . implemented = MagicMock ( return_value = True ) <EOL> assert len ( handler . handlers ) == <NUM_LIT:0> <EOL> handler . register ( '<STR_LIT:default>' , sample ) <EOL> assert len ( handler . handlers ) == <NUM_LIT:1> <EOL> handler . run ( ) <EOL> sample . implemented . assert_called_with ( ) <EOL> class TestSerfHandlerProxyStandardEvent : <EOL> def setup ( self ) : <EOL> os . environ = { <EOL> '<STR_LIT>' : '<STR_LIT:null>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> self . handler = SerfHandlerProxy ( ) <EOL> self . sample = SerfHandler ( ) <EOL> self . sample . member_join = MagicMock ( return_value = True ) <EOL> def test_standard_events_called ( self ) : <EOL> self . handler . register ( '<STR_LIT:default>' , self . sample ) <EOL> assert len ( self . handler . handlers ) == <NUM_LIT:1> <EOL> assert '<STR_LIT:default>' in self . handler . handlers <EOL> self . handler . run ( ) <EOL> self . sample . member_join . assert_called_with ( ) <EOL> def test_role_registration ( self ) : <EOL> self . handler . register ( '<STR_LIT>' , self . sample ) <EOL> assert len ( self . handler . handlers ) == <NUM_LIT:1> <EOL> assert '<STR_LIT>' in self . handler . handlers <EOL> self . handler . run ( ) <EOL> self . sample . member_join . assert_called_with ( ) </s>
