<s> """<STR_LIT>""" <EOL> from cafe . drivers . unittest . decorators import ( <EOL> data_driven_test , DataDrivenFixture ) <EOL> from cloudcafe . common . tools . datagen import rand_name <EOL> from cloudcafe . glance . common . constants import Messages <EOL> from cloudcafe . glance . common . types import ImageStatus <EOL> from cloudroast . glance . fixtures import ImagesIntegrationFixture <EOL> from cloudroast . glance . generators import ImagesDatasetListGenerator <EOL> @ DataDrivenFixture <EOL> class ReactivateImage ( ImagesIntegrationFixture ) : <EOL> @ classmethod <EOL> def setUpClass ( cls ) : <EOL> super ( ReactivateImage , cls ) . setUpClass ( ) <EOL> created_images = cls . images . behaviors . create_images_via_task ( <EOL> image_properties = { '<STR_LIT:name>' : rand_name ( '<STR_LIT>' ) } , count = <NUM_LIT:3> ) <EOL> cls . deleted_image = created_images . pop ( ) <EOL> cls . images . client . delete_image ( cls . deleted_image . id_ ) <EOL> cls . protected_image = created_images . pop ( ) <EOL> cls . images_admin . client . deactivate_image ( cls . protected_image . id_ ) <EOL> cls . images . client . update_image ( <EOL> cls . protected_image . id_ , replace = { '<STR_LIT>' : True } ) <EOL> cls . deactivated_image = created_images . pop ( ) <EOL> cls . images_admin . client . deactivate_image ( cls . deactivated_image . id_ ) <EOL> created_server = cls . compute . servers . behaviors . create_active_server ( <EOL> image_ref = cls . images . config . primary_image ) . entity <EOL> cls . resources . add ( <EOL> created_server . id , cls . compute . servers . client . delete_server ) <EOL> cls . created_snapshot = ( <EOL> cls . compute . images . behaviors . create_active_image ( <EOL> created_server . id ) . entity ) <EOL> cls . resources . add ( <EOL> cls . created_snapshot . id , cls . images . client . delete_image ) <EOL> cls . images_admin . client . deactivate_image ( cls . created_snapshot . id ) <EOL> @ classmethod <EOL> def tearDownClass ( cls ) : <EOL> cls . images . client . update_image ( <EOL> cls . protected_image . id_ , replace = { '<STR_LIT>' : False } ) <EOL> cls . images . behaviors . resources . release ( ) <EOL> super ( ReactivateImage , cls ) . tearDownClass ( ) <EOL> @ data_driven_test ( <EOL> ImagesDatasetListGenerator . ReactivateImageTypes ( ) ) <EOL> def ddtest_reactivate_image ( self , image ) : <EOL> """<STR_LIT>""" <EOL> resp = self . images_admin . client . reactivate_image ( image . id_ ) <EOL> self . assertEqual ( <EOL> resp . status_code , <NUM_LIT> , <EOL> Messages . STATUS_CODE_MSG . format ( <NUM_LIT> , resp . status_code ) ) <EOL> resp = self . images . client . get_image_details ( image . id_ ) <EOL> self . assertTrue ( resp . ok , Messages . OK_RESP_MSG . format ( resp . status_code ) ) <EOL> get_image = resp . entity <EOL> self . assertEqual ( <EOL> get_image . status , ImageStatus . ACTIVE , <EOL> msg = ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) . format ( image . id_ , ImageStatus . ACTIVE , <EOL> get_image . status ) ) <EOL> def test_reactivate_protected_image ( self ) : <EOL> """<STR_LIT>""" <EOL> resp = self . images_admin . client . reactivate_image ( <EOL> self . protected_image . id_ ) <EOL> self . assertEqual ( <EOL> resp . status_code , <NUM_LIT> , <EOL> Messages . STATUS_CODE_MSG . format ( <NUM_LIT> , resp . status_code ) ) <EOL> resp = self . images . client . get_image_details ( self . protected_image . id_ ) <EOL> self . assertTrue ( resp . ok , Messages . OK_RESP_MSG . format ( resp . status_code ) ) <EOL> get_image = resp . entity <EOL> self . assertEqual ( <EOL> get_image . status , ImageStatus . ACTIVE , <EOL> msg = ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) . format ( self . protected_image . id_ , <EOL> ImageStatus . ACTIVE , get_image . status ) ) <EOL> def test_reactivate_snapshot_image ( self ) : <EOL> """<STR_LIT>""" <EOL> resp = self . images_admin . client . reactivate_image ( <EOL> self . created_snapshot . id ) <EOL> self . assertEqual ( <EOL> resp . status_code , <NUM_LIT> , <EOL> Messages . STATUS_CODE_MSG . format ( <NUM_LIT> , resp . status_code ) ) <EOL> resp = self . images . client . get_image_details ( self . created_snapshot . id ) <EOL> self . assertTrue ( resp . ok , Messages . OK_RESP_MSG . format ( resp . status_code ) ) <EOL> get_image = resp . entity <EOL> self . assertEqual ( <EOL> get_image . status , ImageStatus . ACTIVE , <EOL> msg = ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) . format ( self . created_snapshot . id , <EOL> ImageStatus . ACTIVE , get_image . status ) ) <EOL> def test_reactivate_deleted_image ( self ) : <EOL> """<STR_LIT>""" <EOL> resp = self . images_admin . client . reactivate_image ( <EOL> self . deleted_image . id_ ) <EOL> self . assertEqual ( <EOL> resp . status_code , <NUM_LIT> , <EOL> Messages . STATUS_CODE_MSG . format ( <NUM_LIT> , resp . status_code ) ) <EOL> def test_reactivate_image_using_non_admin_forbidden ( self ) : <EOL> """<STR_LIT>""" <EOL> resp = self . images . client . reactivate_image ( <EOL> self . deactivated_image . id_ ) <EOL> self . assertEqual ( <EOL> resp . status_code , <NUM_LIT> , <EOL> Messages . STATUS_CODE_MSG . format ( <NUM_LIT> , resp . status_code ) ) <EOL> resp = self . images . client . get_image_details ( <EOL> self . deactivated_image . id_ ) <EOL> self . assertTrue ( resp . ok , Messages . OK_RESP_MSG . format ( resp . status_code ) ) <EOL> get_image = resp . entity <EOL> self . assertEqual ( <EOL> get_image . status , ImageStatus . DEACTIVATED , <EOL> msg = ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) . format ( self . deactivated_image . id_ , <EOL> ImageStatus . DEACTIVATED , get_image . status ) ) <EOL> def test_reactivate_image_using_invalid_image_id ( self ) : <EOL> """<STR_LIT>""" <EOL> resp = self . images_admin . client . deactivate_image ( image_id = '<STR_LIT>' ) <EOL> self . assertEqual ( <EOL> resp . status_code , <NUM_LIT> , <EOL> Messages . STATUS_CODE_MSG . format ( <NUM_LIT> , resp . status_code ) ) </s>
