<s> from datetime import datetime <EOL> from twisted . trial import unittest <EOL> from twisted . internet import defer <EOL> from txtorcon . router import Router , hexIdFromHash , hashFromHexId <EOL> class FakeController ( object ) : <EOL> def get_info_raw ( self , i ) : <EOL> return defer . succeed ( '<STR_LIT>' ) <EOL> class UtilityTests ( unittest . TestCase ) : <EOL> def test_hex_converters ( self ) : <EOL> self . assertEqual ( <EOL> hexIdFromHash ( '<STR_LIT>' ) , <EOL> '<STR_LIT>' <EOL> ) <EOL> self . assertEqual ( <EOL> hashFromHexId ( '<STR_LIT>' ) , <EOL> '<STR_LIT>' <EOL> ) <EOL> self . assertEqual ( <EOL> hexIdFromHash ( hashFromHexId ( '<STR_LIT>' ) ) , <EOL> '<STR_LIT>' <EOL> ) <EOL> class RouterTests ( unittest . TestCase ) : <EOL> def test_ctor ( self ) : <EOL> controller = object ( ) <EOL> router = Router ( controller ) <EOL> router . update ( "<STR_LIT:foo>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" ) <EOL> self . assertEqual ( <EOL> router . id_hex , <EOL> "<STR_LIT>" <EOL> ) <EOL> self . assertTrue ( isinstance ( router . modified , datetime ) ) <EOL> self . assertTrue ( isinstance ( router . modified , datetime ) ) <EOL> self . assertEqual ( router . policy , '<STR_LIT>' ) <EOL> def test_unique_name ( self ) : <EOL> controller = object ( ) <EOL> router = Router ( controller ) <EOL> router . update ( "<STR_LIT:foo>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" ) <EOL> self . assertEqual ( <EOL> router . id_hex , <EOL> "<STR_LIT>" <EOL> ) <EOL> self . assertEqual ( <EOL> router . unique_name , <EOL> "<STR_LIT>" <EOL> ) <EOL> router . flags = [ '<STR_LIT>' ] <EOL> self . assertEqual ( router . unique_name , "<STR_LIT:foo>" ) <EOL> def test_flags ( self ) : <EOL> controller = object ( ) <EOL> router = Router ( controller ) <EOL> router . update ( "<STR_LIT:foo>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" ) <EOL> router . flags = "<STR_LIT>" . split ( ) <EOL> self . assertEqual ( router . name_is_unique , True ) <EOL> def test_flags_from_string ( self ) : <EOL> controller = object ( ) <EOL> router = Router ( controller ) <EOL> router . update ( "<STR_LIT:foo>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" ) <EOL> router . flags = "<STR_LIT>" <EOL> self . assertEqual ( router . name_is_unique , True ) <EOL> def test_policy_accept ( self ) : <EOL> controller = object ( ) <EOL> router = Router ( controller ) <EOL> router . update ( "<STR_LIT:foo>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" ) <EOL> router . policy = "<STR_LIT>" . split ( ) <EOL> self . assertTrue ( router . accepts_port ( <NUM_LIT> ) ) <EOL> for x in range ( <NUM_LIT> , <NUM_LIT> ) : <EOL> self . assertTrue ( router . accepts_port ( x ) ) <EOL> self . assertTrue ( not router . accepts_port ( <NUM_LIT> ) ) <EOL> self . assertEqual ( router . policy , '<STR_LIT>' ) <EOL> def test_policy_reject ( self ) : <EOL> controller = object ( ) <EOL> router = Router ( controller ) <EOL> router . update ( "<STR_LIT:foo>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" ) <EOL> router . policy = "<STR_LIT>" . split ( ) <EOL> for x in range ( <NUM_LIT:1> , <NUM_LIT> ) : <EOL> self . assertTrue ( router . accepts_port ( x ) ) <EOL> for x in range ( <NUM_LIT> , <NUM_LIT> ) : <EOL> self . assertTrue ( not router . accepts_port ( x ) ) <EOL> self . assertEqual ( router . policy , '<STR_LIT>' ) <EOL> def test_countrycode ( self ) : <EOL> class CountryCodeController ( object ) : <EOL> def get_info_raw ( self , i ) : <EOL> return defer . succeed ( <EOL> '<STR_LIT>' <EOL> ) <EOL> controller = CountryCodeController ( ) <EOL> router = Router ( controller ) <EOL> router . update ( "<STR_LIT:foo>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" ) <EOL> self . assertEqual ( router . location . countrycode , '<STR_LIT>' ) <EOL> def test_policy_error ( self ) : <EOL> router = Router ( object ( ) ) <EOL> try : <EOL> router . policy = '<STR_LIT>' <EOL> self . fail ( ) <EOL> except Exception , e : <EOL> self . assertTrue ( "<STR_LIT>" in str ( e ) ) <EOL> def test_policy_not_set_error ( self ) : <EOL> router = Router ( object ( ) ) <EOL> try : <EOL> router . accepts_port ( <NUM_LIT> ) <EOL> self . fail ( ) <EOL> except Exception , e : <EOL> self . assertTrue ( "<STR_LIT>" in str ( e ) ) <EOL> def test_repr ( self ) : <EOL> router = Router ( FakeController ( ) ) <EOL> router . update ( "<STR_LIT:foo>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" ) <EOL> router . flags = [ '<STR_LIT>' ] <EOL> repr ( router ) <EOL> def test_repr_no_update ( self ) : <EOL> router = Router ( FakeController ( ) ) <EOL> repr ( router ) </s>
