<s> import base64 <EOL> import tempfile <EOL> from rackclient import exceptions as exc <EOL> from rackclient . tests import utils <EOL> from rackclient . tests . v1 import fakes <EOL> from rackclient . v1 import processes <EOL> class ProcesssTest ( utils . TestCase ) : <EOL> def setUp ( self ) : <EOL> super ( ProcesssTest , self ) . setUp ( ) <EOL> self . cs = fakes . FakeClient ( ) <EOL> self . process_type = processes . Process <EOL> self . gid = '<STR_LIT>' <EOL> self . user_id = '<STR_LIT>' <EOL> self . project_id = '<STR_LIT>' <EOL> def test_list ( self ) : <EOL> processes = self . cs . processes . list ( self . gid ) <EOL> self . cs . assert_called ( '<STR_LIT:GET>' , '<STR_LIT>' % self . gid ) <EOL> for process in processes : <EOL> self . assertIsInstance ( process , self . process_type ) <EOL> def test_get ( self ) : <EOL> pid = '<STR_LIT>' <EOL> process = self . cs . processes . get ( self . gid , pid ) <EOL> self . cs . assert_called ( '<STR_LIT:GET>' , '<STR_LIT>' % ( self . gid , pid ) ) <EOL> self . assertEqual ( self . gid , process . gid ) <EOL> self . assertEqual ( self . user_id , process . user_id ) <EOL> self . assertEqual ( self . project_id , process . project_id ) <EOL> self . assertEqual ( pid , process . pid ) <EOL> self . assertEqual ( None , process . ppid ) <EOL> self . assertEqual ( '<STR_LIT>' , process . nova_instance_id ) <EOL> self . assertEqual ( '<STR_LIT>' , process . name ) <EOL> self . assertEqual ( '<STR_LIT>' , process . glance_image_id ) <EOL> self . assertEqual ( '<STR_LIT>' , process . nova_flavor_id ) <EOL> self . assertEqual ( '<STR_LIT>' , process . keypair_id ) <EOL> self . assertEqual ( [ '<STR_LIT>' , '<STR_LIT>' ] , process . securitygroup_ids ) <EOL> networks = [ { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } ] <EOL> self . assertEqual ( networks , process . networks ) <EOL> self . assertEqual ( '<STR_LIT>' , process . app_status ) <EOL> self . assertEqual ( '<STR_LIT>' , process . status ) <EOL> self . assertEqual ( '<STR_LIT>' , process . userdata ) <EOL> args = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> self . assertEqual ( args , process . args ) <EOL> def _create_body ( self , ppid = None , name = None , nova_flavor_id = None , <EOL> glance_image_id = None , keypair_id = None , <EOL> securitygroup_ids = None , userdata = None , args = None ) : <EOL> return { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : ppid , <EOL> '<STR_LIT:name>' : name , <EOL> '<STR_LIT>' : nova_flavor_id , <EOL> '<STR_LIT>' : glance_image_id , <EOL> '<STR_LIT>' : keypair_id , <EOL> '<STR_LIT>' : securitygroup_ids , <EOL> '<STR_LIT>' : userdata , <EOL> '<STR_LIT:args>' : args <EOL> } <EOL> } <EOL> def test_create ( self ) : <EOL> userdata = '<STR_LIT>' <EOL> f = tempfile . TemporaryFile ( ) <EOL> f . write ( userdata ) <EOL> f . seek ( <NUM_LIT:0> ) <EOL> params = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : <NUM_LIT:1> , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : [ '<STR_LIT>' , '<STR_LIT>' ] , <EOL> '<STR_LIT>' : f , <EOL> '<STR_LIT:args>' : { <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" <EOL> } <EOL> } <EOL> process = self . cs . processes . create ( self . gid , ** params ) <EOL> body = self . _create_body ( ** params ) <EOL> body [ '<STR_LIT>' ] [ '<STR_LIT>' ] = base64 . b64encode ( userdata ) <EOL> self . cs . assert_called ( '<STR_LIT:POST>' , '<STR_LIT>' % self . gid , body ) <EOL> self . assertIsInstance ( process , self . process_type ) <EOL> def test_create_invalid_parameters ( self ) : <EOL> ppid = '<STR_LIT>' <EOL> self . assertRaises ( exc . CommandError , self . cs . processes . create , <EOL> self . gid , ppid = ppid , securitygroup_ids = '<STR_LIT>' ) <EOL> self . assertRaises ( exc . CommandError , self . cs . processes . create , <EOL> self . gid , ppid = ppid , args = '<STR_LIT>' ) <EOL> def _update_body ( self , app_status ) : <EOL> return { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : app_status <EOL> } <EOL> } <EOL> def test_update ( self ) : <EOL> app_status = '<STR_LIT>' <EOL> pid = '<STR_LIT>' <EOL> process = self . cs . processes . update ( self . gid , <EOL> pid , app_status ) <EOL> body = self . _update_body ( app_status ) <EOL> self . cs . assert_called ( '<STR_LIT>' , '<STR_LIT>' % ( self . gid , pid ) , body ) <EOL> self . assertIsInstance ( process , self . process_type ) <EOL> def test_delete ( self ) : <EOL> pid = '<STR_LIT>' <EOL> self . cs . processes . delete ( self . gid , pid ) <EOL> self . cs . assert_called ( '<STR_LIT>' , '<STR_LIT>' % ( self . gid , pid ) ) </s>
