<s> import mock <EOL> from oslo_context import context as oslo_context <EOL> from ironic . common import context <EOL> from ironic . tests import base as tests_base <EOL> class RequestContextTestCase ( tests_base . TestCase ) : <EOL> def setUp ( self ) : <EOL> super ( RequestContextTestCase , self ) . setUp ( ) <EOL> @ mock . patch . object ( oslo_context . RequestContext , "<STR_LIT>" ) <EOL> def test_create_context ( self , context_mock ) : <EOL> test_context = context . RequestContext ( ) <EOL> context_mock . assert_called_once_with ( <EOL> auth_token = None , user = None , tenant = None , is_admin = False , <EOL> read_only = False , show_deleted = False , request_id = None , <EOL> overwrite = True ) <EOL> self . assertFalse ( test_context . is_public_api ) <EOL> self . assertIsNone ( test_context . domain_id ) <EOL> self . assertIsNone ( test_context . domain_name ) <EOL> self . assertTrue ( test_context . show_password ) <EOL> self . assertEqual ( [ ] , test_context . roles ) <EOL> def test_from_dict ( self ) : <EOL> dict = { <EOL> "<STR_LIT:user>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : True , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : False , <EOL> "<STR_LIT>" : None <EOL> } <EOL> ctx = context . RequestContext . from_dict ( dict ) <EOL> self . assertIsNone ( ctx . user ) <EOL> self . assertIsNone ( ctx . tenant ) <EOL> self . assertTrue ( ctx . is_public_api ) <EOL> self . assertEqual ( "<STR_LIT>" , ctx . domain_id ) <EOL> self . assertEqual ( "<STR_LIT>" , ctx . domain_name ) <EOL> self . assertFalse ( ctx . show_password ) <EOL> self . assertEqual ( [ ] , ctx . roles ) <EOL> def test_to_dict ( self ) : <EOL> values = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> "<STR_LIT:user>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> "<STR_LIT>" : True , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : False , <EOL> "<STR_LIT>" : None , <EOL> "<STR_LIT>" : True <EOL> } <EOL> ctx = context . RequestContext ( ** values ) <EOL> ctx_dict = ctx . to_dict ( ) <EOL> self . assertIn ( '<STR_LIT>' , ctx_dict ) <EOL> self . assertIn ( '<STR_LIT:user>' , ctx_dict ) <EOL> self . assertIn ( '<STR_LIT>' , ctx_dict ) <EOL> self . assertIn ( '<STR_LIT>' , ctx_dict ) <EOL> self . assertIn ( '<STR_LIT>' , ctx_dict ) <EOL> self . assertIn ( '<STR_LIT>' , ctx_dict ) <EOL> self . assertIn ( '<STR_LIT>' , ctx_dict ) <EOL> self . assertIn ( '<STR_LIT>' , ctx_dict ) <EOL> self . assertIn ( '<STR_LIT>' , ctx_dict ) <EOL> self . assertIn ( '<STR_LIT>' , ctx_dict ) <EOL> self . assertIn ( '<STR_LIT>' , ctx_dict ) <EOL> self . assertIn ( '<STR_LIT>' , ctx_dict ) <EOL> self . assertNotIn ( '<STR_LIT>' , ctx_dict ) <EOL> self . assertEqual ( '<STR_LIT>' , ctx_dict [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( '<STR_LIT>' , ctx_dict [ '<STR_LIT:user>' ] ) <EOL> self . assertEqual ( '<STR_LIT>' , ctx_dict [ '<STR_LIT>' ] ) <EOL> self . assertTrue ( ctx_dict [ '<STR_LIT>' ] ) <EOL> self . assertTrue ( ctx_dict [ '<STR_LIT>' ] ) <EOL> self . assertTrue ( ctx_dict [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( '<STR_LIT>' , ctx_dict [ '<STR_LIT>' ] ) <EOL> self . assertTrue ( ctx_dict [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( '<STR_LIT>' , ctx_dict [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( '<STR_LIT>' , ctx_dict [ '<STR_LIT>' ] ) <EOL> self . assertFalse ( ctx_dict [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( [ ] , ctx_dict [ '<STR_LIT>' ] ) <EOL> def test_get_admin_context ( self ) : <EOL> admin_context = context . get_admin_context ( ) <EOL> self . assertTrue ( admin_context . is_admin ) <EOL> @ mock . patch . object ( oslo_context , '<STR_LIT>' ) <EOL> def test_thread_without_context ( self , context_get_mock ) : <EOL> self . context . update_store = mock . Mock ( ) <EOL> context_get_mock . return_value = None <EOL> self . context . ensure_thread_contain_context ( ) <EOL> self . context . update_store . assert_called_once_with ( ) <EOL> @ mock . patch . object ( oslo_context , '<STR_LIT>' ) <EOL> def test_thread_with_context ( self , context_get_mock ) : <EOL> self . context . update_store = mock . Mock ( ) <EOL> context_get_mock . return_value = self . context <EOL> self . context . ensure_thread_contain_context ( ) <EOL> self . assertFalse ( self . context . update_store . called ) </s>
