<s> from daapserver . provider import Provider <EOL> from daapserver . models import Server <EOL> import unittest <EOL> class Latch ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> """<STR_LIT>""" <EOL> self . toggled = False <EOL> self . args = None <EOL> self . kwargs = None <EOL> def __call__ ( self , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> self . toggled = True <EOL> self . args = args <EOL> self . kwargs = kwargs <EOL> class TestProvider ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> """<STR_LIT>""" <EOL> self . provider = Provider ( ) <EOL> self . provider . server = Server ( ) <EOL> def test_hooks ( self ) : <EOL> """<STR_LIT>""" <EOL> updated = Latch ( ) <EOL> session_created = Latch ( ) <EOL> session_destroyed = Latch ( ) <EOL> self . provider . hooks [ "<STR_LIT>" ] . append ( updated ) <EOL> self . provider . hooks [ "<STR_LIT>" ] . append ( session_created ) <EOL> self . provider . hooks [ "<STR_LIT>" ] . append ( session_destroyed ) <EOL> self . provider . update ( ) <EOL> self . assertTrue ( updated . toggled ) <EOL> self . provider . create_session ( "<STR_LIT>" , "<STR_LIT:127.0.0.1>" , "<STR_LIT:1.0>" ) <EOL> self . assertTrue ( session_created . toggled ) <EOL> self . assertEqual ( session_created . args [ <NUM_LIT:0> ] , <NUM_LIT:1> ) <EOL> self . provider . destroy_session ( <NUM_LIT:1> ) <EOL> self . assertTrue ( session_destroyed . toggled ) <EOL> self . assertEqual ( session_destroyed . args [ <NUM_LIT:0> ] , <NUM_LIT:1> ) </s>
