<s> from __future__ import unicode_literals <EOL> import unittest <EOL> import spotify <EOL> import tests <EOL> from tests import mock <EOL> @ mock . patch ( '<STR_LIT>' , spec = spotify . lib ) <EOL> @ mock . patch ( '<STR_LIT>' , spec = spotify . lib ) <EOL> class ConnectionTest ( unittest . TestCase ) : <EOL> def tearDown ( self ) : <EOL> spotify . _session_instance = None <EOL> def test_connection_state ( self , session_lib_mock , lib_mock ) : <EOL> lib_mock . sp_session_connectionstate . return_value = int ( <EOL> spotify . ConnectionState . LOGGED_OUT ) <EOL> session = tests . create_real_session ( session_lib_mock ) <EOL> self . assertIs ( <EOL> session . connection . state , spotify . ConnectionState . LOGGED_OUT ) <EOL> lib_mock . sp_session_connectionstate . assert_called_once_with ( <EOL> session . _sp_session ) <EOL> def test_connection_type_defaults_to_unknown ( <EOL> self , session_lib_mock , lib_mock ) : <EOL> lib_mock . sp_session_set_connection_type . return_value = ( <EOL> spotify . ErrorType . OK ) <EOL> session = tests . create_real_session ( session_lib_mock ) <EOL> result = session . connection . type <EOL> self . assertIs ( result , spotify . ConnectionType . UNKNOWN ) <EOL> self . assertEqual ( lib_mock . sp_session_set_connection_type . call_count , <NUM_LIT:0> ) <EOL> def test_set_connection_type ( self , session_lib_mock , lib_mock ) : <EOL> lib_mock . sp_session_set_connection_type . return_value = ( <EOL> spotify . ErrorType . OK ) <EOL> session = tests . create_real_session ( session_lib_mock ) <EOL> session . connection . type = spotify . ConnectionType . MOBILE_ROAMING <EOL> lib_mock . sp_session_set_connection_type . assert_called_with ( <EOL> session . _sp_session , spotify . ConnectionType . MOBILE_ROAMING ) <EOL> result = session . connection . type <EOL> self . assertIs ( result , spotify . ConnectionType . MOBILE_ROAMING ) <EOL> def test_set_connection_type_fail_raises_error ( <EOL> self , session_lib_mock , lib_mock ) : <EOL> lib_mock . sp_session_set_connection_type . return_value = ( <EOL> spotify . ErrorType . BAD_API_VERSION ) <EOL> session = tests . create_real_session ( session_lib_mock ) <EOL> with self . assertRaises ( spotify . Error ) : <EOL> session . connection . type = spotify . ConnectionType . MOBILE_ROAMING <EOL> result = session . connection . type <EOL> self . assertIs ( result , spotify . ConnectionType . UNKNOWN ) <EOL> def test_allow_network_defaults_to_true ( self , session_lib_mock , lib_mock ) : <EOL> session = tests . create_real_session ( session_lib_mock ) <EOL> self . assertTrue ( session . connection . allow_network ) <EOL> def test_set_allow_network ( self , session_lib_mock , lib_mock ) : <EOL> lib_mock . sp_session_set_connection_rules . return_value = ( <EOL> spotify . ErrorType . OK ) <EOL> session = tests . create_real_session ( session_lib_mock ) <EOL> session . connection . allow_network = False <EOL> self . assertFalse ( session . connection . allow_network ) <EOL> lib_mock . sp_session_set_connection_rules . assert_called_with ( <EOL> session . _sp_session , <EOL> int ( spotify . ConnectionRule . ALLOW_SYNC_OVER_WIFI ) ) <EOL> def test_allow_network_if_roaming_defaults_to_false ( <EOL> self , session_lib_mock , lib_mock ) : <EOL> session = tests . create_real_session ( session_lib_mock ) <EOL> self . assertFalse ( session . connection . allow_network_if_roaming ) <EOL> def test_set_allow_network_if_roaming ( self , session_lib_mock , lib_mock ) : <EOL> lib_mock . sp_session_set_connection_rules . return_value = ( <EOL> spotify . ErrorType . OK ) <EOL> session = tests . create_real_session ( session_lib_mock ) <EOL> session . connection . allow_network_if_roaming = True <EOL> self . assertTrue ( session . connection . allow_network_if_roaming ) <EOL> lib_mock . sp_session_set_connection_rules . assert_called_with ( <EOL> session . _sp_session , <EOL> spotify . ConnectionRule . NETWORK | <EOL> spotify . ConnectionRule . NETWORK_IF_ROAMING | <EOL> spotify . ConnectionRule . ALLOW_SYNC_OVER_WIFI ) <EOL> def test_allow_sync_over_wifi_defaults_to_true ( <EOL> self , session_lib_mock , lib_mock ) : <EOL> session = tests . create_real_session ( session_lib_mock ) <EOL> self . assertTrue ( session . connection . allow_sync_over_wifi ) <EOL> def test_set_allow_sync_over_wifi ( self , session_lib_mock , lib_mock ) : <EOL> lib_mock . sp_session_set_connection_rules . return_value = ( <EOL> spotify . ErrorType . OK ) <EOL> session = tests . create_real_session ( session_lib_mock ) <EOL> session . connection . allow_sync_over_wifi = False <EOL> self . assertFalse ( session . connection . allow_sync_over_wifi ) <EOL> lib_mock . sp_session_set_connection_rules . assert_called_with ( <EOL> session . _sp_session , <EOL> int ( spotify . ConnectionRule . NETWORK ) ) <EOL> def test_allow_sync_over_mobile_defaults_to_false ( <EOL> self , session_lib_mock , lib_mock ) : <EOL> session = tests . create_real_session ( session_lib_mock ) <EOL> self . assertFalse ( session . connection . allow_sync_over_mobile ) <EOL> def test_set_allow_sync_over_mobile ( self , session_lib_mock , lib_mock ) : <EOL> lib_mock . sp_session_set_connection_rules . return_value = ( <EOL> spotify . ErrorType . OK ) <EOL> session = tests . create_real_session ( session_lib_mock ) <EOL> session . connection . allow_sync_over_mobile = True <EOL> self . assertTrue ( session . connection . allow_sync_over_mobile ) <EOL> lib_mock . sp_session_set_connection_rules . assert_called_with ( <EOL> session . _sp_session , <EOL> spotify . ConnectionRule . NETWORK | <EOL> spotify . ConnectionRule . ALLOW_SYNC_OVER_WIFI | <EOL> spotify . ConnectionRule . ALLOW_SYNC_OVER_MOBILE ) <EOL> def test_set_connection_rules_without_rules ( <EOL> self , session_lib_mock , lib_mock ) : <EOL> lib_mock . sp_session_set_connection_rules . return_value = ( <EOL> spotify . ErrorType . OK ) <EOL> session = tests . create_real_session ( session_lib_mock ) <EOL> session . connection . allow_network = False <EOL> session . connection . allow_sync_over_wifi = False <EOL> lib_mock . sp_session_set_connection_rules . assert_called_with ( <EOL> session . _sp_session , <NUM_LIT:0> ) <EOL> def test_set_connection_rules_fail_raises_error ( <EOL> self , session_lib_mock , lib_mock ) : <EOL> lib_mock . sp_session_set_connection_rules . return_value = ( <EOL> spotify . ErrorType . BAD_API_VERSION ) <EOL> session = tests . create_real_session ( session_lib_mock ) <EOL> with self . assertRaises ( spotify . Error ) : <EOL> session . connection . allow_network = False <EOL> class ConnectionRuleTest ( unittest . TestCase ) : <EOL> def test_has_constants ( self ) : <EOL> self . assertEqual ( spotify . ConnectionRule . NETWORK , <NUM_LIT:1> ) <EOL> self . assertEqual ( spotify . ConnectionRule . ALLOW_SYNC_OVER_WIFI , <NUM_LIT:8> ) <EOL> class ConnectionStateTest ( unittest . TestCase ) : <EOL> def test_has_constants ( self ) : <EOL> self . assertEqual ( spotify . ConnectionState . LOGGED_OUT , <NUM_LIT:0> ) <EOL> class ConnectionTypeTest ( unittest . TestCase ) : <EOL> def test_has_constants ( self ) : <EOL> self . assertEqual ( spotify . ConnectionType . UNKNOWN , <NUM_LIT:0> ) </s>
