<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 . api import cinder <EOL> from openstack_dashboard . test import helpers as test <EOL> from openstack_dashboard . usage import quotas <EOL> INDEX_URL = reverse ( '<STR_LIT>' ) <EOL> VOLUME_SNAPSHOTS_TAB_URL = reverse ( '<STR_LIT>' ) <EOL> class VolumeSnapshotsViewTests ( test . TestCase ) : <EOL> @ test . create_stubs ( { cinder : ( '<STR_LIT>' , ) , <EOL> quotas : ( '<STR_LIT>' , ) } ) <EOL> def test_create_snapshot_get ( self ) : <EOL> volume = self . cinder_volumes . first ( ) <EOL> cinder . volume_get ( IsA ( http . HttpRequest ) , volume . id ) . AndReturn ( volume ) <EOL> snapshot_used = len ( self . cinder_volume_snapshots . list ( ) ) <EOL> usage_limit = { '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : <NUM_LIT:20> , <EOL> '<STR_LIT>' : snapshot_used , <EOL> '<STR_LIT>' : <NUM_LIT:6> } <EOL> quotas . tenant_limit_usages ( IsA ( http . HttpRequest ) ) . AndReturn ( usage_limit ) <EOL> self . mox . ReplayAll ( ) <EOL> url = reverse ( '<STR_LIT>' <EOL> '<STR_LIT>' , args = [ volume . id ] ) <EOL> res = self . client . get ( url ) <EOL> self . assertTemplateUsed ( res , '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> @ test . create_stubs ( { cinder : ( '<STR_LIT>' , <EOL> '<STR_LIT>' , ) } ) <EOL> def test_create_snapshot_post ( self ) : <EOL> volume = self . cinder_volumes . first ( ) <EOL> snapshot = self . cinder_volume_snapshots . first ( ) <EOL> cinder . volume_get ( IsA ( http . HttpRequest ) , volume . id ) . AndReturn ( volume ) <EOL> cinder . volume_snapshot_create ( IsA ( http . HttpRequest ) , <EOL> volume . id , <EOL> snapshot . name , <EOL> snapshot . description , <EOL> force = False ) . AndReturn ( snapshot ) <EOL> self . mox . ReplayAll ( ) <EOL> formData = { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : self . tenant . id , <EOL> '<STR_LIT>' : volume . id , <EOL> '<STR_LIT:name>' : snapshot . name , <EOL> '<STR_LIT:description>' : snapshot . description } <EOL> url = reverse ( '<STR_LIT>' , <EOL> args = [ volume . id ] ) <EOL> res = self . client . post ( url , formData ) <EOL> self . assertRedirectsNoFollow ( res , VOLUME_SNAPSHOTS_TAB_URL ) <EOL> @ test . create_stubs ( { cinder : ( '<STR_LIT>' , <EOL> '<STR_LIT>' , ) } ) <EOL> def test_force_create_snapshot ( self ) : <EOL> volume = self . cinder_volumes . get ( name = '<STR_LIT>' ) <EOL> snapshot = self . cinder_volume_snapshots . first ( ) <EOL> cinder . volume_get ( IsA ( http . HttpRequest ) , volume . id ) . AndReturn ( volume ) <EOL> cinder . volume_snapshot_create ( IsA ( http . HttpRequest ) , <EOL> volume . id , <EOL> snapshot . name , <EOL> snapshot . description , <EOL> force = True ) . AndReturn ( snapshot ) <EOL> self . mox . ReplayAll ( ) <EOL> formData = { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : self . tenant . id , <EOL> '<STR_LIT>' : volume . id , <EOL> '<STR_LIT:name>' : snapshot . name , <EOL> '<STR_LIT:description>' : snapshot . description } <EOL> url = reverse ( '<STR_LIT>' , <EOL> args = [ volume . id ] ) <EOL> res = self . client . post ( url , formData ) <EOL> self . assertRedirectsNoFollow ( res , VOLUME_SNAPSHOTS_TAB_URL ) <EOL> @ test . create_stubs ( { api . cinder : ( '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ) } ) <EOL> def test_delete_volume_snapshot ( self ) : <EOL> vol_snapshots = self . cinder_volume_snapshots . list ( ) <EOL> volumes = self . cinder_volumes . list ( ) <EOL> snapshot = self . cinder_volume_snapshots . first ( ) <EOL> api . cinder . volume_backup_supported ( IsA ( http . HttpRequest ) ) . MultipleTimes ( ) . AndReturn ( True ) <EOL> api . cinder . volume_snapshot_list_paged ( <EOL> IsA ( http . HttpRequest ) , paginate = True , marker = None , <EOL> sort_dir = '<STR_LIT>' ) . AndReturn ( [ vol_snapshots , False , False ] ) <EOL> api . cinder . volume_list ( IsA ( http . HttpRequest ) ) . AndReturn ( volumes ) <EOL> api . cinder . volume_snapshot_delete ( IsA ( http . HttpRequest ) , snapshot . id ) <EOL> self . mox . ReplayAll ( ) <EOL> formData = { '<STR_LIT:action>' : <EOL> '<STR_LIT>' % snapshot . id } <EOL> res = self . client . post ( VOLUME_SNAPSHOTS_TAB_URL , formData ) <EOL> self . assertRedirectsNoFollow ( res , VOLUME_SNAPSHOTS_TAB_URL ) <EOL> self . assertMessageCount ( success = <NUM_LIT:1> ) <EOL> @ test . create_stubs ( { api . cinder : ( '<STR_LIT>' , '<STR_LIT>' ) } ) <EOL> def test_volume_snapshot_detail_get ( self ) : <EOL> volume = self . cinder_volumes . first ( ) <EOL> snapshot = self . cinder_volume_snapshots . first ( ) <EOL> api . cinder . volume_get ( IsA ( http . HttpRequest ) , volume . id ) . AndReturn ( volume ) <EOL> api . cinder . volume_snapshot_get ( IsA ( http . HttpRequest ) , snapshot . id ) . AndReturn ( snapshot ) <EOL> self . mox . ReplayAll ( ) <EOL> url = reverse ( '<STR_LIT>' , <EOL> args = [ snapshot . id ] ) <EOL> res = self . client . get ( url ) <EOL> self . assertTemplateUsed ( res , '<STR_LIT>' ) <EOL> self . assertEqual ( res . context [ '<STR_LIT>' ] . id , snapshot . id ) <EOL> @ test . create_stubs ( { api . cinder : ( '<STR_LIT>' , ) } ) <EOL> def test_volume_snapshot_detail_get_with_exception ( self ) : <EOL> snapshot = self . cinder_volume_snapshots . first ( ) <EOL> api . cinder . volume_snapshot_get ( IsA ( http . HttpRequest ) , snapshot . id ) . AndRaise ( self . exceptions . cinder ) <EOL> self . mox . ReplayAll ( ) <EOL> url = reverse ( '<STR_LIT>' , <EOL> args = [ snapshot . id ] ) <EOL> res = self . client . get ( url ) <EOL> self . assertRedirectsNoFollow ( res , INDEX_URL ) <EOL> @ test . create_stubs ( { api . cinder : ( '<STR_LIT>' , '<STR_LIT>' ) } ) <EOL> def test_volume_snapshot_detail_with_volume_get_exception ( self ) : <EOL> volume = self . cinder_volumes . first ( ) <EOL> snapshot = self . cinder_volume_snapshots . first ( ) <EOL> api . cinder . volume_get ( IsA ( http . HttpRequest ) , volume . id ) . AndRaise ( self . exceptions . cinder ) <EOL> api . cinder . volume_snapshot_get ( IsA ( http . HttpRequest ) , snapshot . id ) . AndReturn ( snapshot ) <EOL> self . mox . ReplayAll ( ) <EOL> url = reverse ( '<STR_LIT>' , <EOL> args = [ snapshot . id ] ) <EOL> res = self . client . get ( url ) <EOL> self . assertRedirectsNoFollow ( res , INDEX_URL ) <EOL> @ test . create_stubs ( { cinder : ( '<STR_LIT>' , <EOL> '<STR_LIT>' ) } ) <EOL> def test_update_snapshot ( self ) : <EOL> snapshot = self . cinder_volume_snapshots . first ( ) <EOL> cinder . volume_snapshot_get ( IsA ( http . HttpRequest ) , snapshot . id ) . AndReturn ( snapshot ) <EOL> cinder . volume_snapshot_update ( IsA ( http . HttpRequest ) , <EOL> snapshot . id , <EOL> snapshot . name , <EOL> snapshot . description ) . AndReturn ( snapshot ) <EOL> self . mox . ReplayAll ( ) <EOL> formData = { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:name>' : snapshot . name , <EOL> '<STR_LIT:description>' : snapshot . description } <EOL> url = reverse ( ( '<STR_LIT>' ) , <EOL> args = [ snapshot . id ] ) <EOL> res = self . client . post ( url , formData ) <EOL> self . assertRedirectsNoFollow ( res , INDEX_URL ) </s>
