@@ -28,7 +28,7 @@
def _get_create_request_json (body_dict ):
req = webob .Request .blank ('/v1.1/123 /os-security-groups' )
req = webob .Request .blank ('/v1.1/fake /os-security-groups' )
req .headers ['Content-Type' ] = 'application/json'
req .method = 'POST'
req .body = json .dumps (body_dict )
@@ -109,7 +109,7 @@ def _format_create_xml_request_body(self, body_dict):
return '' .join (body_parts )
def _get_create_request_xml (self , body_dict ):
req = webob .Request .blank ('/v1.1/123 /os-security-groups' )
req = webob .Request .blank ('/v1.1/fake /os-security-groups' )
req .headers ['Content-Type' ] = 'application/xml'
req .content_type = 'application/xml'
req .accept = 'application/xml'
@@ -124,7 +124,7 @@ def _create_security_group_xml(self, security_group):
return response
def _delete_security_group (self , id ):
request = webob .Request .blank ('/v1.1/123 /os-security-groups/%s'
request = webob .Request .blank ('/v1.1/fake /os-security-groups/%s'
% id )
request .method = 'DELETE'
response = request .get_response (fakes .wsgi_app ())
@@ -263,7 +263,7 @@ def test_get_security_group_list(self):
security_group ['description' ] = "group-description"
response = _create_security_group_json (security_group )
req = webob .Request .blank ('/v1.1/123 /os-security-groups' )
req = webob .Request .blank ('/v1.1/fake /os-security-groups' )
req .headers ['Content-Type' ] = 'application/json'
req .method = 'GET'
response = req .get_response (fakes .wsgi_app ())
@@ -272,7 +272,7 @@ def test_get_security_group_list(self):
expected = {'security_groups' : [
{'id' : 1 ,
'name' :"default" ,
'tenant_id' : "123 " ,
'tenant_id' : "fake " ,
"description" :"default" ,
"rules" : []
},
@@ -282,7 +282,7 @@ def test_get_security_group_list(self):
{
'id' : 2 ,
'name' : "test" ,
'tenant_id' : "123 " ,
'tenant_id' : "fake " ,
"description" : "group-description" ,
"rules" : []
}
@@ -297,7 +297,7 @@ def test_get_security_group_by_id(self):
response = _create_security_group_json (security_group )
res_dict = json .loads (response .body )
req = webob .Request .blank ('/v1.1/123 /os-security-groups/%s' %
req = webob .Request .blank ('/v1.1/fake /os-security-groups/%s' %
res_dict ['security_group' ]['id' ])
req .headers ['Content-Type' ] = 'application/json'
req .method = 'GET'
@@ -308,22 +308,22 @@ def test_get_security_group_by_id(self):
'security_group' : {
'id' : 2 ,
'name' : "test" ,
'tenant_id' : "123 " ,
'tenant_id' : "fake " ,
'description' : "group-description" ,
'rules' : []
}
}
self .assertEquals (res_dict , expected )
def test_get_security_group_by_invalid_id (self ):
req = webob .Request .blank ('/v1.1/123 /os-security-groups/invalid' )
req = webob .Request .blank ('/v1.1/fake /os-security-groups/invalid' )
req .headers ['Content-Type' ] = 'application/json'
req .method = 'GET'
response = req .get_response (fakes .wsgi_app ())
self .assertEquals (response .status_int , 400 )
def test_get_security_group_by_non_existing_id (self ):
req = webob .Request .blank ('/v1.1/123 /os-security-groups/111111111' )
req = webob .Request .blank ('/v1.1/fake /os-security-groups/111111111' )
req .headers ['Content-Type' ] = 'application/json'
req .method = 'GET'
response = req .get_response (fakes .wsgi_app ())
@@ -351,7 +351,7 @@ def test_delete_security_group_by_non_existing_id(self):
def test_associate_by_non_existing_security_group_name (self ):
body = dict (addSecurityGroup = dict (name = 'non-existing' ))
req = webob .Request .blank ('/v1.1/123 /servers/1/action' )
req = webob .Request .blank ('/v1.1/fake /servers/1/action' )
req .headers ['Content-Type' ] = 'application/json'
req .method = 'POST'
req .body = json .dumps (body )
@@ -362,15 +362,15 @@ def test_associate_by_invalid_server_id(self):
body = dict (addSecurityGroup = dict (name = 'test' ))
self .stubs .Set (nova .db .api , 'security_group_get_by_name' ,
return_security_group )
req = webob .Request .blank ('/v1.1/123 /servers/invalid/action' )
req = webob .Request .blank ('/v1.1/fake /servers/invalid/action' )
req .headers ['Content-Type' ] = 'application/json'
req .method = 'POST'
req .body = json .dumps (body )
response = req .get_response (fakes .wsgi_app ())
self .assertEquals (response .status_int , 400 )
def test_associate_without_body (self ):
req = webob .Request .blank ('/v1.1/123 /servers/1/action' )
req = webob .Request .blank ('/v1.1/fake /servers/1/action' )
body = dict (addSecurityGroup = None )
self .stubs .Set (nova .db .api , 'instance_get' , return_server )
req .headers ['Content-Type' ] = 'application/json'
@@ -380,7 +380,7 @@ def test_associate_without_body(self):
self .assertEquals (response .status_int , 400 )
def test_associate_no_security_group_name (self ):
req = webob .Request .blank ('/v1.1/123 /servers/1/action' )
req = webob .Request .blank ('/v1.1/fake /servers/1/action' )
body = dict (addSecurityGroup = dict ())
self .stubs .Set (nova .db .api , 'instance_get' , return_server )
req .headers ['Content-Type' ] = 'application/json'
@@ -390,7 +390,7 @@ def test_associate_no_security_group_name(self):
self .assertEquals (response .status_int , 400 )
def test_associate_security_group_name_with_whitespaces (self ):
req = webob .Request .blank ('/v1.1/123 /servers/1/action' )
req = webob .Request .blank ('/v1.1/fake /servers/1/action' )
body = dict (addSecurityGroup = dict (name = " " ))
self .stubs .Set (nova .db .api , 'instance_get' , return_server )
req .headers ['Content-Type' ] = 'application/json'
@@ -404,7 +404,7 @@ def test_associate_non_existing_instance(self):
body = dict (addSecurityGroup = dict (name = "test" ))
self .stubs .Set (nova .db .api , 'security_group_get_by_name' ,
return_security_group )
req = webob .Request .blank ('/v1.1/123 /servers/10000/action' )
req = webob .Request .blank ('/v1.1/fake /servers/10000/action' )
req .headers ['Content-Type' ] = 'application/json'
req .method = 'POST'
req .body = json .dumps (body )
@@ -416,7 +416,7 @@ def test_associate_non_running_instance(self):
self .stubs .Set (nova .db .api , 'security_group_get_by_name' ,
return_security_group_without_instances )
body = dict (addSecurityGroup = dict (name = "test" ))
req = webob .Request .blank ('/v1.1/123 /servers/1/action' )
req = webob .Request .blank ('/v1.1/fake /servers/1/action' )
req .headers ['Content-Type' ] = 'application/json'
req .method = 'POST'
req .body = json .dumps (body )
@@ -428,7 +428,7 @@ def test_associate_already_associated_security_group_to_instance(self):
self .stubs .Set (nova .db .api , 'security_group_get_by_name' ,
return_security_group )
body = dict (addSecurityGroup = dict (name = "test" ))
req = webob .Request .blank ('/v1.1/123 /servers/1/action' )
req = webob .Request .blank ('/v1.1/fake /servers/1/action' )
req .headers ['Content-Type' ] = 'application/json'
req .method = 'POST'
req .body = json .dumps (body )
@@ -446,7 +446,7 @@ def test_associate(self):
self .mox .ReplayAll ()
body = dict (addSecurityGroup = dict (name = "test" ))
req = webob .Request .blank ('/v1.1/123 /servers/1/action' )
req = webob .Request .blank ('/v1.1/fake /servers/1/action' )
req .headers ['Content-Type' ] = 'application/json'
req .method = 'POST'
req .body = json .dumps (body )
@@ -463,7 +463,7 @@ def test_associate_xml(self):
return_security_group_without_instances )
self .mox .ReplayAll ()
req = webob .Request .blank ('/v1.1/123 /servers/1/action' )
req = webob .Request .blank ('/v1.1/fake /servers/1/action' )
req .headers ['Content-Type' ] = 'application/xml'
req .method = 'POST'
req .body = """<addSecurityGroup>
@@ -474,7 +474,7 @@ def test_associate_xml(self):
def test_disassociate_by_non_existing_security_group_name (self ):
body = dict (removeSecurityGroup = dict (name = 'non-existing' ))
req = webob .Request .blank ('/v1.1/123 /servers/1/action' )
req = webob .Request .blank ('/v1.1/fake /servers/1/action' )
req .headers ['Content-Type' ] = 'application/json'
req .method = 'POST'
req .body = json .dumps (body )
@@ -485,15 +485,15 @@ def test_disassociate_by_invalid_server_id(self):
body = dict (removeSecurityGroup = dict (name = 'test' ))
self .stubs .Set (nova .db .api , 'security_group_get_by_name' ,
return_security_group )
req = webob .Request .blank ('/v1.1/123 /servers/invalid/action' )
req = webob .Request .blank ('/v1.1/fake /servers/invalid/action' )
req .headers ['Content-Type' ] = 'application/json'
req .method = 'POST'
req .body = json .dumps (body )
response = req .get_response (fakes .wsgi_app ())
self .assertEquals (response .status_int , 400 )
def test_disassociate_without_body (self ):
req = webob .Request .blank ('/v1.1/123 /servers/1/action' )
req = webob .Request .blank ('/v1.1/fake /servers/1/action' )
body = dict (removeSecurityGroup = None )
self .stubs .Set (nova .db .api , 'instance_get' , return_server )
req .headers ['Content-Type' ] = 'application/json'
@@ -503,7 +503,7 @@ def test_disassociate_without_body(self):
self .assertEquals (response .status_int , 400 )
def test_disassociate_no_security_group_name (self ):
req = webob .Request .blank ('/v1.1/123 /servers/1/action' )
req = webob .Request .blank ('/v1.1/fake /servers/1/action' )
body = dict (removeSecurityGroup = dict ())
self .stubs .Set (nova .db .api , 'instance_get' , return_server )
req .headers ['Content-Type' ] = 'application/json'
@@ -513,7 +513,7 @@ def test_disassociate_no_security_group_name(self):
self .assertEquals (response .status_int , 400 )
def test_disassociate_security_group_name_with_whitespaces (self ):
req = webob .Request .blank ('/v1.1/123 /servers/1/action' )
req = webob .Request .blank ('/v1.1/fake /servers/1/action' )
body = dict (removeSecurityGroup = dict (name = " " ))
self .stubs .Set (nova .db .api , 'instance_get' , return_server )
req .headers ['Content-Type' ] = 'application/json'
@@ -527,7 +527,7 @@ def test_disassociate_non_existing_instance(self):
body = dict (removeSecurityGroup = dict (name = "test" ))
self .stubs .Set (nova .db .api , 'security_group_get_by_name' ,
return_security_group )
req = webob .Request .blank ('/v1.1/123 /servers/10000/action' )
req = webob .Request .blank ('/v1.1/fake /servers/10000/action' )
req .headers ['Content-Type' ] = 'application/json'
req .method = 'POST'
req .body = json .dumps (body )
@@ -539,7 +539,7 @@ def test_disassociate_non_running_instance(self):
self .stubs .Set (nova .db .api , 'security_group_get_by_name' ,
return_security_group )
body = dict (removeSecurityGroup = dict (name = "test" ))
req = webob .Request .blank ('/v1.1/123 /servers/1/action' )
req = webob .Request .blank ('/v1.1/fake /servers/1/action' )
req .headers ['Content-Type' ] = 'application/json'
req .method = 'POST'
req .body = json .dumps (body )
@@ -551,7 +551,7 @@ def test_disassociate_already_associated_security_group_to_instance(self):
self .stubs .Set (nova .db .api , 'security_group_get_by_name' ,
return_security_group_without_instances )
body = dict (removeSecurityGroup = dict (name = "test" ))
req = webob .Request .blank ('/v1.1/123 /servers/1/action' )
req = webob .Request .blank ('/v1.1/fake /servers/1/action' )
req .headers ['Content-Type' ] = 'application/json'
req .method = 'POST'
req .body = json .dumps (body )
@@ -569,7 +569,7 @@ def test_disassociate(self):
self .mox .ReplayAll ()
body = dict (removeSecurityGroup = dict (name = "test" ))
req = webob .Request .blank ('/v1.1/123 /servers/1/action' )
req = webob .Request .blank ('/v1.1/fake /servers/1/action' )
req .headers ['Content-Type' ] = 'application/json'
req .method = 'POST'
req .body = json .dumps (body )
@@ -586,7 +586,7 @@ def test_disassociate_xml(self):
return_security_group )
self .mox .ReplayAll ()
req = webob .Request .blank ('/v1.1/123 /servers/1/action' )
req = webob .Request .blank ('/v1.1/fake /servers/1/action' )
req .headers ['Content-Type' ] = 'application/xml'
req .method = 'POST'
req .body = """<removeSecurityGroup>
@@ -624,15 +624,15 @@ def tearDown(self):
super (TestSecurityGroupRules , self ).tearDown ()
def _create_security_group_rule_json (self , rules ):
request = webob .Request .blank ('/v1.1/123 /os-security-group-rules' )
request = webob .Request .blank ('/v1.1/fake /os-security-group-rules' )
request .headers ['Content-Type' ] = 'application/json'
request .method = 'POST'
request .body = json .dumps (rules )
response = request .get_response (fakes .wsgi_app ())
return response
def _delete_security_group_rule (self , id ):
request = webob .Request .blank ('/v1.1/123 /os-security-group-rules/%s'
request = webob .Request .blank ('/v1.1/fake /os-security-group-rules/%s'
% id )
request .method = 'DELETE'
response = request .get_response (fakes .wsgi_app ())
@@ -690,15 +690,15 @@ def test_create_add_existing_rules_json(self):
self .assertEquals (response .status_int , 400 )
def test_create_with_no_body_json (self ):
request = webob .Request .blank ('/v1.1/123 /os-security-group-rules' )
request = webob .Request .blank ('/v1.1/fake /os-security-group-rules' )
request .headers ['Content-Type' ] = 'application/json'
request .method = 'POST'
request .body = json .dumps (None )
response = request .get_response (fakes .wsgi_app ())
self .assertEquals (response .status_int , 422 )
def test_create_with_no_security_group_rule_in_body_json (self ):
request = webob .Request .blank ('/v1.1/123 /os-security-group-rules' )
request = webob .Request .blank ('/v1.1/fake /os-security-group-rules' )
request .headers ['Content-Type' ] = 'application/json'
request .method = 'POST'
body_dict = {'test' : "test" }