<s> import ari <EOL> import httpretty <EOL> import json <EOL> import requests <EOL> import unittest <EOL> import urllib <EOL> from ari_test . utils import AriTestCase <EOL> GET = httpretty . GET <EOL> PUT = httpretty . PUT <EOL> POST = httpretty . POST <EOL> DELETE = httpretty . DELETE <EOL> class ClientTest ( AriTestCase ) : <EOL> def test_docs ( self ) : <EOL> fp = urllib . urlopen ( "<STR_LIT>" ) <EOL> try : <EOL> actual = json . load ( fp ) <EOL> self . assertEqual ( self . BASE_URL , actual [ '<STR_LIT>' ] ) <EOL> finally : <EOL> fp . close ( ) <EOL> def test_empty_listing ( self ) : <EOL> self . serve ( GET , '<STR_LIT>' , body = '<STR_LIT>' ) <EOL> actual = self . uut . channels . list ( ) <EOL> self . assertEqual ( [ ] , actual ) <EOL> def test_one_listing ( self ) : <EOL> self . serve ( GET , '<STR_LIT>' , body = '<STR_LIT>' ) <EOL> self . serve ( DELETE , '<STR_LIT>' , '<STR_LIT>' ) <EOL> actual = self . uut . channels . list ( ) <EOL> self . assertEqual ( <NUM_LIT:1> , len ( actual ) ) <EOL> actual [ <NUM_LIT:0> ] . hangup ( ) <EOL> def test_play ( self ) : <EOL> self . serve ( GET , '<STR_LIT>' , '<STR_LIT>' , <EOL> body = '<STR_LIT>' ) <EOL> self . serve ( POST , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> body = '<STR_LIT>' ) <EOL> self . serve ( DELETE , '<STR_LIT>' , '<STR_LIT>' ) <EOL> channel = self . uut . channels . get ( channelId = '<STR_LIT>' ) <EOL> playback = channel . play ( media = '<STR_LIT>' ) <EOL> playback . stop ( ) <EOL> def test_bad_resource ( self ) : <EOL> try : <EOL> self . uut . i_am_not_a_resource . list ( ) <EOL> self . fail ( "<STR_LIT>" ) <EOL> except AttributeError : <EOL> pass <EOL> def test_bad_repo_method ( self ) : <EOL> try : <EOL> self . uut . channels . i_am_not_a_method ( ) <EOL> self . fail ( "<STR_LIT>" ) <EOL> except AttributeError : <EOL> pass <EOL> def test_bad_object_method ( self ) : <EOL> self . serve ( GET , '<STR_LIT>' , '<STR_LIT>' , <EOL> body = '<STR_LIT>' ) <EOL> try : <EOL> channel = self . uut . channels . get ( channelId = '<STR_LIT>' ) <EOL> channel . i_am_not_a_method ( ) <EOL> self . fail ( "<STR_LIT>" ) <EOL> except AttributeError : <EOL> pass <EOL> def test_bad_param ( self ) : <EOL> try : <EOL> self . uut . channels . list ( i_am_not_a_param = '<STR_LIT>' ) <EOL> self . fail ( "<STR_LIT>" ) <EOL> except TypeError : <EOL> pass <EOL> def test_bad_response ( self ) : <EOL> self . serve ( GET , '<STR_LIT>' , body = '<STR_LIT>' , <EOL> status = <NUM_LIT> ) <EOL> try : <EOL> self . uut . channels . list ( ) <EOL> self . fail ( "<STR_LIT>" ) <EOL> except requests . HTTPError as e : <EOL> self . assertEqual ( <NUM_LIT> , e . response . status_code ) <EOL> self . assertEqual ( <EOL> { "<STR_LIT:message>" : "<STR_LIT>" } , e . response . json ( ) ) <EOL> def test_endpoints ( self ) : <EOL> self . serve ( GET , '<STR_LIT>' , <EOL> body = '<STR_LIT>' ) <EOL> self . serve ( GET , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> body = '<STR_LIT>' ) <EOL> endpoints = self . uut . endpoints . list ( ) <EOL> self . assertEqual ( <NUM_LIT:1> , len ( endpoints ) ) <EOL> endpoint = endpoints [ <NUM_LIT:0> ] . get ( ) <EOL> self . assertEqual ( '<STR_LIT>' , endpoint . json [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( '<STR_LIT>' , endpoint . json [ '<STR_LIT>' ] ) <EOL> def test_live_recording ( self ) : <EOL> self . serve ( GET , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> body = '<STR_LIT>' ) <EOL> self . serve ( DELETE , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , status = <NUM_LIT> ) <EOL> recording = self . uut . recordings . getLive ( recordingName = '<STR_LIT>' ) <EOL> recording . cancel ( ) <EOL> def test_stored_recording ( self ) : <EOL> self . serve ( GET , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> body = '<STR_LIT>' ) <EOL> self . serve ( DELETE , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> status = <NUM_LIT> ) <EOL> recording = self . uut . recordings . getStored ( <EOL> recordingName = '<STR_LIT>' ) <EOL> recording . deleteStored ( ) <EOL> def test_mailboxes ( self ) : <EOL> self . serve ( PUT , '<STR_LIT>' , '<STR_LIT>' , <EOL> body = '<STR_LIT>' ) <EOL> mailbox = self . uut . mailboxes . update ( <EOL> mailboxName = '<STR_LIT>' , <EOL> oldMessages = '<STR_LIT:1>' , <EOL> newMessages = '<STR_LIT:3>' ) <EOL> self . assertEqual ( '<STR_LIT>' , mailbox [ '<STR_LIT:name>' ] ) <EOL> self . assertEqual ( '<STR_LIT:1>' , mailbox [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( '<STR_LIT:3>' , mailbox [ '<STR_LIT>' ] ) <EOL> def test_device_state ( self ) : <EOL> self . serve ( PUT , '<STR_LIT>' , '<STR_LIT>' , <EOL> body = '<STR_LIT>' ) <EOL> device_state = self . uut . deviceStates . update ( <EOL> deviceName = '<STR_LIT>' , <EOL> deviceState = '<STR_LIT>' ) <EOL> self . assertEqual ( '<STR_LIT>' , device_state [ '<STR_LIT:name>' ] ) <EOL> self . assertEqual ( '<STR_LIT>' , device_state [ '<STR_LIT:state>' ] ) <EOL> def setUp ( self ) : <EOL> super ( ClientTest , self ) . setUp ( ) <EOL> self . uut = ari . connect ( '<STR_LIT>' , '<STR_LIT:test>' , '<STR_LIT:test>' ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> unittest . main ( ) </s>
