<s> from django . core . urlresolvers import reverse <EOL> from django import http <EOL> from mox3 . mox import IsA <EOL> from openstack_dashboard import api <EOL> from openstack_dashboard . test import helpers as test <EOL> class VolTypeExtrasTests ( test . BaseAdminViewTests ) : <EOL> @ test . create_stubs ( { api . cinder : ( '<STR_LIT>' , <EOL> '<STR_LIT>' ) , } ) <EOL> def test_list_extras_when_none_exists ( self ) : <EOL> vol_type = self . cinder_volume_types . first ( ) <EOL> extras = [ api . cinder . VolTypeExtraSpec ( vol_type . id , '<STR_LIT>' , '<STR_LIT>' ) ] <EOL> api . cinder . volume_type_get ( IsA ( http . HttpRequest ) , <EOL> vol_type . id ) . AndReturn ( vol_type ) <EOL> api . cinder . volume_type_extra_get ( IsA ( http . HttpRequest ) , <EOL> vol_type . id ) . AndReturn ( extras ) <EOL> self . mox . ReplayAll ( ) <EOL> url = reverse ( '<STR_LIT>' , <EOL> args = [ vol_type . id ] ) <EOL> resp = self . client . get ( url ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT:200> ) <EOL> self . assertTemplateUsed ( resp , <EOL> "<STR_LIT>" ) <EOL> @ test . create_stubs ( { api . cinder : ( '<STR_LIT>' , <EOL> '<STR_LIT>' ) , } ) <EOL> def test_extras_view_with_exception ( self ) : <EOL> vol_type = self . cinder_volume_types . first ( ) <EOL> api . cinder . volume_type_get ( IsA ( http . HttpRequest ) , <EOL> vol_type . id ) . AndReturn ( vol_type ) <EOL> api . cinder . volume_type_extra_get ( IsA ( http . HttpRequest ) , <EOL> vol_type . id ) . AndRaise ( self . exceptions . cinder ) <EOL> self . mox . ReplayAll ( ) <EOL> url = reverse ( '<STR_LIT>' , <EOL> args = [ vol_type . id ] ) <EOL> resp = self . client . get ( url ) <EOL> self . assertEqual ( len ( resp . context [ '<STR_LIT>' ] . data ) , <NUM_LIT:0> ) <EOL> self . assertMessageCount ( resp , error = <NUM_LIT:1> ) <EOL> @ test . create_stubs ( { api . cinder : ( '<STR_LIT>' , ) , } ) <EOL> def test_extra_create_post ( self ) : <EOL> vol_type = self . cinder_volume_types . first ( ) <EOL> create_url = reverse ( <EOL> '<STR_LIT>' , <EOL> args = [ vol_type . id ] ) <EOL> index_url = reverse ( <EOL> '<STR_LIT>' , <EOL> args = [ vol_type . id ] ) <EOL> data = { '<STR_LIT:key>' : u'<STR_LIT>' , <EOL> '<STR_LIT:value>' : u'<STR_LIT>' } <EOL> api . cinder . volume_type_extra_set ( IsA ( http . HttpRequest ) , <EOL> vol_type . id , <EOL> { data [ '<STR_LIT:key>' ] : data [ '<STR_LIT:value>' ] } ) <EOL> self . mox . ReplayAll ( ) <EOL> resp = self . client . post ( create_url , data ) <EOL> self . assertNoFormErrors ( resp ) <EOL> self . assertMessageCount ( success = <NUM_LIT:1> ) <EOL> self . assertRedirectsNoFollow ( resp , index_url ) <EOL> @ test . create_stubs ( { api . cinder : ( '<STR_LIT>' , ) , } ) <EOL> def test_extra_create_get ( self ) : <EOL> vol_type = self . cinder_volume_types . first ( ) <EOL> create_url = reverse ( <EOL> '<STR_LIT>' , <EOL> args = [ vol_type . id ] ) <EOL> api . cinder . volume_type_get ( IsA ( http . HttpRequest ) , <EOL> vol_type . id ) . AndReturn ( vol_type ) <EOL> self . mox . ReplayAll ( ) <EOL> resp = self . client . get ( create_url ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT:200> ) <EOL> self . assertTemplateUsed ( <EOL> resp , '<STR_LIT>' ) <EOL> @ test . create_stubs ( { api . cinder : ( '<STR_LIT>' , <EOL> '<STR_LIT>' , ) , } ) <EOL> def test_extra_edit ( self ) : <EOL> vol_type = self . cinder_volume_types . first ( ) <EOL> key = '<STR_LIT:foo>' <EOL> edit_url = reverse ( '<STR_LIT>' , <EOL> args = [ vol_type . id , key ] ) <EOL> index_url = reverse ( '<STR_LIT>' , <EOL> args = [ vol_type . id ] ) <EOL> data = { '<STR_LIT:value>' : u'<STR_LIT>' } <EOL> extras = { key : data [ '<STR_LIT:value>' ] } <EOL> api . cinder . volume_type_extra_get ( IsA ( http . HttpRequest ) , <EOL> vol_type . id , <EOL> raw = True ) . AndReturn ( extras ) <EOL> api . cinder . volume_type_extra_set ( IsA ( http . HttpRequest ) , <EOL> vol_type . id , <EOL> extras ) <EOL> self . mox . ReplayAll ( ) <EOL> resp = self . client . post ( edit_url , data ) <EOL> self . assertNoFormErrors ( resp ) <EOL> self . assertMessageCount ( success = <NUM_LIT:1> ) <EOL> self . assertRedirectsNoFollow ( resp , index_url ) <EOL> @ test . create_stubs ( { api . cinder : ( '<STR_LIT>' , <EOL> '<STR_LIT>' ) , } ) <EOL> def test_extra_delete ( self ) : <EOL> vol_type = self . cinder_volume_types . first ( ) <EOL> extras = [ api . cinder . VolTypeExtraSpec ( vol_type . id , '<STR_LIT>' , '<STR_LIT>' ) ] <EOL> formData = { '<STR_LIT:action>' : '<STR_LIT>' } <EOL> index_url = reverse ( '<STR_LIT>' , <EOL> args = [ vol_type . id ] ) <EOL> api . cinder . volume_type_extra_get ( IsA ( http . HttpRequest ) , <EOL> vol_type . id ) . AndReturn ( extras ) <EOL> api . cinder . volume_type_extra_delete ( IsA ( http . HttpRequest ) , <EOL> vol_type . id , <EOL> '<STR_LIT>' ) . AndReturn ( vol_type ) <EOL> self . mox . ReplayAll ( ) <EOL> res = self . client . post ( index_url , formData ) <EOL> self . assertNoFormErrors ( res ) <EOL> self . assertRedirectsNoFollow ( res , index_url ) </s>
