<s> from cinderclient import exceptions as cinder_exceptions <EOL> import mock <EOL> from nova import test <EOL> from nova . tests import fixtures as nova_fixtures <EOL> from nova . tests . functional . api import client <EOL> from nova . tests . unit import policy_fixture <EOL> class TestCinderForbidden ( test . TestCase ) : <EOL> def setUp ( self ) : <EOL> super ( TestCinderForbidden , self ) . setUp ( ) <EOL> self . useFixture ( policy_fixture . RealPolicyFixture ( ) ) <EOL> api_fixture = self . useFixture ( nova_fixtures . OSAPIFixture ( <EOL> api_version = '<STR_LIT>' ) ) <EOL> self . api = api_fixture . api <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> def test_forbidden_cinder_operation_returns_403 ( self , mock_cinder ) : <EOL> """<STR_LIT>""" <EOL> cinder_client = mock . Mock ( ) <EOL> mock_cinder . return_value = cinder_client <EOL> exc = cinder_exceptions . Forbidden ( '<STR_LIT>' ) <EOL> cinder_client . volumes . create . side_effect = exc <EOL> volume = { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT:size>' : <NUM_LIT:3> } <EOL> e = self . assertRaises ( client . OpenStackApiException , <EOL> self . api . post_volume , { '<STR_LIT>' : volume } ) <EOL> self . assertEqual ( <NUM_LIT> , e . response . status_code ) <EOL> class TestCinderOverLimit ( test . TestCase ) : <EOL> def setUp ( self ) : <EOL> super ( TestCinderOverLimit , self ) . setUp ( ) <EOL> self . useFixture ( policy_fixture . RealPolicyFixture ( ) ) <EOL> api_fixture = self . useFixture ( nova_fixtures . OSAPIFixture ( <EOL> api_version = '<STR_LIT>' ) ) <EOL> self . api = api_fixture . api <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> def test_over_limit_volumes ( self , mock_cinder ) : <EOL> """<STR_LIT>""" <EOL> cinder_client = mock . Mock ( ) <EOL> mock_cinder . return_value = cinder_client <EOL> exc = cinder_exceptions . OverLimit ( '<STR_LIT>' ) <EOL> cinder_client . volumes . create . side_effect = exc <EOL> volume = { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT:size>' : <NUM_LIT:3> } <EOL> e = self . assertRaises ( client . OpenStackApiException , <EOL> self . api . post_volume , { '<STR_LIT>' : volume } ) <EOL> self . assertEqual ( <NUM_LIT> , e . response . status_code ) <EOL> self . assertIn ( '<STR_LIT>' , e . response . content ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> def test_over_limit_snapshots ( self , mock_cinder ) : <EOL> """<STR_LIT>""" <EOL> self . _do_snapshot_over_test ( mock_cinder ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> def test_over_limit_snapshots_force ( self , mock_cinder ) : <EOL> """<STR_LIT>""" <EOL> self . _do_snapshot_over_test ( mock_cinder , force = True ) <EOL> def _do_snapshot_over_test ( self , mock_cinder , force = False ) : <EOL> cinder_client = mock . Mock ( ) <EOL> mock_cinder . return_value = cinder_client <EOL> exc = cinder_exceptions . OverLimit ( '<STR_LIT>' ) <EOL> cinder_client . volume_snapshots . create . side_effect = exc <EOL> snap = { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : force } <EOL> e = self . assertRaises ( client . OpenStackApiException , <EOL> self . api . post_snapshot , { '<STR_LIT>' : snap } ) <EOL> self . assertEqual ( <NUM_LIT> , e . response . status_code ) <EOL> self . assertIn ( '<STR_LIT>' , e . response . content ) </s>
