<s> from datetime import datetime <EOL> from django . test import TestCase <EOL> from mock import MagicMock <EOL> from corehq . apps . users . dbaccessors . all_commcare_users import delete_all_users <EOL> from corehq . apps . users . models import CommCareUser <EOL> from corehq . apps . domain . models import Domain <EOL> from corehq . apps . fixtures . models import UserFixtureStatus , UserFixtureType <EOL> class TestFixtureStatus ( TestCase ) : <EOL> def setUp ( self ) : <EOL> self . _delete_everything ( ) <EOL> self . username = "<STR_LIT>" <EOL> password = "<STR_LIT:password>" <EOL> self . domain = Domain ( name = '<STR_LIT>' ) <EOL> self . domain . save ( ) <EOL> self . couch_user = CommCareUser . create ( self . domain . name , self . username , password ) <EOL> self . couch_user . save ( ) <EOL> def tearDown ( self ) : <EOL> self . _delete_everything ( ) <EOL> def _delete_everything ( self ) : <EOL> delete_all_users ( ) <EOL> UserFixtureStatus . objects . all ( ) . delete ( ) <EOL> def test_get_statuses ( self ) : <EOL> no_status = { UserFixtureType . CHOICES [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] : UserFixtureStatus . DEFAULT_LAST_MODIFIED } <EOL> self . assertEqual ( self . couch_user . _get_fixture_statuses ( ) , no_status ) <EOL> now = datetime . utcnow ( ) <EOL> UserFixtureStatus ( <EOL> user_id = self . couch_user . _id , <EOL> fixture_type = UserFixtureType . CHOICES [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] , <EOL> last_modified = now , <EOL> ) . save ( ) <EOL> expected_status = { UserFixtureType . CHOICES [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] : now } <EOL> self . assertEqual ( self . couch_user . _get_fixture_statuses ( ) , expected_status ) <EOL> def test_get_status ( self ) : <EOL> now = datetime . utcnow ( ) <EOL> couch_user = CommCareUser . get_by_username ( self . username ) <EOL> UserFixtureStatus ( <EOL> user_id = self . couch_user . _id , <EOL> fixture_type = UserFixtureType . CHOICES [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] , <EOL> last_modified = now , <EOL> ) . save ( ) <EOL> self . assertEqual ( self . couch_user . fixture_status ( "<STR_LIT>" ) , UserFixtureStatus . DEFAULT_LAST_MODIFIED ) <EOL> self . assertEqual ( couch_user . fixture_status ( UserFixtureType . CHOICES [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] ) , now ) <EOL> def test_update_status_set_location ( self ) : <EOL> fake_location = MagicMock ( ) <EOL> fake_location . location_id = "<STR_LIT>" <EOL> fake_location . group_id = "<STR_LIT>" <EOL> self . assertEqual ( UserFixtureStatus . objects . all ( ) . count ( ) , <NUM_LIT:0> ) <EOL> self . couch_user . set_location ( fake_location ) <EOL> self . assertEqual ( UserFixtureStatus . objects . all ( ) . count ( ) , <NUM_LIT:1> ) <EOL> user_fixture_status = UserFixtureStatus . objects . first ( ) <EOL> self . assertEqual ( user_fixture_status . user_id , self . couch_user . _id ) <EOL> self . assertEqual ( user_fixture_status . fixture_type , UserFixtureType . LOCATION ) <EOL> def test_update_status_unset_location ( self ) : <EOL> fake_location = MagicMock ( ) <EOL> fake_location . location_id = "<STR_LIT>" <EOL> fake_location . group_id = "<STR_LIT>" <EOL> self . couch_user . set_location ( fake_location ) <EOL> previously_updated_time = UserFixtureStatus . objects . get ( user_id = self . couch_user . _id ) . last_modified <EOL> self . couch_user . unset_location ( ) <EOL> new_updated_time = UserFixtureStatus . objects . get ( user_id = self . couch_user . _id ) . last_modified <EOL> self . assertTrue ( new_updated_time > previously_updated_time ) <EOL> def test_update_status_reset_location ( self ) : <EOL> fake_location = MagicMock ( ) <EOL> fake_location . location_id = "<STR_LIT>" <EOL> fake_location . group_id = "<STR_LIT>" <EOL> self . couch_user . set_location ( fake_location ) <EOL> previously_updated_time = UserFixtureStatus . objects . get ( user_id = self . couch_user . _id ) . last_modified <EOL> fake_location . location_id = "<STR_LIT>" <EOL> fake_location . group_id = "<STR_LIT>" <EOL> self . couch_user . set_location ( fake_location ) <EOL> new_updated_time = UserFixtureStatus . objects . get ( user_id = self . couch_user . _id ) . last_modified <EOL> self . assertTrue ( new_updated_time > previously_updated_time ) </s>
