<s> from __future__ import absolute_import <EOL> from django . conf import settings <EOL> from horizon import exceptions <EOL> from openstack_dashboard . api import base as api_base <EOL> from openstack_dashboard . api import cinder <EOL> from openstack_dashboard . api import glance <EOL> from openstack_dashboard . api import keystone <EOL> from openstack_dashboard . test import helpers as test <EOL> class APIResource ( api_base . APIResourceWrapper ) : <EOL> """<STR_LIT>""" <EOL> _attrs = [ '<STR_LIT:foo>' , '<STR_LIT:bar>' , '<STR_LIT>' ] <EOL> @ staticmethod <EOL> def get_instance ( innerObject = None ) : <EOL> if innerObject is None : <EOL> class InnerAPIResource ( object ) : <EOL> pass <EOL> innerObject = InnerAPIResource ( ) <EOL> innerObject . foo = '<STR_LIT:foo>' <EOL> innerObject . bar = '<STR_LIT:bar>' <EOL> return APIResource ( innerObject ) <EOL> class APIDict ( api_base . APIDictWrapper ) : <EOL> """<STR_LIT>""" <EOL> _attrs = [ '<STR_LIT:foo>' , '<STR_LIT:bar>' , '<STR_LIT>' ] <EOL> @ staticmethod <EOL> def get_instance ( innerDict = None ) : <EOL> if innerDict is None : <EOL> innerDict = { '<STR_LIT:foo>' : '<STR_LIT:foo>' , <EOL> '<STR_LIT:bar>' : '<STR_LIT:bar>' } <EOL> return APIDict ( innerDict ) <EOL> class APIResourceWrapperTests ( test . TestCase ) : <EOL> def test_get_attribute ( self ) : <EOL> resource = APIResource . get_instance ( ) <EOL> self . assertEqual ( '<STR_LIT:foo>' , resource . foo ) <EOL> def test_get_invalid_attribute ( self ) : <EOL> resource = APIResource . get_instance ( ) <EOL> self . assertNotIn ( <EOL> '<STR_LIT>' , resource . _attrs , <EOL> msg = "<STR_LIT>" ) <EOL> with self . assertRaises ( AttributeError ) : <EOL> resource . missing <EOL> def test_get_inner_missing_attribute ( self ) : <EOL> resource = APIResource . get_instance ( ) <EOL> with self . assertRaises ( AttributeError ) : <EOL> resource . baz <EOL> def test_repr ( self ) : <EOL> resource = APIResource . get_instance ( ) <EOL> resource_str = resource . __repr__ ( ) <EOL> self . assertIn ( '<STR_LIT:foo>' , resource_str ) <EOL> self . assertIn ( '<STR_LIT:bar>' , resource_str ) <EOL> self . assertNotIn ( '<STR_LIT>' , resource_str ) <EOL> class APIDictWrapperTests ( test . TestCase ) : <EOL> def test_get_item ( self ) : <EOL> resource = APIDict . get_instance ( ) <EOL> self . assertEqual ( '<STR_LIT:foo>' , resource . foo ) <EOL> self . assertEqual ( '<STR_LIT:foo>' , resource [ '<STR_LIT:foo>' ] ) <EOL> def test_get_invalid_item ( self ) : <EOL> resource = APIDict . get_instance ( ) <EOL> self . assertNotIn ( <EOL> '<STR_LIT>' , resource . _attrs , <EOL> msg = "<STR_LIT>" ) <EOL> with self . assertRaises ( AttributeError ) : <EOL> resource . missing <EOL> with self . assertRaises ( KeyError ) : <EOL> resource [ '<STR_LIT>' ] <EOL> def test_get_inner_missing_attribute ( self ) : <EOL> resource = APIDict . get_instance ( ) <EOL> with self . assertRaises ( AttributeError ) : <EOL> resource . baz <EOL> with self . assertRaises ( KeyError ) : <EOL> resource [ '<STR_LIT>' ] <EOL> def test_get_with_default ( self ) : <EOL> resource = APIDict . get_instance ( ) <EOL> self . assertEqual ( '<STR_LIT:foo>' , resource . get ( '<STR_LIT:foo>' ) ) <EOL> self . assertIsNone ( resource . get ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( '<STR_LIT>' , resource . get ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> def test_get_with_non_str ( self ) : <EOL> resource = APIDict . get_instance ( ) <EOL> self . assertNotIn ( <NUM_LIT:0> , resource . _attrs , <EOL> msg = "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> self . assertIsNone ( resource . get ( <NUM_LIT:0> ) ) <EOL> self . assertEqual ( '<STR_LIT>' , resource . get ( <NUM_LIT:0> , '<STR_LIT>' ) ) <EOL> def test_get_item_non_str ( self ) : <EOL> resource = APIDict . get_instance ( ) <EOL> self . assertNotIn ( <NUM_LIT:0> , resource . _attrs , <EOL> msg = "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> with self . assertRaises ( KeyError ) : <EOL> resource [ <NUM_LIT:0> ] <EOL> def test_in_not_there_str ( self ) : <EOL> resource = APIDict . get_instance ( ) <EOL> self . assertNotIn ( '<STR_LIT>' , resource . _attrs , <EOL> msg = "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> self . assertFalse ( '<STR_LIT>' in resource ) <EOL> def test_in_not_there_non_str ( self ) : <EOL> resource = APIDict . get_instance ( ) <EOL> self . assertNotIn ( <NUM_LIT:0> , resource . _attrs , <EOL> msg = "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> self . assertFalse ( <NUM_LIT:0> in resource ) <EOL> class ApiVersionTests ( test . TestCase ) : <EOL> def setUp ( self ) : <EOL> super ( ApiVersionTests , self ) . setUp ( ) <EOL> self . previous_settings = settings . OPENSTACK_API_VERSIONS <EOL> settings . OPENSTACK_API_VERSIONS = { <EOL> "<STR_LIT>" : <NUM_LIT> , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : <NUM_LIT:1> <EOL> } <EOL> cinder . VERSIONS . clear_active_cache ( ) <EOL> keystone . VERSIONS . clear_active_cache ( ) <EOL> glance . VERSIONS . clear_active_cache ( ) <EOL> def tearDown ( self ) : <EOL> super ( ApiVersionTests , self ) . tearDown ( ) <EOL> settings . OPENSTACK_API_VERSIONS = self . previous_settings <EOL> cinder . VERSIONS . clear_active_cache ( ) <EOL> keystone . VERSIONS . clear_active_cache ( ) <EOL> glance . VERSIONS . clear_active_cache ( ) <EOL> def test_invalid_versions ( self ) : <EOL> with self . assertRaises ( exceptions . ConfigurationError ) : <EOL> getattr ( keystone . VERSIONS , '<STR_LIT>' ) <EOL> with self . assertRaises ( exceptions . ConfigurationError ) : <EOL> getattr ( cinder . VERSIONS , '<STR_LIT>' ) <EOL> try : <EOL> getattr ( glance . VERSIONS , '<STR_LIT>' ) <EOL> except exceptions . ConfigurationError : <EOL> self . fail ( "<STR_LIT>" ) <EOL> class ApiHelperTests ( test . TestCase ) : <EOL> """<STR_LIT>""" <EOL> def test_url_for ( self ) : <EOL> url = api_base . url_for ( self . request , '<STR_LIT:image>' ) <EOL> self . assertEqual ( '<STR_LIT>' , url ) <EOL> url = api_base . url_for ( self . request , '<STR_LIT:image>' , endpoint_type = '<STR_LIT>' ) <EOL> self . assertEqual ( '<STR_LIT>' , url ) <EOL> url = api_base . url_for ( self . request , '<STR_LIT>' ) <EOL> self . assertEqual ( '<STR_LIT>' , url ) <EOL> url = api_base . url_for ( self . request , '<STR_LIT>' , <EOL> endpoint_type = '<STR_LIT>' ) <EOL> self . assertEqual ( '<STR_LIT>' , url ) <EOL> url = api_base . url_for ( self . request , '<STR_LIT>' ) <EOL> self . assertEqual ( '<STR_LIT>' , url ) <EOL> url = api_base . url_for ( self . request , '<STR_LIT>' , <EOL> endpoint_type = "<STR_LIT>" ) <EOL> self . assertEqual ( '<STR_LIT>' , url ) <EOL> url = api_base . url_for ( self . request , '<STR_LIT>' , <EOL> endpoint_type = '<STR_LIT>' ) <EOL> self . assertEqual ( '<STR_LIT>' , url ) <EOL> self . assertNotIn ( '<STR_LIT>' , self . request . user . service_catalog , <EOL> '<STR_LIT>' ) <EOL> with self . assertRaises ( exceptions . ServiceCatalogException ) : <EOL> url = api_base . url_for ( self . request , '<STR_LIT>' ) <EOL> self . request . user . services_region = "<STR_LIT>" <EOL> url = api_base . url_for ( self . request , '<STR_LIT>' ) <EOL> self . assertEqual ( '<STR_LIT>' , url ) <EOL> self . request . user . services_region = "<STR_LIT>" <EOL> url = api_base . url_for ( self . request , '<STR_LIT>' , <EOL> endpoint_type = '<STR_LIT>' ) <EOL> self . assertEqual ( '<STR_LIT>' , url ) <EOL> self . request . user . services_region = "<STR_LIT>" <EOL> with self . assertRaises ( exceptions . ServiceCatalogException ) : <EOL> url = api_base . url_for ( self . request , '<STR_LIT:image>' ) <EOL> self . request . user . services_region = "<STR_LIT>" <EOL> url = api_base . url_for ( self . request , '<STR_LIT>' , <EOL> endpoint_type = '<STR_LIT>' ) <EOL> self . assertEqual ( '<STR_LIT>' , url ) <EOL> self . request . user . services_region = "<STR_LIT>" <EOL> with self . assertRaises ( exceptions . ServiceCatalogException ) : <EOL> url = api_base . url_for ( self . request , '<STR_LIT:image>' ) <EOL> class QuotaSetTests ( test . TestCase ) : <EOL> def test_quotaset_add_with_plus ( self ) : <EOL> quota_dict = { '<STR_LIT:foo>' : <NUM_LIT:1> , '<STR_LIT:bar>' : <NUM_LIT:10> } <EOL> other_quota_dict = { '<STR_LIT>' : <NUM_LIT:12> } <EOL> quota_set = api_base . QuotaSet ( quota_dict ) <EOL> other_quota_set = api_base . QuotaSet ( other_quota_dict ) <EOL> quota_set += other_quota_set <EOL> self . assertEqual ( <NUM_LIT:3> , len ( quota_set ) ) <EOL> quota_dict . update ( other_quota_dict ) <EOL> for q in quota_set : <EOL> self . assertEqual ( quota_dict [ q . name ] , q . limit ) <EOL> def test_quotaset_add_doesnt_override_existing_quota ( self ) : <EOL> quota_dict = { '<STR_LIT:foo>' : <NUM_LIT:1> , '<STR_LIT:bar>' : <NUM_LIT:10> } <EOL> quota_set = api_base . QuotaSet ( quota_dict ) <EOL> other_quota_set = api_base . QuotaSet ( { '<STR_LIT:foo>' : <NUM_LIT:12> } ) <EOL> quota_set += other_quota_set <EOL> self . assertEqual ( <NUM_LIT:2> , len ( quota_set ) ) <EOL> for q in quota_set : <EOL> self . assertEqual ( quota_dict [ q . name ] , q . limit ) <EOL> def test_quotaset_add_method ( self ) : <EOL> quota_dict = { '<STR_LIT:foo>' : <NUM_LIT:1> , '<STR_LIT:bar>' : <NUM_LIT:10> } <EOL> other_quota_dict = { '<STR_LIT>' : <NUM_LIT:12> } <EOL> quota_set = api_base . QuotaSet ( quota_dict ) <EOL> other_quota_set = api_base . QuotaSet ( other_quota_dict ) <EOL> quota_set . add ( other_quota_set ) <EOL> self . assertEqual ( <NUM_LIT:3> , len ( quota_set ) ) <EOL> quota_dict . update ( other_quota_dict ) <EOL> for q in quota_set : <EOL> self . assertEqual ( quota_dict [ q . name ] , q . limit ) <EOL> def test_quotaset_add_with_wrong_type ( self ) : <EOL> quota_set = api_base . QuotaSet ( { '<STR_LIT:foo>' : <NUM_LIT:1> , '<STR_LIT:bar>' : <NUM_LIT:10> } ) <EOL> self . assertRaises ( ValueError , quota_set . add , { '<STR_LIT:test>' : <NUM_LIT:7> } ) </s>
