<s> import copy <EOL> import mock <EOL> from novaclient import exceptions as nova_exceptions <EOL> from rally . plugins . openstack . context . nova import flavors <EOL> from tests . unit import test <EOL> CTX = "<STR_LIT>" <EOL> class FlavorsGeneratorTestCase ( test . TestCase ) : <EOL> def setUp ( self ) : <EOL> super ( FlavorsGeneratorTestCase , self ) . setUp ( ) <EOL> self . context = { <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : [ { <EOL> "<STR_LIT:name>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : <NUM_LIT> , <EOL> "<STR_LIT>" : <NUM_LIT:10> , <EOL> "<STR_LIT>" : <NUM_LIT:3> , <EOL> "<STR_LIT>" : <NUM_LIT:3> , <EOL> "<STR_LIT>" : <NUM_LIT:5> , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT:key>" : "<STR_LIT:value>" <EOL> } <EOL> } ] <EOL> } , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : mock . MagicMock ( ) <EOL> } , <EOL> "<STR_LIT>" : mock . MagicMock ( ) , <EOL> } <EOL> @ mock . patch ( "<STR_LIT>" % CTX ) <EOL> def test_setup ( self , mock_clients ) : <EOL> mock_create = mock_clients ( ) . nova ( ) . flavors . create <EOL> mock_create ( ) . to_dict . return_value = { "<STR_LIT>" : "<STR_LIT>" } <EOL> flavors_ctx = flavors . FlavorsGenerator ( self . context ) <EOL> flavors_ctx . setup ( ) <EOL> self . assertEqual ( flavors_ctx . context [ "<STR_LIT>" ] , <EOL> { "<STR_LIT>" : { "<STR_LIT>" : "<STR_LIT>" } } ) <EOL> mock_clients . assert_called_with ( self . context [ "<STR_LIT>" ] [ "<STR_LIT>" ] ) <EOL> mock_create . assert_called_with ( <EOL> name = "<STR_LIT>" , ram = <NUM_LIT> , vcpus = <NUM_LIT:3> , <EOL> disk = <NUM_LIT:10> , ephemeral = <NUM_LIT:3> , swap = <NUM_LIT:5> ) <EOL> mock_create ( ) . set_keys . assert_called_with ( { "<STR_LIT:key>" : "<STR_LIT:value>" } ) <EOL> mock_create ( ) . to_dict . assert_called_with ( ) <EOL> @ mock . patch ( "<STR_LIT>" % CTX ) <EOL> def test_setup_failexists ( self , mock_clients ) : <EOL> new_context = copy . deepcopy ( self . context ) <EOL> new_context [ "<STR_LIT>" ] = { } <EOL> mock_flavor_create = mock_clients ( ) . nova ( ) . flavors . create <EOL> exception = nova_exceptions . Conflict ( "<STR_LIT>" ) <EOL> mock_flavor_create . side_effect = exception <EOL> flavors_ctx = flavors . FlavorsGenerator ( self . context ) <EOL> flavors_ctx . setup ( ) <EOL> self . assertEqual ( new_context , flavors_ctx . context ) <EOL> mock_clients . assert_called_with ( self . context [ "<STR_LIT>" ] [ "<STR_LIT>" ] ) <EOL> mock_flavor_create . assert_called_once_with ( <EOL> name = "<STR_LIT>" , ram = <NUM_LIT> , vcpus = <NUM_LIT:3> , <EOL> disk = <NUM_LIT:10> , ephemeral = <NUM_LIT:3> , swap = <NUM_LIT:5> ) <EOL> @ mock . patch ( "<STR_LIT>" % CTX ) <EOL> def test_cleanup ( self , mock_clients ) : <EOL> real_context = { <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT:id>" : "<STR_LIT>" <EOL> } <EOL> } , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : mock . MagicMock ( ) <EOL> } , <EOL> "<STR_LIT>" : mock . MagicMock ( ) , <EOL> } <EOL> flavors_ctx = flavors . FlavorsGenerator ( real_context ) <EOL> flavors_ctx . cleanup ( ) <EOL> mock_clients . assert_called_with ( real_context [ "<STR_LIT>" ] [ "<STR_LIT>" ] ) <EOL> mock_flavors_delete = mock_clients ( ) . nova ( ) . flavors . delete <EOL> mock_flavors_delete . assert_called_with ( "<STR_LIT>" ) </s>
