<s> """<STR_LIT>""" <EOL> import calendar <EOL> import time <EOL> from cloudcafe . common . tools . datagen import rand_name <EOL> from cloudcafe . glance . common . constants import Messages <EOL> from cloudcafe . glance . common . types import ImageMemberStatus <EOL> from cloudroast . glance . fixtures import ImagesFixture <EOL> class ImageSharingOperationsActions ( ImagesFixture ) : <EOL> @ classmethod <EOL> def setUpClass ( cls ) : <EOL> super ( ImageSharingOperationsActions , cls ) . setUpClass ( ) <EOL> cls . member_id = cls . images_alt_one . auth . tenant_id <EOL> cls . alt_member_id = cls . images_alt_two . auth . tenant_id <EOL> created_images = cls . images . behaviors . create_images_via_task ( <EOL> image_properties = { <EOL> '<STR_LIT:name>' : rand_name ( '<STR_LIT>' ) } , <EOL> count = <NUM_LIT:5> ) <EOL> cls . create_image_member_image = created_images . pop ( ) <EOL> cls . delete_image_member_image = created_images . pop ( ) <EOL> cls . images . client . create_image_member ( <EOL> cls . delete_image_member_image . id_ , cls . member_id ) <EOL> cls . get_image_member_image = created_images . pop ( ) <EOL> resp = cls . images . client . create_image_member ( <EOL> cls . get_image_member_image . id_ , cls . member_id ) <EOL> cls . member_get_image = resp . entity <EOL> cls . list_image_member_image = created_images . pop ( ) <EOL> cls . images . client . create_image_member ( <EOL> cls . list_image_member_image . id_ , cls . member_id ) <EOL> cls . images . client . create_image_member ( <EOL> cls . list_image_member_image . id_ , cls . alt_member_id ) <EOL> cls . image_member_created_at_time_in_sec = ( <EOL> calendar . timegm ( time . gmtime ( ) ) ) <EOL> cls . update_image_member_image = created_images . pop ( ) <EOL> resp = cls . images . client . create_image_member ( <EOL> cls . update_image_member_image . id_ , cls . member_id ) <EOL> cls . member_update_image = resp . entity <EOL> @ classmethod <EOL> def tearDownClass ( cls ) : <EOL> cls . images . behaviors . resources . release ( ) <EOL> super ( ImageSharingOperationsActions , cls ) . tearDownClass ( ) <EOL> def test_create_image_member ( self ) : <EOL> """<STR_LIT>""" <EOL> errors = [ ] <EOL> resp = self . images . client . create_image_member ( <EOL> self . create_image_member_image . id_ , self . member_id ) <EOL> image_member_created_at_time_in_sec = calendar . timegm ( time . gmtime ( ) ) <EOL> self . assertEqual ( <EOL> resp . status_code , <NUM_LIT:200> , <EOL> Messages . STATUS_CODE_MSG . format ( <NUM_LIT:200> , resp . status_code ) ) <EOL> image_member = resp . entity <EOL> created_at_delta = self . images . behaviors . get_time_delta ( <EOL> image_member_created_at_time_in_sec , image_member . created_at ) <EOL> updated_at_delta = self . images . behaviors . get_time_delta ( <EOL> image_member_created_at_time_in_sec , image_member . updated_at ) <EOL> if created_at_delta > self . images . config . max_created_at_delta : <EOL> errors . append ( Messages . PROPERTY_MSG . format ( <EOL> '<STR_LIT>' , self . images . config . max_created_at_delta , <EOL> created_at_delta ) ) <EOL> if image_member . image_id != self . create_image_member_image . id_ : <EOL> errors . append ( Messages . PROPERTY_MSG . format ( <EOL> '<STR_LIT>' , self . create_image_member_image . id_ , <EOL> image_member . image_id ) ) <EOL> if image_member . member_id != self . member_id : <EOL> errors . append ( Messages . PROPERTY_MSG . format ( <EOL> '<STR_LIT>' , self . member_id , image_member . member_id ) ) <EOL> if image_member . status != ImageMemberStatus . PENDING : <EOL> errors . append ( Messages . PROPERTY_MSG . format ( <EOL> '<STR_LIT:status>' , ImageMemberStatus . PENDING , image_member . status ) ) <EOL> if updated_at_delta > self . images . config . max_updated_at_delta : <EOL> errors . append ( Messages . PROPERTY_MSG . format ( <EOL> '<STR_LIT>' , self . images . config . max_updated_at_delta , <EOL> updated_at_delta ) ) <EOL> self . assertEqual ( <EOL> errors , [ ] , <EOL> msg = ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) . format ( self . create_image_member_image . id_ , <EOL> errors ) ) <EOL> def test_delete_image_member ( self ) : <EOL> """<STR_LIT>""" <EOL> resp = self . images . client . delete_image_member ( <EOL> self . delete_image_member_image . id_ , self . member_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 . list_image_members ( <EOL> self . delete_image_member_image . id_ ) <EOL> self . assertTrue ( resp . ok , Messages . OK_RESP_MSG . format ( resp . status_code ) ) <EOL> members = resp . entity <EOL> self . assertListEqual ( <EOL> members , [ ] , <EOL> msg = ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) . format ( self . delete_image_member_image . id_ , <EOL> members ) ) <EOL> listed_images = self . images_alt_one . behaviors . list_all_images ( ) <EOL> self . assertNotIn ( <EOL> self . delete_image_member_image , listed_images , <EOL> msg = ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) . format ( self . delete_image_member_image , <EOL> listed_images ) ) <EOL> def test_get_image_member ( self ) : <EOL> """<STR_LIT>""" <EOL> errors = [ ] <EOL> resp = self . images . client . get_image_member ( <EOL> self . get_image_member_image . id_ , self . member_id ) <EOL> self . assertEqual ( <EOL> resp . status_code , <NUM_LIT:200> , <EOL> Messages . STATUS_CODE_MSG . format ( <NUM_LIT:200> , resp . status_code ) ) <EOL> get_member = resp . entity <EOL> if get_member . created_at != self . member_get_image . created_at : <EOL> errors . append ( self . error_msg . format ( <EOL> '<STR_LIT>' , self . member_get_image . created_at , <EOL> get_member . created_at ) ) <EOL> if get_member . image_id != self . member_get_image . image_id : <EOL> errors . append ( self . error_msg . format ( <EOL> '<STR_LIT>' , self . member_get_image . image_id , <EOL> get_member . image_id ) ) <EOL> if get_member . member_id != self . member_get_image . member_id : <EOL> errors . append ( self . error_msg . format ( <EOL> '<STR_LIT>' , self . member_get_image . member_id , <EOL> get_member . member_id ) ) <EOL> if get_member . schema != self . member_get_image . schema : <EOL> errors . append ( self . error_msg . format ( <EOL> '<STR_LIT>' , self . member_get_image . schema , get_member . schema ) ) <EOL> if get_member . status != self . member_get_image . status : <EOL> errors . append ( self . error_msg . format ( <EOL> '<STR_LIT:status>' , self . member_get_image . status , get_member . status ) ) <EOL> if get_member . updated_at != self . member_get_image . updated_at : <EOL> errors . append ( self . error_msg . format ( <EOL> '<STR_LIT>' , self . member_get_image . updated_at , <EOL> get_member . updated_at ) ) <EOL> self . assertEqual ( <EOL> errors , [ ] , <EOL> msg = ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) . format ( self . get_image_member_image . id_ , <EOL> errors ) ) <EOL> def test_list_image_members ( self ) : <EOL> """<STR_LIT>""" <EOL> image_member_ids = [ ] <EOL> errors = [ ] <EOL> resp = self . images . client . list_image_members ( <EOL> self . list_image_member_image . id_ ) <EOL> self . assertEqual ( <EOL> resp . status_code , <NUM_LIT:200> , <EOL> Messages . STATUS_CODE_MSG . format ( <NUM_LIT:200> , resp . status_code ) ) <EOL> listed_image_members = resp . entity <EOL> self . assertEqual ( <EOL> len ( listed_image_members ) , <NUM_LIT:2> , <EOL> msg = ( '<STR_LIT>' <EOL> '<STR_LIT>' ) . format ( len ( listed_image_members ) ) ) <EOL> [ image_member_ids . append ( image_member . member_id ) <EOL> for image_member in listed_image_members ] <EOL> self . assertIn ( <EOL> self . member_id , image_member_ids , <EOL> msg = ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) . format ( self . member_id , image_member_ids ) ) <EOL> self . assertIn ( <EOL> self . alt_member_id , image_member_ids , <EOL> msg = ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) . format ( self . alt_member_id , image_member_ids ) ) <EOL> for image_member in listed_image_members : <EOL> created_at_delta = self . images . behaviors . get_time_delta ( <EOL> self . image_member_created_at_time_in_sec , <EOL> image_member . created_at ) <EOL> updated_at_delta = self . images . behaviors . get_time_delta ( <EOL> self . image_member_created_at_time_in_sec , <EOL> image_member . updated_at ) <EOL> if created_at_delta > self . images . config . max_created_at_delta : <EOL> errors . append ( Messages . PROPERTY_MSG . format ( <EOL> '<STR_LIT>' , <EOL> self . images . config . max_created_at_delta , created_at_delta ) ) <EOL> if image_member . image_id != self . list_image_member_image . id_ : <EOL> errors . append ( Messages . PROPERTY_MSG . format ( <EOL> '<STR_LIT>' , self . list_image_member_image . id_ , <EOL> image_member . image_id ) ) <EOL> if ( image_member . member_id != self . member_id and <EOL> image_member . member_id != self . alt_member_id ) : <EOL> errors . append ( Messages . PROPERTY_MSG . format ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' . format ( self . member_id , <EOL> self . alt_member_id ) , <EOL> image_member . member_id ) ) <EOL> if image_member . status != ImageMemberStatus . PENDING : <EOL> errors . append ( Messages . PROPERTY_MSG . format ( <EOL> '<STR_LIT:status>' , ImageMemberStatus . PENDING , image_member . status ) ) <EOL> if updated_at_delta > self . images . config . max_updated_at_delta : <EOL> errors . append ( Messages . PROPERTY_MSG . format ( <EOL> '<STR_LIT>' , <EOL> self . images . config . max_updated_at_delta , updated_at_delta ) ) <EOL> self . assertEqual ( <EOL> errors , [ ] , <EOL> msg = ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) . format ( self . list_image_member_image . id_ , <EOL> errors ) ) <EOL> def test_update_image_member ( self ) : <EOL> """<STR_LIT>""" <EOL> errors = [ ] <EOL> resp = self . images_alt_one . client . update_image_member ( <EOL> self . update_image_member_image . id_ , self . member_id , <EOL> ImageMemberStatus . ACCEPTED ) <EOL> self . assertEqual ( <EOL> resp . status_code , <NUM_LIT:200> , <EOL> Messages . STATUS_CODE_MSG . format ( <NUM_LIT:200> , resp . status_code ) ) <EOL> updated_member = resp . entity <EOL> if updated_member . created_at != self . member_update_image . created_at : <EOL> errors . append ( Messages . PROPERTY_MSG . format ( <EOL> '<STR_LIT>' , self . member_update_image . created_at , <EOL> updated_member . created_at ) ) <EOL> if updated_member . image_id != self . member_update_image . image_id : <EOL> errors . append ( Messages . PROPERTY_MSG . format ( <EOL> '<STR_LIT>' , self . member_update_image . image_id , <EOL> updated_member . image_id ) ) <EOL> if updated_member . member_id != self . member_update_image . member_id : <EOL> errors . append ( Messages . PROPERTY_MSG . format ( <EOL> '<STR_LIT>' , self . member_update_image . member_id , <EOL> updated_member . member_id ) ) <EOL> if updated_member . schema != self . member_update_image . schema : <EOL> errors . append ( Messages . PROPERTY_MSG . format ( <EOL> '<STR_LIT>' , self . member_update_image . schema , <EOL> updated_member . schema ) ) <EOL> if updated_member . status != ImageMemberStatus . ACCEPTED : <EOL> errors . append ( Messages . PROPERTY_MSG . format ( <EOL> '<STR_LIT:status>' , ImageMemberStatus . ACCEPTED , updated_member . status ) ) <EOL> if updated_member . updated_at < self . member_update_image . updated_at : <EOL> errors . append ( Messages . PROPERTY_MSG . format ( <EOL> '<STR_LIT>' , self . member_update_image . updated_at , <EOL> updated_member . updated_at ) ) <EOL> self . assertEqual ( <EOL> errors , [ ] , <EOL> msg = ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) . format ( self . update_image_member_image . id_ , <EOL> errors ) ) </s>
