<s> import copy <EOL> import fixtures <EOL> import mock <EOL> from oslo_config import cfg <EOL> from oslo_utils import uuidutils <EOL> from webob import exc <EOL> from neutron . api . v2 import attributes as attr <EOL> from neutron import context <EOL> from neutron . db import api as dbapi <EOL> from neutron . db import flavors_db <EOL> from neutron . db import servicetype_db <EOL> from neutron . extensions import flavors <EOL> from neutron . plugins . common import constants <EOL> from neutron . services . flavors import flavors_plugin <EOL> from neutron . services import provider_configuration as provconf <EOL> from neutron . tests import base <EOL> from neutron . tests . unit . api . v2 import test_base <EOL> from neutron . tests . unit . db import test_db_base_plugin_v2 <EOL> from neutron . tests . unit . extensions import base as extension <EOL> _uuid = uuidutils . generate_uuid <EOL> _get_path = test_base . _get_path <EOL> _driver = ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> _provider = '<STR_LIT>' <EOL> _long_name = '<STR_LIT:x>' * ( attr . NAME_MAX_LEN + <NUM_LIT:1> ) <EOL> _long_description = '<STR_LIT:x>' * ( attr . LONG_DESCRIPTION_MAX_LEN + <NUM_LIT:1> ) <EOL> class FlavorExtensionTestCase ( extension . ExtensionTestCase ) : <EOL> def setUp ( self ) : <EOL> super ( FlavorExtensionTestCase , self ) . setUp ( ) <EOL> self . _setUpExtension ( <EOL> '<STR_LIT>' , <EOL> constants . FLAVORS , flavors . RESOURCE_ATTRIBUTE_MAP , <EOL> flavors . Flavors , '<STR_LIT>' , supported_extension_aliases = '<STR_LIT>' ) <EOL> def test_create_flavor ( self ) : <EOL> tenant_id = uuidutils . generate_uuid ( ) <EOL> data = { '<STR_LIT>' : { '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : constants . FLAVORS , <EOL> '<STR_LIT:description>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : tenant_id , <EOL> '<STR_LIT>' : True } } <EOL> expected = copy . deepcopy ( data ) <EOL> expected [ '<STR_LIT>' ] [ '<STR_LIT>' ] = [ ] <EOL> instance = self . plugin . return_value <EOL> instance . create_flavor . return_value = expected [ '<STR_LIT>' ] <EOL> res = self . api . post ( _get_path ( '<STR_LIT>' , fmt = self . fmt ) , <EOL> self . serialize ( data ) , <EOL> content_type = '<STR_LIT>' % self . fmt ) <EOL> instance . create_flavor . assert_called_with ( mock . ANY , <EOL> flavor = expected ) <EOL> res = self . deserialize ( res ) <EOL> self . assertIn ( '<STR_LIT>' , res ) <EOL> self . assertEqual ( expected , res ) <EOL> def test_create_flavor_invalid_service_type ( self ) : <EOL> tenant_id = uuidutils . generate_uuid ( ) <EOL> data = { '<STR_LIT>' : { '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:description>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : tenant_id , <EOL> '<STR_LIT>' : True } } <EOL> self . api . post ( _get_path ( '<STR_LIT>' , fmt = self . fmt ) , <EOL> self . serialize ( data ) , <EOL> content_type = '<STR_LIT>' % self . fmt , <EOL> status = exc . HTTPBadRequest . code ) <EOL> def test_create_flavor_too_long_name ( self ) : <EOL> tenant_id = uuidutils . generate_uuid ( ) <EOL> data = { '<STR_LIT>' : { '<STR_LIT:name>' : _long_name , <EOL> '<STR_LIT>' : constants . FLAVORS , <EOL> '<STR_LIT:description>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : tenant_id , <EOL> '<STR_LIT>' : True } } <EOL> self . api . post ( _get_path ( '<STR_LIT>' , fmt = self . fmt ) , <EOL> self . serialize ( data ) , <EOL> content_type = '<STR_LIT>' % self . fmt , <EOL> status = exc . HTTPBadRequest . code ) <EOL> def test_create_flavor_too_long_description ( self ) : <EOL> tenant_id = uuidutils . generate_uuid ( ) <EOL> data = { '<STR_LIT>' : { '<STR_LIT:name>' : _long_name , <EOL> '<STR_LIT>' : constants . FLAVORS , <EOL> '<STR_LIT:description>' : _long_description , <EOL> '<STR_LIT>' : tenant_id , <EOL> '<STR_LIT>' : True } } <EOL> self . api . post ( _get_path ( '<STR_LIT>' , fmt = self . fmt ) , <EOL> self . serialize ( data ) , <EOL> content_type = '<STR_LIT>' % self . fmt , <EOL> status = exc . HTTPBadRequest . code ) <EOL> def test_create_flavor_invalid_enabled ( self ) : <EOL> tenant_id = uuidutils . generate_uuid ( ) <EOL> data = { '<STR_LIT>' : { '<STR_LIT:name>' : _long_name , <EOL> '<STR_LIT>' : constants . FLAVORS , <EOL> '<STR_LIT:description>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : tenant_id , <EOL> '<STR_LIT>' : '<STR_LIT>' } } <EOL> self . api . post ( _get_path ( '<STR_LIT>' , fmt = self . fmt ) , <EOL> self . serialize ( data ) , <EOL> content_type = '<STR_LIT>' % self . fmt , <EOL> status = exc . HTTPBadRequest . code ) <EOL> def test_update_flavor ( self ) : <EOL> flavor_id = '<STR_LIT>' <EOL> data = { '<STR_LIT>' : { '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT:description>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : True } } <EOL> expected = copy . copy ( data ) <EOL> expected [ '<STR_LIT>' ] [ '<STR_LIT>' ] = [ ] <EOL> instance = self . plugin . return_value <EOL> instance . update_flavor . return_value = expected [ '<STR_LIT>' ] <EOL> res = self . api . put ( _get_path ( '<STR_LIT>' , id = flavor_id , fmt = self . fmt ) , <EOL> self . serialize ( data ) , <EOL> content_type = '<STR_LIT>' % self . fmt ) <EOL> instance . update_flavor . assert_called_with ( mock . ANY , <EOL> flavor_id , <EOL> flavor = expected ) <EOL> res = self . deserialize ( res ) <EOL> self . assertIn ( '<STR_LIT>' , res ) <EOL> self . assertEqual ( expected , res ) <EOL> def test_update_flavor_too_long_name ( self ) : <EOL> flavor_id = '<STR_LIT>' <EOL> data = { '<STR_LIT>' : { '<STR_LIT:name>' : _long_name , <EOL> '<STR_LIT:description>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : True } } <EOL> self . api . put ( _get_path ( '<STR_LIT>' , id = flavor_id , fmt = self . fmt ) , <EOL> self . serialize ( data ) , <EOL> content_type = '<STR_LIT>' % self . fmt , <EOL> status = exc . HTTPBadRequest . code ) <EOL> def test_update_flavor_too_long_description ( self ) : <EOL> flavor_id = '<STR_LIT>' <EOL> data = { '<STR_LIT>' : { '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT:description>' : _long_description , <EOL> '<STR_LIT>' : True } } <EOL> self . api . put ( _get_path ( '<STR_LIT>' , id = flavor_id , fmt = self . fmt ) , <EOL> self . serialize ( data ) , <EOL> content_type = '<STR_LIT>' % self . fmt , <EOL> status = exc . HTTPBadRequest . code ) <EOL> def test_update_flavor_invalid_enabled ( self ) : <EOL> flavor_id = '<STR_LIT>' <EOL> data = { '<STR_LIT>' : { '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT:description>' : _long_description , <EOL> '<STR_LIT>' : '<STR_LIT>' } } <EOL> self . api . put ( _get_path ( '<STR_LIT>' , id = flavor_id , fmt = self . fmt ) , <EOL> self . serialize ( data ) , <EOL> content_type = '<STR_LIT>' % self . fmt , <EOL> status = exc . HTTPBadRequest . code ) <EOL> def test_delete_flavor ( self ) : <EOL> flavor_id = '<STR_LIT>' <EOL> instance = self . plugin . return_value <EOL> self . api . delete ( _get_path ( '<STR_LIT>' , id = flavor_id , fmt = self . fmt ) , <EOL> content_type = '<STR_LIT>' % self . fmt ) <EOL> instance . delete_flavor . assert_called_with ( mock . ANY , <EOL> flavor_id ) <EOL> def test_show_flavor ( self ) : <EOL> flavor_id = '<STR_LIT>' <EOL> expected = { '<STR_LIT>' : { '<STR_LIT:id>' : flavor_id , <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT:description>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : [ '<STR_LIT>' ] } } <EOL> instance = self . plugin . return_value <EOL> instance . get_flavor . return_value = expected [ '<STR_LIT>' ] <EOL> res = self . api . get ( _get_path ( '<STR_LIT>' , id = flavor_id , fmt = self . fmt ) ) <EOL> instance . get_flavor . assert_called_with ( mock . ANY , <EOL> flavor_id , <EOL> fields = mock . ANY ) <EOL> res = self . deserialize ( res ) <EOL> self . assertEqual ( expected , res ) <EOL> def test_get_flavors ( self ) : <EOL> data = { '<STR_LIT>' : [ { '<STR_LIT:id>' : '<STR_LIT>' , <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT:description>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : [ '<STR_LIT>' ] } , <EOL> { '<STR_LIT:id>' : '<STR_LIT>' , <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT:description>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : [ '<STR_LIT>' , '<STR_LIT>' ] } ] } <EOL> instance = self . plugin . return_value <EOL> instance . get_flavors . return_value = data [ '<STR_LIT>' ] <EOL> res = self . api . get ( _get_path ( '<STR_LIT>' , fmt = self . fmt ) ) <EOL> instance . get_flavors . assert_called_with ( mock . ANY , <EOL> fields = mock . ANY , <EOL> filters = mock . ANY ) <EOL> res = self . deserialize ( res ) <EOL> self . assertEqual ( data , res ) <EOL> def test_create_service_profile ( self ) : <EOL> tenant_id = uuidutils . generate_uuid ( ) <EOL> expected = { '<STR_LIT>' : { '<STR_LIT:description>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : tenant_id , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : '<STR_LIT>' } } <EOL> instance = self . plugin . return_value <EOL> instance . create_service_profile . return_value = ( <EOL> expected [ '<STR_LIT>' ] ) <EOL> res = self . api . post ( _get_path ( '<STR_LIT>' , fmt = self . fmt ) , <EOL> self . serialize ( expected ) , <EOL> content_type = '<STR_LIT>' % self . fmt ) <EOL> instance . create_service_profile . assert_called_with ( <EOL> mock . ANY , <EOL> service_profile = expected ) <EOL> res = self . deserialize ( res ) <EOL> self . assertIn ( '<STR_LIT>' , res ) <EOL> self . assertEqual ( expected , res ) <EOL> def test_create_service_profile_too_long_description ( self ) : <EOL> tenant_id = uuidutils . generate_uuid ( ) <EOL> expected = { '<STR_LIT>' : { '<STR_LIT:description>' : _long_description , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : tenant_id , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : '<STR_LIT>' } } <EOL> self . api . post ( _get_path ( '<STR_LIT>' , fmt = self . fmt ) , <EOL> self . serialize ( expected ) , <EOL> content_type = '<STR_LIT>' % self . fmt , <EOL> status = exc . HTTPBadRequest . code ) <EOL> def test_create_service_profile_too_long_driver ( self ) : <EOL> tenant_id = uuidutils . generate_uuid ( ) <EOL> expected = { '<STR_LIT>' : { '<STR_LIT:description>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : _long_description , <EOL> '<STR_LIT>' : tenant_id , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : '<STR_LIT>' } } <EOL> self . api . post ( _get_path ( '<STR_LIT>' , fmt = self . fmt ) , <EOL> self . serialize ( expected ) , <EOL> content_type = '<STR_LIT>' % self . fmt , <EOL> status = exc . HTTPBadRequest . code ) <EOL> def test_create_service_profile_invalid_enabled ( self ) : <EOL> tenant_id = uuidutils . generate_uuid ( ) <EOL> expected = { '<STR_LIT>' : { '<STR_LIT:description>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : tenant_id , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' } } <EOL> self . api . post ( _get_path ( '<STR_LIT>' , fmt = self . fmt ) , <EOL> self . serialize ( expected ) , <EOL> content_type = '<STR_LIT>' % self . fmt , <EOL> status = exc . HTTPBadRequest . code ) <EOL> def test_update_service_profile ( self ) : <EOL> sp_id = "<STR_LIT>" <EOL> expected = { '<STR_LIT>' : { '<STR_LIT:description>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT>' : '<STR_LIT>' } } <EOL> instance = self . plugin . return_value <EOL> instance . update_service_profile . return_value = ( <EOL> expected [ '<STR_LIT>' ] ) <EOL> res = self . api . put ( _get_path ( '<STR_LIT>' , <EOL> id = sp_id , fmt = self . fmt ) , <EOL> self . serialize ( expected ) , <EOL> content_type = '<STR_LIT>' % self . fmt ) <EOL> instance . update_service_profile . assert_called_with ( <EOL> mock . ANY , <EOL> sp_id , <EOL> service_profile = expected ) <EOL> res = self . deserialize ( res ) <EOL> self . assertIn ( '<STR_LIT>' , res ) <EOL> self . assertEqual ( expected , res ) <EOL> def test_update_service_profile_too_long_description ( self ) : <EOL> sp_id = "<STR_LIT>" <EOL> expected = { '<STR_LIT>' : { '<STR_LIT:description>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' } } <EOL> self . api . put ( _get_path ( '<STR_LIT>' , <EOL> id = sp_id , fmt = self . fmt ) , <EOL> self . serialize ( expected ) , <EOL> content_type = '<STR_LIT>' % self . fmt , <EOL> status = exc . HTTPBadRequest . code ) <EOL> def test_update_service_profile_invalid_enabled ( self ) : <EOL> sp_id = "<STR_LIT>" <EOL> expected = { '<STR_LIT>' : { '<STR_LIT:description>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' } } <EOL> self . api . put ( _get_path ( '<STR_LIT>' , <EOL> id = sp_id , fmt = self . fmt ) , <EOL> self . serialize ( expected ) , <EOL> content_type = '<STR_LIT>' % self . fmt , <EOL> status = exc . HTTPBadRequest . code ) <EOL> def test_delete_service_profile ( self ) : <EOL> sp_id = '<STR_LIT>' <EOL> instance = self . plugin . return_value <EOL> self . api . delete ( _get_path ( '<STR_LIT>' , id = sp_id , fmt = self . fmt ) , <EOL> content_type = '<STR_LIT>' % self . fmt ) <EOL> instance . delete_service_profile . assert_called_with ( mock . ANY , <EOL> sp_id ) <EOL> def test_show_service_profile ( self ) : <EOL> sp_id = '<STR_LIT>' <EOL> expected = { '<STR_LIT>' : { '<STR_LIT:id>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : _driver , <EOL> '<STR_LIT:description>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:{}>' , <EOL> '<STR_LIT>' : True } } <EOL> instance = self . plugin . return_value <EOL> instance . get_service_profile . return_value = ( <EOL> expected [ '<STR_LIT>' ] ) <EOL> res = self . api . get ( _get_path ( '<STR_LIT>' , <EOL> id = sp_id , fmt = self . fmt ) ) <EOL> instance . get_service_profile . assert_called_with ( mock . ANY , <EOL> sp_id , <EOL> fields = mock . ANY ) <EOL> res = self . deserialize ( res ) <EOL> self . assertEqual ( expected , res ) <EOL> def test_get_service_profiles ( self ) : <EOL> expected = { '<STR_LIT>' : [ { '<STR_LIT:id>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : _driver , <EOL> '<STR_LIT:description>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:{}>' , <EOL> '<STR_LIT>' : True } , <EOL> { '<STR_LIT:id>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : _driver , <EOL> '<STR_LIT:description>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:{}>' , <EOL> '<STR_LIT>' : True } ] } <EOL> instance = self . plugin . return_value <EOL> instance . get_service_profiles . return_value = ( <EOL> expected [ '<STR_LIT>' ] ) <EOL> res = self . api . get ( _get_path ( '<STR_LIT>' , fmt = self . fmt ) ) <EOL> instance . get_service_profiles . assert_called_with ( mock . ANY , <EOL> fields = mock . ANY , <EOL> filters = mock . ANY ) <EOL> res = self . deserialize ( res ) <EOL> self . assertEqual ( expected , res ) <EOL> def test_associate_service_profile_with_flavor ( self ) : <EOL> tenant_id = uuidutils . generate_uuid ( ) <EOL> expected = { '<STR_LIT>' : { '<STR_LIT:id>' : _uuid ( ) , <EOL> '<STR_LIT>' : tenant_id } } <EOL> instance = self . plugin . return_value <EOL> instance . create_flavor_service_profile . return_value = ( <EOL> expected [ '<STR_LIT>' ] ) <EOL> res = self . api . post ( '<STR_LIT>' , <EOL> self . serialize ( expected ) , <EOL> content_type = '<STR_LIT>' % self . fmt ) <EOL> instance . create_flavor_service_profile . assert_called_with ( <EOL> mock . ANY , service_profile = expected , flavor_id = '<STR_LIT>' ) <EOL> res = self . deserialize ( res ) <EOL> self . assertEqual ( expected , res ) <EOL> def test_disassociate_service_profile_with_flavor ( self ) : <EOL> instance = self . plugin . return_value <EOL> instance . delete_flavor_service_profile . return_value = None <EOL> self . api . delete ( '<STR_LIT>' % '<STR_LIT>' , <EOL> content_type = '<STR_LIT>' % self . fmt ) <EOL> instance . delete_flavor_service_profile . assert_called_with ( <EOL> mock . ANY , <EOL> '<STR_LIT>' , <EOL> flavor_id = '<STR_LIT>' ) <EOL> def test_update_association_error ( self ) : <EOL> """<STR_LIT>""" <EOL> new_id = uuidutils . generate_uuid ( ) <EOL> data = { '<STR_LIT>' : { '<STR_LIT:id>' : new_id } } <EOL> self . api . put ( '<STR_LIT>' % '<STR_LIT>' , <EOL> self . serialize ( data ) , <EOL> content_type = '<STR_LIT>' % self . fmt , <EOL> status = exc . HTTPBadRequest . code ) <EOL> class DummyCorePlugin ( object ) : <EOL> pass <EOL> class DummyServicePlugin ( object ) : <EOL> def driver_loaded ( self , driver , service_profile ) : <EOL> pass <EOL> def get_plugin_type ( self ) : <EOL> return constants . DUMMY <EOL> def get_plugin_description ( self ) : <EOL> return "<STR_LIT>" <EOL> class DummyServiceDriver ( object ) : <EOL> @ staticmethod <EOL> def get_service_type ( ) : <EOL> return constants . DUMMY <EOL> def __init__ ( self , plugin ) : <EOL> pass <EOL> class FlavorPluginTestCase ( test_db_base_plugin_v2 . NeutronDbPluginV2TestCase , <EOL> base . PluginFixture ) : <EOL> def setUp ( self ) : <EOL> super ( FlavorPluginTestCase , self ) . setUp ( ) <EOL> self . config_parse ( ) <EOL> cfg . CONF . set_override ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ) <EOL> cfg . CONF . set_override ( <EOL> '<STR_LIT>' , <EOL> [ '<STR_LIT>' ] ) <EOL> self . useFixture ( <EOL> fixtures . MonkeyPatch ( '<STR_LIT>' ) ) <EOL> self . plugin = flavors_plugin . FlavorsPlugin ( ) <EOL> self . ctx = context . get_admin_context ( ) <EOL> providers = [ DummyServiceDriver . get_service_type ( ) + <EOL> "<STR_LIT::>" + _provider + "<STR_LIT::>" + _driver ] <EOL> self . service_manager = servicetype_db . ServiceTypeManager . get_instance ( ) <EOL> self . service_providers = mock . patch . object ( <EOL> provconf . NeutronModule , '<STR_LIT>' ) . start ( ) <EOL> self . service_providers . return_value = providers <EOL> for provider in providers : <EOL> self . service_manager . add_provider_configuration ( <EOL> provider . split ( '<STR_LIT::>' ) [ <NUM_LIT:0> ] , provconf . ProviderConfiguration ( ) ) <EOL> dbapi . get_engine ( ) <EOL> def _create_flavor ( self , description = None ) : <EOL> flavor = { '<STR_LIT>' : { '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : constants . DUMMY , <EOL> '<STR_LIT:description>' : description or '<STR_LIT>' , <EOL> '<STR_LIT>' : True } } <EOL> return self . plugin . create_flavor ( self . ctx , flavor ) , flavor <EOL> def test_create_flavor ( self ) : <EOL> self . _create_flavor ( ) <EOL> res = self . ctx . session . query ( flavors_db . Flavor ) . all ( ) <EOL> self . assertEqual ( <NUM_LIT:1> , len ( res ) ) <EOL> self . assertEqual ( '<STR_LIT>' , res [ <NUM_LIT:0> ] [ '<STR_LIT:name>' ] ) <EOL> self . assertEqual ( constants . DUMMY , res [ <NUM_LIT:0> ] [ '<STR_LIT>' ] ) <EOL> def test_update_flavor ( self ) : <EOL> fl , flavor = self . _create_flavor ( ) <EOL> flavor = { '<STR_LIT>' : { '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : False } } <EOL> self . plugin . update_flavor ( self . ctx , fl [ '<STR_LIT:id>' ] , flavor ) <EOL> res = ( self . ctx . session . query ( flavors_db . Flavor ) . <EOL> filter_by ( id = fl [ '<STR_LIT:id>' ] ) . one ( ) ) <EOL> self . assertEqual ( '<STR_LIT>' , res [ '<STR_LIT:name>' ] ) <EOL> self . assertFalse ( res [ '<STR_LIT>' ] ) <EOL> def test_delete_flavor ( self ) : <EOL> fl , data = self . _create_flavor ( ) <EOL> self . plugin . delete_flavor ( self . ctx , fl [ '<STR_LIT:id>' ] ) <EOL> res = ( self . ctx . session . query ( flavors_db . Flavor ) . all ( ) ) <EOL> self . assertFalse ( res ) <EOL> def test_show_flavor ( self ) : <EOL> fl , data = self . _create_flavor ( ) <EOL> show_fl = self . plugin . get_flavor ( self . ctx , fl [ '<STR_LIT:id>' ] ) <EOL> self . assertEqual ( fl , show_fl ) <EOL> def test_get_flavors ( self ) : <EOL> fl , flavor = self . _create_flavor ( ) <EOL> flavor [ '<STR_LIT>' ] [ '<STR_LIT:name>' ] = '<STR_LIT>' <EOL> self . plugin . create_flavor ( self . ctx , flavor ) <EOL> show_fl = self . plugin . get_flavors ( self . ctx ) <EOL> self . assertEqual ( <NUM_LIT:2> , len ( show_fl ) ) <EOL> def _create_service_profile ( self , description = None ) : <EOL> data = { '<STR_LIT>' : <EOL> { '<STR_LIT:description>' : description or '<STR_LIT>' , <EOL> '<STR_LIT>' : _driver , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : '<STR_LIT>' } } <EOL> sp = self . plugin . create_service_profile ( self . ctx , <EOL> data ) <EOL> return sp , data <EOL> def test_create_service_profile ( self ) : <EOL> sp , data = self . _create_service_profile ( ) <EOL> res = ( self . ctx . session . query ( flavors_db . ServiceProfile ) . <EOL> filter_by ( id = sp [ '<STR_LIT:id>' ] ) . one ( ) ) <EOL> self . assertEqual ( data [ '<STR_LIT>' ] [ '<STR_LIT>' ] , res [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( data [ '<STR_LIT>' ] [ '<STR_LIT>' ] , res [ '<STR_LIT>' ] ) <EOL> def test_create_service_profile_empty_driver ( self ) : <EOL> data = { '<STR_LIT>' : <EOL> { '<STR_LIT:description>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : '<STR_LIT>' } } <EOL> sp = self . plugin . create_service_profile ( self . ctx , <EOL> data ) <EOL> res = ( self . ctx . session . query ( flavors_db . ServiceProfile ) . <EOL> filter_by ( id = sp [ '<STR_LIT:id>' ] ) . one ( ) ) <EOL> self . assertEqual ( data [ '<STR_LIT>' ] [ '<STR_LIT>' ] , res [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( data [ '<STR_LIT>' ] [ '<STR_LIT>' ] , res [ '<STR_LIT>' ] ) <EOL> def test_create_service_profile_invalid_driver ( self ) : <EOL> data = { '<STR_LIT>' : <EOL> { '<STR_LIT:description>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : "<STR_LIT>" , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : '<STR_LIT>' } } <EOL> self . assertRaises ( flavors . ServiceProfileDriverNotFound , <EOL> self . plugin . create_service_profile , <EOL> self . ctx , <EOL> data ) <EOL> def test_create_service_profile_invalid_empty ( self ) : <EOL> data = { '<STR_LIT>' : <EOL> { '<STR_LIT:description>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : '<STR_LIT>' } } <EOL> self . assertRaises ( flavors . ServiceProfileEmpty , <EOL> self . plugin . create_service_profile , <EOL> self . ctx , <EOL> data ) <EOL> def test_update_service_profile ( self ) : <EOL> sp , data = self . _create_service_profile ( ) <EOL> data [ '<STR_LIT>' ] [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> sp = self . plugin . update_service_profile ( self . ctx , sp [ '<STR_LIT:id>' ] , <EOL> data ) <EOL> res = ( self . ctx . session . query ( flavors_db . ServiceProfile ) . <EOL> filter_by ( id = sp [ '<STR_LIT:id>' ] ) . one ( ) ) <EOL> self . assertEqual ( data [ '<STR_LIT>' ] [ '<STR_LIT>' ] , res [ '<STR_LIT>' ] ) <EOL> def test_delete_service_profile ( self ) : <EOL> sp , data = self . _create_service_profile ( ) <EOL> self . plugin . delete_service_profile ( self . ctx , sp [ '<STR_LIT:id>' ] ) <EOL> res = self . ctx . session . query ( flavors_db . ServiceProfile ) . all ( ) <EOL> self . assertFalse ( res ) <EOL> def test_show_service_profile ( self ) : <EOL> sp , data = self . _create_service_profile ( ) <EOL> sp_show = self . plugin . get_service_profile ( self . ctx , sp [ '<STR_LIT:id>' ] ) <EOL> self . assertEqual ( sp , sp_show ) <EOL> def test_get_service_profiles ( self ) : <EOL> self . _create_service_profile ( ) <EOL> self . _create_service_profile ( description = '<STR_LIT>' ) <EOL> self . assertEqual ( <NUM_LIT:2> , len ( self . plugin . get_service_profiles ( self . ctx ) ) ) <EOL> def test_associate_service_profile_with_flavor ( self ) : <EOL> sp , data = self . _create_service_profile ( ) <EOL> fl , data = self . _create_flavor ( ) <EOL> self . plugin . create_flavor_service_profile ( <EOL> self . ctx , <EOL> { '<STR_LIT>' : { '<STR_LIT:id>' : sp [ '<STR_LIT:id>' ] } } , <EOL> fl [ '<STR_LIT:id>' ] ) <EOL> binding = ( <EOL> self . ctx . session . query ( flavors_db . FlavorServiceProfileBinding ) . <EOL> first ( ) ) <EOL> self . assertEqual ( fl [ '<STR_LIT:id>' ] , binding [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( sp [ '<STR_LIT:id>' ] , binding [ '<STR_LIT>' ] ) <EOL> res = self . plugin . get_flavor ( self . ctx , fl [ '<STR_LIT:id>' ] ) <EOL> self . assertEqual ( <NUM_LIT:1> , len ( res [ '<STR_LIT>' ] ) ) <EOL> self . assertEqual ( sp [ '<STR_LIT:id>' ] , res [ '<STR_LIT>' ] [ <NUM_LIT:0> ] ) <EOL> res = self . plugin . get_service_profile ( self . ctx , sp [ '<STR_LIT:id>' ] ) <EOL> self . assertEqual ( <NUM_LIT:1> , len ( res [ '<STR_LIT>' ] ) ) <EOL> self . assertEqual ( fl [ '<STR_LIT:id>' ] , res [ '<STR_LIT>' ] [ <NUM_LIT:0> ] ) <EOL> def test_autodelete_flavor_associations ( self ) : <EOL> sp , data = self . _create_service_profile ( ) <EOL> fl , data = self . _create_flavor ( ) <EOL> self . plugin . create_flavor_service_profile ( <EOL> self . ctx , <EOL> { '<STR_LIT>' : { '<STR_LIT:id>' : sp [ '<STR_LIT:id>' ] } } , <EOL> fl [ '<STR_LIT:id>' ] ) <EOL> self . plugin . delete_flavor ( self . ctx , fl [ '<STR_LIT:id>' ] ) <EOL> binding = ( <EOL> self . ctx . session . query ( flavors_db . FlavorServiceProfileBinding ) . <EOL> first ( ) ) <EOL> self . assertIsNone ( binding ) <EOL> def test_associate_service_profile_with_flavor_exists ( self ) : <EOL> sp , data = self . _create_service_profile ( ) <EOL> fl , data = self . _create_flavor ( ) <EOL> self . plugin . create_flavor_service_profile ( <EOL> self . ctx , <EOL> { '<STR_LIT>' : { '<STR_LIT:id>' : sp [ '<STR_LIT:id>' ] } } , <EOL> fl [ '<STR_LIT:id>' ] ) <EOL> self . assertRaises ( flavors . FlavorServiceProfileBindingExists , <EOL> self . plugin . create_flavor_service_profile , <EOL> self . ctx , <EOL> { '<STR_LIT>' : { '<STR_LIT:id>' : sp [ '<STR_LIT:id>' ] } } , <EOL> fl [ '<STR_LIT:id>' ] ) <EOL> def test_disassociate_service_profile_with_flavor ( self ) : <EOL> sp , data = self . _create_service_profile ( ) <EOL> fl , data = self . _create_flavor ( ) <EOL> self . plugin . create_flavor_service_profile ( <EOL> self . ctx , <EOL> { '<STR_LIT>' : { '<STR_LIT:id>' : sp [ '<STR_LIT:id>' ] } } , <EOL> fl [ '<STR_LIT:id>' ] ) <EOL> self . plugin . delete_flavor_service_profile ( <EOL> self . ctx , sp [ '<STR_LIT:id>' ] , fl [ '<STR_LIT:id>' ] ) <EOL> binding = ( <EOL> self . ctx . session . query ( flavors_db . FlavorServiceProfileBinding ) . <EOL> first ( ) ) <EOL> self . assertIsNone ( binding ) <EOL> self . assertRaises ( <EOL> flavors . FlavorServiceProfileBindingNotFound , <EOL> self . plugin . delete_flavor_service_profile , <EOL> self . ctx , sp [ '<STR_LIT:id>' ] , fl [ '<STR_LIT:id>' ] ) <EOL> def test_delete_service_profile_in_use ( self ) : <EOL> sp , data = self . _create_service_profile ( ) <EOL> fl , data = self . _create_flavor ( ) <EOL> self . plugin . create_flavor_service_profile ( <EOL> self . ctx , <EOL> { '<STR_LIT>' : { '<STR_LIT:id>' : sp [ '<STR_LIT:id>' ] } } , <EOL> fl [ '<STR_LIT:id>' ] ) <EOL> self . assertRaises ( <EOL> flavors . ServiceProfileInUse , <EOL> self . plugin . delete_service_profile , <EOL> self . ctx , <EOL> sp [ '<STR_LIT:id>' ] ) <EOL> def test_get_flavor_next_provider_no_binding ( self ) : <EOL> fl , data = self . _create_flavor ( ) <EOL> self . assertRaises ( <EOL> flavors . FlavorServiceProfileBindingNotFound , <EOL> self . plugin . get_flavor_next_provider , <EOL> self . ctx , <EOL> fl [ '<STR_LIT:id>' ] ) <EOL> def test_get_flavor_next_provider_disabled ( self ) : <EOL> data = { '<STR_LIT>' : <EOL> { '<STR_LIT:description>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : _driver , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT>' : '<STR_LIT>' } } <EOL> sp = self . plugin . create_service_profile ( self . ctx , <EOL> data ) <EOL> fl , data = self . _create_flavor ( ) <EOL> self . plugin . create_flavor_service_profile ( <EOL> self . ctx , <EOL> { '<STR_LIT>' : { '<STR_LIT:id>' : sp [ '<STR_LIT:id>' ] } } , <EOL> fl [ '<STR_LIT:id>' ] ) <EOL> self . assertRaises ( <EOL> flavors . ServiceProfileDisabled , <EOL> self . plugin . get_flavor_next_provider , <EOL> self . ctx , <EOL> fl [ '<STR_LIT:id>' ] ) <EOL> def test_get_flavor_next_provider_no_driver ( self ) : <EOL> data = { '<STR_LIT>' : <EOL> { '<STR_LIT:description>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : '<STR_LIT>' } } <EOL> sp = self . plugin . create_service_profile ( self . ctx , <EOL> data ) <EOL> fl , data = self . _create_flavor ( ) <EOL> self . plugin . create_flavor_service_profile ( <EOL> self . ctx , <EOL> { '<STR_LIT>' : { '<STR_LIT:id>' : sp [ '<STR_LIT:id>' ] } } , <EOL> fl [ '<STR_LIT:id>' ] ) <EOL> self . assertRaises ( <EOL> flavors . ServiceProfileDriverNotFound , <EOL> self . plugin . get_flavor_next_provider , <EOL> self . ctx , <EOL> fl [ '<STR_LIT:id>' ] ) <EOL> def test_get_flavor_next_provider ( self ) : <EOL> sp , data = self . _create_service_profile ( ) <EOL> fl , data = self . _create_flavor ( ) <EOL> self . plugin . create_flavor_service_profile ( <EOL> self . ctx , <EOL> { '<STR_LIT>' : { '<STR_LIT:id>' : sp [ '<STR_LIT:id>' ] } } , <EOL> fl [ '<STR_LIT:id>' ] ) <EOL> providers = self . plugin . get_flavor_next_provider ( <EOL> self . ctx , <EOL> fl [ '<STR_LIT:id>' ] ) <EOL> self . assertEqual ( _provider , providers [ <NUM_LIT:0> ] . get ( '<STR_LIT>' , None ) ) </s>
