<s> import tower_cli <EOL> from tower_cli import models <EOL> from tower_cli . api import client <EOL> from tower_cli . utils import exceptions as exc <EOL> from tests . compat import unittest , mock <EOL> class GroupTests ( unittest . TestCase ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> self . gr = tower_cli . get_resource ( '<STR_LIT>' ) <EOL> def test_root_and_no_inventory ( self ) : <EOL> """<STR_LIT>""" <EOL> with self . assertRaises ( exc . UsageError ) : <EOL> self . gr . list ( root = True , inventory = None ) <EOL> def test_list_root ( self ) : <EOL> """<STR_LIT>""" <EOL> with client . test_mode as t : <EOL> t . register_json ( '<STR_LIT>' , { <EOL> '<STR_LIT:count>' : <NUM_LIT:2> , <EOL> '<STR_LIT>' : [ <EOL> { '<STR_LIT:id>' : <NUM_LIT:1> , '<STR_LIT:name>' : '<STR_LIT>' , '<STR_LIT>' : <NUM_LIT:1> } , <EOL> { '<STR_LIT:id>' : <NUM_LIT:2> , '<STR_LIT:name>' : '<STR_LIT>' , '<STR_LIT>' : <NUM_LIT:2> } , <EOL> ] , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : None , <EOL> } ) <EOL> result = self . gr . list ( root = True , inventory = <NUM_LIT:1> ) <EOL> self . assertEqual ( result [ '<STR_LIT>' ] , [ <EOL> { '<STR_LIT:id>' : <NUM_LIT:1> , '<STR_LIT:name>' : '<STR_LIT>' , '<STR_LIT>' : <NUM_LIT:1> } , <EOL> { '<STR_LIT:id>' : <NUM_LIT:2> , '<STR_LIT:name>' : '<STR_LIT>' , '<STR_LIT>' : <NUM_LIT:2> } , <EOL> ] ) <EOL> def test_list_normal_situation ( self ) : <EOL> """<STR_LIT>""" <EOL> with mock . patch . object ( models . Resource , '<STR_LIT:list>' ) as super_list : <EOL> self . gr . list ( root = False ) <EOL> super_list . assert_called_once_with ( ) <EOL> def test_create_no_change ( self ) : <EOL> """<STR_LIT>""" <EOL> with mock . patch . object ( models . Resource , '<STR_LIT>' ) as super_create : <EOL> super_create . return_value = { '<STR_LIT>' : False , '<STR_LIT:id>' : <NUM_LIT:1> } <EOL> with client . test_mode as t : <EOL> answer = self . gr . create ( name = '<STR_LIT>' , inventory = <NUM_LIT:1> ) <EOL> self . assertEqual ( len ( t . requests ) , <NUM_LIT:0> ) <EOL> super_create . assert_called_once_with ( <EOL> fail_on_found = False , force_on_exists = False , <EOL> name = '<STR_LIT>' , inventory = <NUM_LIT:1> ) <EOL> self . assertFalse ( answer [ '<STR_LIT>' ] ) <EOL> def test_create_change_but_no_isource_request_needed ( self ) : <EOL> """<STR_LIT>""" <EOL> with client . test_mode as t : <EOL> t . register_json ( '<STR_LIT>' , { <EOL> '<STR_LIT:count>' : <NUM_LIT:0> , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : [ ] , <EOL> } , method = '<STR_LIT:GET>' ) <EOL> t . register_json ( '<STR_LIT>' , { <EOL> '<STR_LIT:id>' : <NUM_LIT:1> , <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : <NUM_LIT:1> , <EOL> } , method = '<STR_LIT:POST>' ) <EOL> answer = self . gr . create ( name = '<STR_LIT>' , inventory = <NUM_LIT:1> ) <EOL> self . assertEqual ( len ( t . requests ) , <NUM_LIT:2> ) <EOL> self . assertTrue ( answer [ '<STR_LIT>' ] ) <EOL> def test_create_with_manual ( self ) : <EOL> """<STR_LIT>""" <EOL> with client . test_mode as t : <EOL> t . register_json ( '<STR_LIT>' , { <EOL> '<STR_LIT:count>' : <NUM_LIT:0> , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : [ ] , <EOL> } , method = '<STR_LIT:GET>' ) <EOL> t . register_json ( '<STR_LIT>' , { <EOL> '<STR_LIT:id>' : <NUM_LIT:1> , <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : <NUM_LIT:1> , <EOL> } , method = '<STR_LIT:POST>' ) <EOL> answer = self . gr . create ( name = '<STR_LIT>' , inventory = <NUM_LIT:1> , source = "<STR_LIT>" ) <EOL> self . assertEqual ( len ( t . requests ) , <NUM_LIT:2> ) <EOL> self . assertTrue ( answer [ '<STR_LIT>' ] ) <EOL> def test_create_change_with_isource_modify ( self ) : <EOL> """<STR_LIT>""" <EOL> with client . test_mode as t : <EOL> t . register_json ( '<STR_LIT>' , { <EOL> '<STR_LIT:count>' : <NUM_LIT:0> , '<STR_LIT>' : [ ] , <EOL> '<STR_LIT>' : None , '<STR_LIT>' : None , <EOL> } , method = '<STR_LIT:GET>' ) <EOL> t . register_json ( '<STR_LIT>' , { <EOL> '<STR_LIT:id>' : <NUM_LIT:1> , '<STR_LIT>' : <NUM_LIT:1> , '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : { '<STR_LIT>' : '<STR_LIT>' } , <EOL> } , method = '<STR_LIT:POST>' ) <EOL> t . register_json ( '<STR_LIT>' , { <EOL> '<STR_LIT:id>' : <NUM_LIT> , '<STR_LIT:source>' : '<STR_LIT>' , '<STR_LIT>' : None , <EOL> } , method = '<STR_LIT:GET>' ) <EOL> t . register_json ( '<STR_LIT>' , { <EOL> '<STR_LIT:id>' : <NUM_LIT> , <EOL> '<STR_LIT:source>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : None , <EOL> } , method = '<STR_LIT>' ) <EOL> answer = self . gr . create ( name = '<STR_LIT>' , inventory = <NUM_LIT:1> , source = '<STR_LIT>' ) <EOL> self . assertEqual ( len ( t . requests ) , <NUM_LIT:4> ) <EOL> self . assertTrue ( answer [ '<STR_LIT>' ] ) <EOL> def test_create_FOE_with_isource_modify ( self ) : <EOL> """<STR_LIT>""" <EOL> Foo_data = { '<STR_LIT:id>' : <NUM_LIT:1> , '<STR_LIT:name>' : '<STR_LIT>' , '<STR_LIT>' : <NUM_LIT:1> , <EOL> '<STR_LIT>' : { '<STR_LIT>' : '<STR_LIT>' } } <EOL> with client . test_mode as t : <EOL> t . register_json ( '<STR_LIT>' , { <EOL> '<STR_LIT:count>' : <NUM_LIT:1> , '<STR_LIT>' : [ Foo_data ] , <EOL> '<STR_LIT>' : None , '<STR_LIT>' : None , <EOL> } , method = '<STR_LIT:GET>' ) <EOL> t . register_json ( '<STR_LIT>' , { <EOL> '<STR_LIT:id>' : <NUM_LIT> , '<STR_LIT:source>' : '<STR_LIT>' , '<STR_LIT>' : None , <EOL> } , method = '<STR_LIT:GET>' ) <EOL> answer = self . gr . create ( name = '<STR_LIT>' , inventory = <NUM_LIT:1> , source = '<STR_LIT>' , <EOL> force_on_exists = True ) <EOL> self . assertEqual ( len ( t . requests ) , <NUM_LIT:2> ) <EOL> self . assertFalse ( answer [ '<STR_LIT>' ] ) <EOL> def test_modify_no_change ( self ) : <EOL> """<STR_LIT>""" <EOL> with mock . patch . object ( models . Resource , '<STR_LIT>' ) as super_modify : <EOL> super_modify . return_value = { '<STR_LIT>' : False } <EOL> with client . test_mode as t : <EOL> self . gr . modify ( <NUM_LIT> , description = '<STR_LIT>' ) <EOL> self . assertEqual ( len ( t . requests ) , <NUM_LIT:0> ) <EOL> super_modify . assert_called_once_with ( <EOL> pk = <NUM_LIT> , create_on_missing = False , description = '<STR_LIT>' ) <EOL> def test_modify_with_source_attr_change ( self ) : <EOL> """<STR_LIT>""" <EOL> isrc = tower_cli . get_resource ( '<STR_LIT>' ) <EOL> with mock . patch . object ( type ( isrc ) , '<STR_LIT>' ) as isrc_modify : <EOL> isrc_modify . return_value = { '<STR_LIT>' : True } <EOL> with client . test_mode as t : <EOL> t . register_json ( '<STR_LIT>' , { <EOL> '<STR_LIT:id>' : <NUM_LIT:1> , '<STR_LIT:name>' : '<STR_LIT:foo>' , '<STR_LIT>' : <NUM_LIT:1> , <EOL> '<STR_LIT>' : { '<STR_LIT>' : '<STR_LIT>' } , <EOL> } , method = '<STR_LIT:GET>' ) <EOL> r = self . gr . modify ( <NUM_LIT:1> , name = '<STR_LIT:foo>' , source = '<STR_LIT>' ) <EOL> self . assertEqual ( len ( t . requests ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( r [ '<STR_LIT>' ] , True ) <EOL> isrc_modify . assert_called_once_with ( <EOL> pk = <NUM_LIT> , source = '<STR_LIT>' , force_on_exists = True , <EOL> ) <EOL> def test_modify_with_group_attr_change ( self ) : <EOL> """<STR_LIT>""" <EOL> isrc = tower_cli . get_resource ( '<STR_LIT>' ) <EOL> with mock . patch . object ( type ( isrc ) , '<STR_LIT>' ) as isrc_modify : <EOL> isrc_modify . return_value = { '<STR_LIT>' : False } <EOL> with client . test_mode as t : <EOL> t . register_json ( '<STR_LIT>' , { <EOL> '<STR_LIT:id>' : <NUM_LIT:1> , '<STR_LIT:name>' : '<STR_LIT:foo>' , '<STR_LIT>' : <NUM_LIT:1> , <EOL> '<STR_LIT>' : { '<STR_LIT>' : '<STR_LIT>' } , <EOL> } , method = '<STR_LIT:GET>' ) <EOL> t . register_json ( '<STR_LIT>' , { <EOL> '<STR_LIT:id>' : <NUM_LIT:1> , '<STR_LIT>' : True , <EOL> '<STR_LIT>' : { '<STR_LIT>' : '<STR_LIT>' } , <EOL> } , method = '<STR_LIT>' ) <EOL> r = self . gr . modify ( <EOL> <NUM_LIT:1> , name = '<STR_LIT:foo>' , description = '<STR_LIT>' , source = '<STR_LIT>' ) <EOL> self . assertEqual ( len ( t . requests ) , <NUM_LIT:2> ) <EOL> self . assertEqual ( r [ '<STR_LIT>' ] , True ) <EOL> def test_modify_with_change_manual ( self ) : <EOL> """<STR_LIT>""" <EOL> isrc = tower_cli . get_resource ( '<STR_LIT>' ) <EOL> with mock . patch . object ( type ( isrc ) , '<STR_LIT>' ) as isrc_modify : <EOL> with client . test_mode as t : <EOL> t . register_json ( '<STR_LIT>' , { <EOL> '<STR_LIT:id>' : <NUM_LIT:1> , '<STR_LIT:name>' : '<STR_LIT:foo>' , '<STR_LIT>' : <NUM_LIT:1> , <EOL> '<STR_LIT>' : { '<STR_LIT>' : '<STR_LIT>' } , <EOL> } , method = '<STR_LIT:GET>' ) <EOL> self . gr . modify ( <NUM_LIT:1> , name = '<STR_LIT:foo>' , source = '<STR_LIT>' ) <EOL> self . assertEqual ( len ( t . requests ) , <NUM_LIT:1> ) <EOL> isrc_modify . assert_called_once_with ( <EOL> pk = <NUM_LIT> , source = '<STR_LIT>' , force_on_exists = True , <EOL> ) <EOL> def test_sync ( self ) : <EOL> """<STR_LIT>""" <EOL> isrc = tower_cli . get_resource ( '<STR_LIT>' ) <EOL> with mock . patch . object ( type ( isrc ) , '<STR_LIT>' ) as isrc_sync : <EOL> with client . test_mode as t : <EOL> t . register_json ( '<STR_LIT>' , { <EOL> '<STR_LIT:id>' : <NUM_LIT:1> , '<STR_LIT:name>' : '<STR_LIT:foo>' , '<STR_LIT>' : <NUM_LIT:1> , <EOL> '<STR_LIT>' : { '<STR_LIT>' : '<STR_LIT>' } , <EOL> } , method = '<STR_LIT:GET>' ) <EOL> self . gr . sync ( <NUM_LIT:1> ) <EOL> isrc_sync . assert_called_once_with ( <NUM_LIT> , monitor = False , <EOL> timeout = None ) <EOL> self . assertEqual ( len ( t . requests ) , <NUM_LIT:1> ) </s>
