<s> from django . test import TestCase <EOL> from corehq . apps . domain . models import Domain <EOL> from corehq . apps . users . dbaccessors . all_commcare_users import delete_all_users <EOL> from corehq . apps . users . models import CouchUser , WebUser , CommCareUser <EOL> from dimagi . utils . couch import get_cached_property <EOL> class PhoneUsersTestCase ( TestCase ) : <EOL> def setUp ( self ) : <EOL> delete_all_users ( ) <EOL> self . username = '<STR_LIT:username>' <EOL> self . password = '<STR_LIT:password>' <EOL> self . domain = '<STR_LIT>' <EOL> Domain ( name = self . domain ) . save ( ) <EOL> self . couch_user = WebUser . create ( self . domain , self . username , self . password ) <EOL> self . couch_user . language = '<STR_LIT>' <EOL> self . couch_user . save ( ) <EOL> def tearDown ( self ) : <EOL> user = WebUser . get_by_username ( self . username ) <EOL> if user : <EOL> user . delete ( ) <EOL> domain = Domain . get_by_name ( self . domain ) <EOL> if domain : <EOL> domain . delete ( ) <EOL> def testPhoneUsersViewNoNumberSet ( self ) : <EOL> phone_users_count = CouchUser . view ( "<STR_LIT>" , <EOL> key = self . domain ) . count ( ) <EOL> self . assertEquals ( phone_users_count , <NUM_LIT:0> ) <EOL> def testPhoneUsersViewDefaultNumber ( self ) : <EOL> self . couch_user . add_phone_number ( <NUM_LIT> ) <EOL> self . couch_user . add_phone_number ( <NUM_LIT> , default = True ) <EOL> self . couch_user . add_phone_number ( <NUM_LIT> ) <EOL> self . couch_user . save ( ) <EOL> phone_user = CouchUser . phone_users_by_domain ( self . domain ) . one ( ) <EOL> self . assertEquals ( phone_user . username , self . username ) <EOL> self . assertEquals ( phone_user . default_phone_number , '<STR_LIT>' ) <EOL> def testPhoneUsersChangeDefaultNumber ( self ) : <EOL> self . couch_user . add_phone_number ( <NUM_LIT> ) <EOL> self . couch_user . add_phone_number ( <NUM_LIT> , default = True ) <EOL> self . couch_user . save ( ) <EOL> self . assertEquals ( self . couch_user . default_phone_number , '<STR_LIT>' ) <EOL> self . couch_user . set_default_phone_number ( <NUM_LIT> ) <EOL> self . couch_user . save ( ) <EOL> self . assertEquals ( self . couch_user . default_phone_number , '<STR_LIT>' ) <EOL> def testPhoneUsersViewLastCommCareUsername ( self ) : <EOL> self . couch_user . delete ( ) <EOL> phone_user_count = CouchUser . phone_users_by_domain ( self . domain ) . count ( ) <EOL> self . assertEquals ( phone_user_count , <NUM_LIT:0> ) <EOL> couch_user = WebUser . create ( self . domain , '<STR_LIT>' , '<STR_LIT:password>' ) <EOL> couch_user . add_phone_number ( <NUM_LIT> ) <EOL> couch_user . save ( ) <EOL> phone_user_count = CouchUser . phone_users_by_domain ( self . domain ) . count ( ) <EOL> self . assertEquals ( phone_user_count , <NUM_LIT:1> ) <EOL> phone_user = CouchUser . phone_users_by_domain ( self . domain ) . one ( ) <EOL> self . assertEquals ( phone_user . username , '<STR_LIT>' ) <EOL> def testWebUserImplementsMobileMixIn ( self ) : <EOL> time_zone = self . couch_user . get_time_zone ( ) <EOL> self . assertEquals ( time_zone , '<STR_LIT>' ) <EOL> lang_code = self . couch_user . get_language_code ( ) <EOL> self . assertEquals ( lang_code , '<STR_LIT>' ) <EOL> def testDeletePhoneNumber ( self ) : <EOL> self . couch_user . add_phone_number ( '<STR_LIT>' ) <EOL> self . couch_user . save ( ) <EOL> self . assertEquals ( len ( self . couch_user . phone_numbers ) , <NUM_LIT:1> ) <EOL> self . couch_user . delete_phone_number ( '<STR_LIT>' ) <EOL> self . assertEquals ( len ( self . couch_user . phone_numbers ) , <NUM_LIT:0> ) <EOL> def test_get_cached_full_name ( self ) : <EOL> testuser = CommCareUser . create ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> FULL_NAME = "<STR_LIT>" <EOL> testuser . set_full_name ( FULL_NAME ) <EOL> testuser . save ( ) <EOL> cached_full_name = get_cached_property ( CouchUser , testuser . get_id , '<STR_LIT>' , expiry = <NUM_LIT:7> * <NUM_LIT> * <NUM_LIT> * <NUM_LIT> ) <EOL> self . assertEqual ( FULL_NAME , cached_full_name ) </s>
