<s> import cgi <EOL> from django . conf import settings <EOL> from django . core . urlresolvers import reverse <EOL> from django import http <EOL> from mox import IsA <EOL> from openstack_dashboard import api <EOL> from openstack_dashboard . test import helpers as test <EOL> from openstack_dashboard . dashboards . project . access_and_security . security_groups import tables <EOL> INDEX_URL = reverse ( '<STR_LIT>' ) <EOL> SG_CREATE_URL = reverse ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> def strip_absolute_base ( uri ) : <EOL> return uri . split ( settings . TESTSERVER , <NUM_LIT:1> ) [ - <NUM_LIT:1> ] <EOL> class SecurityGroupsViewTests ( test . TestCase ) : <EOL> secgroup_backend = '<STR_LIT>' <EOL> def setUp ( self ) : <EOL> super ( SecurityGroupsViewTests , self ) . setUp ( ) <EOL> sec_group = self . security_groups . first ( ) <EOL> self . detail_url = reverse ( '<STR_LIT>' <EOL> '<STR_LIT>' , <EOL> args = [ sec_group . id ] ) <EOL> self . edit_url = reverse ( '<STR_LIT>' <EOL> '<STR_LIT>' , <EOL> args = [ sec_group . id ] ) <EOL> @ test . create_stubs ( { api . network : ( '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ) } ) <EOL> def _add_security_group_rule_fixture ( self , ** kwargs ) : <EOL> sec_group = self . security_groups . first ( ) <EOL> sec_group_list = self . security_groups . list ( ) <EOL> rule = self . security_group_rules . first ( ) <EOL> api . network . security_group_backend ( <EOL> IsA ( http . HttpRequest ) ) . AndReturn ( self . secgroup_backend ) <EOL> api . network . security_group_rule_create ( <EOL> IsA ( http . HttpRequest ) , <EOL> kwargs . get ( '<STR_LIT>' , sec_group . id ) , <EOL> kwargs . get ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> kwargs . get ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> kwargs . get ( '<STR_LIT>' , rule . ip_protocol ) , <EOL> kwargs . get ( '<STR_LIT>' , int ( rule . from_port ) ) , <EOL> kwargs . get ( '<STR_LIT>' , int ( rule . to_port ) ) , <EOL> kwargs . get ( '<STR_LIT>' , rule . ip_range [ '<STR_LIT>' ] ) , <EOL> kwargs . get ( '<STR_LIT>' , u'<STR_LIT:%s>' % sec_group . id ) ) . AndReturn ( rule ) <EOL> api . network . security_group_list ( <EOL> IsA ( http . HttpRequest ) ) . AndReturn ( sec_group_list ) <EOL> return sec_group , rule <EOL> @ test . create_stubs ( { api . network : ( '<STR_LIT>' , ) } ) <EOL> def test_update_security_groups_get ( self ) : <EOL> sec_group = self . security_groups . first ( ) <EOL> api . network . security_group_get ( IsA ( http . HttpRequest ) , <EOL> sec_group . id ) . AndReturn ( sec_group ) <EOL> self . mox . ReplayAll ( ) <EOL> res = self . client . get ( reverse ( '<STR_LIT>' <EOL> '<STR_LIT>' , <EOL> args = [ sec_group . id ] ) ) <EOL> self . assertTemplateUsed ( <EOL> res , '<STR_LIT>' ) <EOL> self . assertEqual ( res . context [ '<STR_LIT>' ] . name , <EOL> sec_group . name ) <EOL> @ test . create_stubs ( { api . network : ( '<STR_LIT>' , <EOL> '<STR_LIT>' ) } ) <EOL> def test_update_security_groups_post ( self ) : <EOL> sec_group = self . security_groups . get ( name = "<STR_LIT>" ) <EOL> api . network . security_group_update ( IsA ( http . HttpRequest ) , <EOL> str ( sec_group . id ) , <EOL> sec_group . name , <EOL> sec_group . description ) . AndReturn ( sec_group ) <EOL> api . network . security_group_get ( IsA ( http . HttpRequest ) , <EOL> sec_group . id ) . AndReturn ( sec_group ) <EOL> self . mox . ReplayAll ( ) <EOL> formData = { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:id>' : sec_group . id , <EOL> '<STR_LIT:name>' : sec_group . name , <EOL> '<STR_LIT:description>' : sec_group . description } <EOL> update_url = reverse ( '<STR_LIT>' <EOL> '<STR_LIT>' , <EOL> args = [ sec_group . id ] ) <EOL> res = self . client . post ( update_url , formData ) <EOL> self . assertRedirectsNoFollow ( res , INDEX_URL ) <EOL> def test_create_security_groups_get ( self ) : <EOL> res = self . client . get ( SG_CREATE_URL ) <EOL> self . assertTemplateUsed ( <EOL> res , '<STR_LIT>' ) <EOL> @ test . create_stubs ( { api . network : ( '<STR_LIT>' , ) } ) <EOL> def test_create_security_groups_post ( self ) : <EOL> sec_group = self . security_groups . first ( ) <EOL> api . network . security_group_create ( IsA ( http . HttpRequest ) , <EOL> sec_group . name , <EOL> sec_group . description ) . AndReturn ( sec_group ) <EOL> self . mox . ReplayAll ( ) <EOL> formData = { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:name>' : sec_group . name , <EOL> '<STR_LIT:description>' : sec_group . description } <EOL> res = self . client . post ( SG_CREATE_URL , formData ) <EOL> self . assertRedirectsNoFollow ( res , INDEX_URL ) <EOL> @ test . create_stubs ( { api . network : ( '<STR_LIT>' , ) } ) <EOL> def test_create_security_groups_post_exception ( self ) : <EOL> sec_group = self . security_groups . first ( ) <EOL> api . network . security_group_create ( IsA ( http . HttpRequest ) , <EOL> sec_group . name , <EOL> sec_group . description ) . AndRaise ( self . exceptions . nova ) <EOL> self . mox . ReplayAll ( ) <EOL> formData = { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:name>' : sec_group . name , <EOL> '<STR_LIT:description>' : sec_group . description } <EOL> res = self . client . post ( SG_CREATE_URL , formData ) <EOL> self . assertMessageCount ( error = <NUM_LIT:1> ) <EOL> self . assertRedirectsNoFollow ( res , INDEX_URL ) <EOL> @ test . create_stubs ( { api . network : ( '<STR_LIT>' , ) } ) <EOL> def test_create_security_groups_post_wrong_name ( self ) : <EOL> sec_group = self . security_groups . first ( ) <EOL> fail_name = sec_group . name + '<STR_LIT>' <EOL> self . mox . ReplayAll ( ) <EOL> formData = { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:name>' : fail_name , <EOL> '<STR_LIT:description>' : sec_group . description } <EOL> res = self . client . post ( SG_CREATE_URL , formData ) <EOL> self . assertTemplateUsed ( <EOL> res , '<STR_LIT>' ) <EOL> self . assertContains ( res , "<STR_LIT>" ) <EOL> @ test . create_stubs ( { api . network : ( '<STR_LIT>' , ) } ) <EOL> def test_detail_get ( self ) : <EOL> sec_group = self . security_groups . first ( ) <EOL> api . network . security_group_get ( IsA ( http . HttpRequest ) , <EOL> sec_group . id ) . AndReturn ( sec_group ) <EOL> self . mox . ReplayAll ( ) <EOL> res = self . client . get ( self . detail_url ) <EOL> self . assertTemplateUsed ( <EOL> res , '<STR_LIT>' ) <EOL> @ test . create_stubs ( { api . network : ( '<STR_LIT>' , ) } ) <EOL> def test_detail_get_exception ( self ) : <EOL> sec_group = self . security_groups . first ( ) <EOL> api . network . security_group_get ( IsA ( http . HttpRequest ) , <EOL> sec_group . id ) . AndRaise ( self . exceptions . nova ) <EOL> self . mox . ReplayAll ( ) <EOL> res = self . client . get ( self . detail_url ) <EOL> self . assertRedirectsNoFollow ( res , INDEX_URL ) <EOL> def test_detail_add_rule_cidr ( self ) : <EOL> sec_group , rule = self . _add_security_group_rule_fixture ( <EOL> security_group = None ) <EOL> self . mox . ReplayAll ( ) <EOL> formData = { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:id>' : sec_group . id , <EOL> '<STR_LIT>' : '<STR_LIT:port>' , <EOL> '<STR_LIT:port>' : rule . from_port , <EOL> '<STR_LIT>' : rule . ip_protocol , <EOL> '<STR_LIT>' : rule . ip_range [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : '<STR_LIT>' } <EOL> res = self . client . post ( self . edit_url , formData ) <EOL> self . assertRedirectsNoFollow ( res , self . detail_url ) <EOL> def test_detail_add_rule_cidr_with_invalid_unused_fields ( self ) : <EOL> sec_group , rule = self . _add_security_group_rule_fixture ( <EOL> security_group = None ) <EOL> self . mox . ReplayAll ( ) <EOL> formData = { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:id>' : sec_group . id , <EOL> '<STR_LIT>' : '<STR_LIT:port>' , <EOL> '<STR_LIT:port>' : rule . from_port , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : rule . ip_protocol , <EOL> '<STR_LIT>' : rule . ip_range [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : '<STR_LIT>' } <EOL> res = self . client . post ( self . edit_url , formData ) <EOL> self . assertNoFormErrors ( res ) <EOL> self . assertRedirectsNoFollow ( res , self . detail_url ) <EOL> def test_detail_add_rule_securitygroup_with_invalid_unused_fields ( self ) : <EOL> sec_group , rule = self . _add_security_group_rule_fixture ( <EOL> cidr = None , ethertype = '<STR_LIT>' ) <EOL> self . mox . ReplayAll ( ) <EOL> formData = { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:id>' : sec_group . id , <EOL> '<STR_LIT>' : '<STR_LIT:port>' , <EOL> '<STR_LIT:port>' : rule . from_port , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : sec_group . id , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : rule . ip_protocol , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' } <EOL> res = self . client . post ( self . edit_url , formData ) <EOL> self . assertNoFormErrors ( res ) <EOL> self . assertRedirectsNoFollow ( res , self . detail_url ) <EOL> def test_detail_add_rule_icmp_with_invalid_unused_fields ( self ) : <EOL> sec_group , rule = self . _add_security_group_rule_fixture ( <EOL> ip_protocol = '<STR_LIT>' , security_group = None ) <EOL> self . mox . ReplayAll ( ) <EOL> formData = { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:id>' : sec_group . id , <EOL> '<STR_LIT>' : '<STR_LIT:port>' , <EOL> '<STR_LIT:port>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : rule . to_port , <EOL> '<STR_LIT>' : rule . from_port , <EOL> '<STR_LIT>' : sec_group . id , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : rule . ip_range [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : '<STR_LIT>' } <EOL> res = self . client . post ( self . edit_url , formData ) <EOL> self . assertNoFormErrors ( res ) <EOL> self . assertRedirectsNoFollow ( res , self . detail_url ) <EOL> @ test . create_stubs ( { api . network : ( '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ) } ) <EOL> def test_detail_add_rule_cidr_with_template ( self ) : <EOL> sec_group = self . security_groups . first ( ) <EOL> sec_group_list = self . security_groups . list ( ) <EOL> rule = self . security_group_rules . first ( ) <EOL> api . network . security_group_backend ( <EOL> IsA ( http . HttpRequest ) ) . AndReturn ( self . secgroup_backend ) <EOL> api . network . security_group_rule_create ( IsA ( http . HttpRequest ) , <EOL> sec_group . id , <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> rule . ip_protocol , <EOL> int ( rule . from_port ) , <EOL> int ( rule . to_port ) , <EOL> rule . ip_range [ '<STR_LIT>' ] , <EOL> None ) . AndReturn ( rule ) <EOL> api . network . security_group_list ( <EOL> IsA ( http . HttpRequest ) ) . AndReturn ( sec_group_list ) <EOL> self . mox . ReplayAll ( ) <EOL> formData = { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:id>' : sec_group . id , <EOL> '<STR_LIT>' : '<STR_LIT:http>' , <EOL> '<STR_LIT>' : '<STR_LIT:port>' , <EOL> '<STR_LIT>' : rule . ip_range [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : '<STR_LIT>' } <EOL> res = self . client . post ( self . edit_url , formData ) <EOL> self . assertRedirectsNoFollow ( res , self . detail_url ) <EOL> def _get_source_group_rule ( self ) : <EOL> return self . security_group_rules . get ( id = <NUM_LIT:3> ) <EOL> @ test . create_stubs ( { api . network : ( '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ) } ) <EOL> def test_detail_add_rule_self_as_source_group ( self ) : <EOL> sec_group = self . security_groups . first ( ) <EOL> sec_group_list = self . security_groups . list ( ) <EOL> rule = self . _get_source_group_rule ( ) <EOL> api . network . security_group_backend ( <EOL> IsA ( http . HttpRequest ) ) . AndReturn ( self . secgroup_backend ) <EOL> api . network . security_group_rule_create ( <EOL> IsA ( http . HttpRequest ) , <EOL> sec_group . id , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> rule . ip_protocol , <EOL> int ( rule . from_port ) , <EOL> int ( rule . to_port ) , <EOL> None , <EOL> u'<STR_LIT:%s>' % sec_group . id ) . AndReturn ( rule ) <EOL> api . network . security_group_list ( <EOL> IsA ( http . HttpRequest ) ) . AndReturn ( sec_group_list ) <EOL> self . mox . ReplayAll ( ) <EOL> formData = { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:id>' : sec_group . id , <EOL> '<STR_LIT>' : '<STR_LIT:port>' , <EOL> '<STR_LIT:port>' : rule . from_port , <EOL> '<STR_LIT>' : rule . ip_protocol , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : sec_group . id , <EOL> '<STR_LIT>' : '<STR_LIT>' } <EOL> res = self . client . post ( self . edit_url , formData ) <EOL> self . assertRedirectsNoFollow ( res , self . detail_url ) <EOL> @ test . create_stubs ( { api . network : ( '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ) } ) <EOL> def test_detail_add_rule_self_as_source_group_with_template ( self ) : <EOL> sec_group = self . security_groups . first ( ) <EOL> sec_group_list = self . security_groups . list ( ) <EOL> rule = self . _get_source_group_rule ( ) <EOL> api . network . security_group_backend ( <EOL> IsA ( http . HttpRequest ) ) . AndReturn ( self . secgroup_backend ) <EOL> api . network . security_group_rule_create ( <EOL> IsA ( http . HttpRequest ) , <EOL> sec_group . id , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> rule . ip_protocol , <EOL> int ( rule . from_port ) , <EOL> int ( rule . to_port ) , <EOL> None , <EOL> u'<STR_LIT:%s>' % sec_group . id ) . AndReturn ( rule ) <EOL> api . network . security_group_list ( <EOL> IsA ( http . HttpRequest ) ) . AndReturn ( sec_group_list ) <EOL> self . mox . ReplayAll ( ) <EOL> formData = { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:id>' : sec_group . id , <EOL> '<STR_LIT>' : '<STR_LIT:http>' , <EOL> '<STR_LIT>' : '<STR_LIT:port>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : sec_group . id , <EOL> '<STR_LIT>' : '<STR_LIT>' } <EOL> res = self . client . post ( self . edit_url , formData ) <EOL> self . assertRedirectsNoFollow ( res , self . detail_url ) <EOL> @ test . create_stubs ( { api . network : ( '<STR_LIT>' , <EOL> '<STR_LIT>' ) } ) <EOL> def test_detail_invalid_port ( self ) : <EOL> sec_group = self . security_groups . first ( ) <EOL> sec_group_list = self . security_groups . list ( ) <EOL> rule = self . security_group_rules . first ( ) <EOL> api . network . security_group_backend ( <EOL> IsA ( http . HttpRequest ) ) . AndReturn ( self . secgroup_backend ) <EOL> api . network . security_group_list ( <EOL> IsA ( http . HttpRequest ) ) . AndReturn ( sec_group_list ) <EOL> self . mox . ReplayAll ( ) <EOL> formData = { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:id>' : sec_group . id , <EOL> '<STR_LIT>' : '<STR_LIT:port>' , <EOL> '<STR_LIT:port>' : None , <EOL> '<STR_LIT>' : rule . ip_protocol , <EOL> '<STR_LIT>' : rule . ip_range [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : '<STR_LIT>' } <EOL> res = self . client . post ( self . edit_url , formData ) <EOL> self . assertNoMessages ( ) <EOL> self . assertContains ( res , "<STR_LIT>" ) <EOL> @ test . create_stubs ( { api . network : ( '<STR_LIT>' , <EOL> '<STR_LIT>' ) } ) <EOL> def test_detail_invalid_port_range ( self ) : <EOL> sec_group = self . security_groups . first ( ) <EOL> sec_group_list = self . security_groups . list ( ) <EOL> rule = self . security_group_rules . first ( ) <EOL> for i in range ( <NUM_LIT:3> ) : <EOL> api . network . security_group_backend ( <EOL> IsA ( http . HttpRequest ) ) . AndReturn ( self . secgroup_backend ) <EOL> api . network . security_group_list ( <EOL> IsA ( http . HttpRequest ) ) . AndReturn ( sec_group_list ) <EOL> self . mox . ReplayAll ( ) <EOL> formData = { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:id>' : sec_group . id , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : rule . from_port , <EOL> '<STR_LIT>' : int ( rule . from_port ) - <NUM_LIT:1> , <EOL> '<STR_LIT>' : rule . ip_protocol , <EOL> '<STR_LIT>' : rule . ip_range [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : '<STR_LIT>' } <EOL> res = self . client . post ( self . edit_url , formData ) <EOL> self . assertNoMessages ( ) <EOL> self . assertContains ( res , "<STR_LIT>" ) <EOL> formData = { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:id>' : sec_group . id , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : rule . to_port , <EOL> '<STR_LIT>' : rule . ip_protocol , <EOL> '<STR_LIT>' : rule . ip_range [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : '<STR_LIT>' } <EOL> res = self . client . post ( self . edit_url , formData ) <EOL> self . assertNoMessages ( ) <EOL> self . assertContains ( res , cgi . escape ( '<STR_LIT>' , <EOL> quote = True ) ) <EOL> formData = { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:id>' : sec_group . id , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : rule . from_port , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : rule . ip_protocol , <EOL> '<STR_LIT>' : rule . ip_range [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : '<STR_LIT>' } <EOL> res = self . client . post ( self . edit_url , formData ) <EOL> self . assertNoMessages ( ) <EOL> self . assertContains ( res , cgi . escape ( '<STR_LIT>' , <EOL> quote = True ) ) <EOL> @ test . create_stubs ( { api . network : ( '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ) } ) <EOL> def test_detail_invalid_icmp_rule ( self ) : <EOL> sec_group = self . security_groups . first ( ) <EOL> sec_group_list = self . security_groups . list ( ) <EOL> icmp_rule = self . security_group_rules . list ( ) [ <NUM_LIT:1> ] <EOL> for i in range ( <NUM_LIT:4> ) : <EOL> api . network . security_group_backend ( <EOL> IsA ( http . HttpRequest ) ) . AndReturn ( self . secgroup_backend ) <EOL> api . network . security_group_list ( <EOL> IsA ( http . HttpRequest ) ) . AndReturn ( sec_group_list ) <EOL> self . mox . ReplayAll ( ) <EOL> formData = { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:id>' : sec_group . id , <EOL> '<STR_LIT>' : '<STR_LIT:port>' , <EOL> '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : icmp_rule . to_port , <EOL> '<STR_LIT>' : icmp_rule . ip_protocol , <EOL> '<STR_LIT>' : icmp_rule . ip_range [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : '<STR_LIT>' } <EOL> res = self . client . post ( self . edit_url , formData ) <EOL> self . assertNoMessages ( ) <EOL> self . assertContains ( res , "<STR_LIT>" ) <EOL> formData = { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:id>' : sec_group . id , <EOL> '<STR_LIT>' : '<STR_LIT:port>' , <EOL> '<STR_LIT>' : icmp_rule . from_port , <EOL> '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : icmp_rule . ip_protocol , <EOL> '<STR_LIT>' : icmp_rule . ip_range [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : '<STR_LIT>' } <EOL> res = self . client . post ( self . edit_url , formData ) <EOL> self . assertNoMessages ( ) <EOL> self . assertContains ( res , "<STR_LIT>" ) <EOL> formData = { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:id>' : sec_group . id , <EOL> '<STR_LIT>' : '<STR_LIT:port>' , <EOL> '<STR_LIT>' : icmp_rule . from_port , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : icmp_rule . ip_protocol , <EOL> '<STR_LIT>' : icmp_rule . ip_range [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : '<STR_LIT>' } <EOL> res = self . client . post ( self . edit_url , formData ) <EOL> self . assertNoMessages ( ) <EOL> self . assertContains ( res , "<STR_LIT>" ) <EOL> formData = { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:id>' : sec_group . id , <EOL> '<STR_LIT>' : '<STR_LIT:port>' , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : icmp_rule . to_port , <EOL> '<STR_LIT>' : icmp_rule . ip_protocol , <EOL> '<STR_LIT>' : icmp_rule . ip_range [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : '<STR_LIT>' } <EOL> res = self . client . post ( self . edit_url , formData ) <EOL> self . assertNoMessages ( ) <EOL> self . assertContains ( res , "<STR_LIT>" ) <EOL> @ test . create_stubs ( { api . network : ( '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ) } ) <EOL> def test_detail_add_rule_exception ( self ) : <EOL> sec_group = self . security_groups . first ( ) <EOL> sec_group_list = self . security_groups . list ( ) <EOL> rule = self . security_group_rules . first ( ) <EOL> api . network . security_group_backend ( <EOL> IsA ( http . HttpRequest ) ) . AndReturn ( self . secgroup_backend ) <EOL> api . network . security_group_rule_create ( <EOL> IsA ( http . HttpRequest ) , <EOL> sec_group . id , '<STR_LIT>' , '<STR_LIT>' , <EOL> rule . ip_protocol , <EOL> int ( rule . from_port ) , <EOL> int ( rule . to_port ) , <EOL> rule . ip_range [ '<STR_LIT>' ] , <EOL> None ) . AndRaise ( self . exceptions . nova ) <EOL> api . network . security_group_list ( <EOL> IsA ( http . HttpRequest ) ) . AndReturn ( sec_group_list ) <EOL> self . mox . ReplayAll ( ) <EOL> formData = { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:id>' : sec_group . id , <EOL> '<STR_LIT>' : '<STR_LIT:port>' , <EOL> '<STR_LIT:port>' : rule . from_port , <EOL> '<STR_LIT>' : rule . ip_protocol , <EOL> '<STR_LIT>' : rule . ip_range [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : '<STR_LIT>' } <EOL> res = self . client . post ( self . edit_url , formData ) <EOL> self . assertRedirectsNoFollow ( res , self . detail_url ) <EOL> @ test . create_stubs ( { api . network : ( '<STR_LIT>' , ) } ) <EOL> def test_detail_delete_rule ( self ) : <EOL> sec_group = self . security_groups . first ( ) <EOL> rule = self . security_group_rules . first ( ) <EOL> api . network . security_group_rule_delete ( IsA ( http . HttpRequest ) , rule . id ) <EOL> self . mox . ReplayAll ( ) <EOL> form_data = { "<STR_LIT:action>" : "<STR_LIT>" % rule . id } <EOL> req = self . factory . post ( self . edit_url , form_data ) <EOL> kwargs = { '<STR_LIT>' : sec_group . id } <EOL> table = tables . RulesTable ( req , sec_group . rules , ** kwargs ) <EOL> handled = table . maybe_handle ( ) <EOL> self . assertEqual ( strip_absolute_base ( handled [ '<STR_LIT:location>' ] ) , <EOL> self . detail_url ) <EOL> @ test . create_stubs ( { api . network : ( '<STR_LIT>' , ) } ) <EOL> def test_detail_delete_rule_exception ( self ) : <EOL> sec_group = self . security_groups . first ( ) <EOL> rule = self . security_group_rules . first ( ) <EOL> api . network . security_group_rule_delete ( <EOL> IsA ( http . HttpRequest ) , <EOL> rule . id ) . AndRaise ( self . exceptions . nova ) <EOL> self . mox . ReplayAll ( ) <EOL> form_data = { "<STR_LIT:action>" : "<STR_LIT>" % rule . id } <EOL> req = self . factory . post ( self . edit_url , form_data ) <EOL> kwargs = { '<STR_LIT>' : sec_group . id } <EOL> table = tables . RulesTable ( <EOL> req , self . security_group_rules . list ( ) , ** kwargs ) <EOL> handled = table . maybe_handle ( ) <EOL> self . assertEqual ( strip_absolute_base ( handled [ '<STR_LIT:location>' ] ) , <EOL> self . detail_url ) <EOL> @ test . create_stubs ( { api . network : ( '<STR_LIT>' , ) } ) <EOL> def test_delete_group ( self ) : <EOL> sec_group = self . security_groups . get ( name = "<STR_LIT>" ) <EOL> api . network . security_group_delete ( IsA ( http . HttpRequest ) , sec_group . id ) <EOL> self . mox . ReplayAll ( ) <EOL> form_data = { "<STR_LIT:action>" : "<STR_LIT>" % sec_group . id } <EOL> req = self . factory . post ( INDEX_URL , form_data ) <EOL> table = tables . SecurityGroupsTable ( req , self . security_groups . list ( ) ) <EOL> handled = table . maybe_handle ( ) <EOL> self . assertEqual ( strip_absolute_base ( handled [ '<STR_LIT:location>' ] ) , <EOL> INDEX_URL ) <EOL> @ test . create_stubs ( { api . network : ( '<STR_LIT>' , ) } ) <EOL> def test_delete_group_exception ( self ) : <EOL> sec_group = self . security_groups . get ( name = "<STR_LIT>" ) <EOL> api . network . security_group_delete ( <EOL> IsA ( http . HttpRequest ) , <EOL> sec_group . id ) . AndRaise ( self . exceptions . nova ) <EOL> self . mox . ReplayAll ( ) <EOL> form_data = { "<STR_LIT:action>" : "<STR_LIT>" % sec_group . id } <EOL> req = self . factory . post ( INDEX_URL , form_data ) <EOL> table = tables . SecurityGroupsTable ( req , self . security_groups . list ( ) ) <EOL> handled = table . maybe_handle ( ) <EOL> self . assertEqual ( strip_absolute_base ( handled [ '<STR_LIT:location>' ] ) , <EOL> INDEX_URL ) <EOL> class SecurityGroupsNovaNeutronDriverTests ( SecurityGroupsViewTests ) : <EOL> secgroup_backend = '<STR_LIT>' <EOL> def setUp ( self ) : <EOL> super ( SecurityGroupsNovaNeutronDriverTests , self ) . setUp ( ) <EOL> self . _sec_groups_orig = self . security_groups <EOL> self . security_groups = self . security_groups_uuid <EOL> self . _sec_group_rules_orig = self . security_group_rules <EOL> self . security_group_rules = self . security_group_rules_uuid <EOL> sec_group = self . security_groups . first ( ) <EOL> self . detail_url = reverse ( '<STR_LIT>' <EOL> '<STR_LIT>' , <EOL> args = [ sec_group . id ] ) <EOL> self . edit_url = reverse ( '<STR_LIT>' <EOL> '<STR_LIT>' , <EOL> args = [ sec_group . id ] ) <EOL> def tearDown ( self ) : <EOL> self . security_groups = self . _sec_groups_orig <EOL> self . security_group_rules = self . _sec_group_rules_orig <EOL> super ( SecurityGroupsNovaNeutronDriverTests , self ) . tearDown ( ) <EOL> class SecurityGroupsNeutronTests ( SecurityGroupsViewTests ) : <EOL> secgroup_backend = '<STR_LIT>' <EOL> def setUp ( self ) : <EOL> super ( SecurityGroupsNeutronTests , self ) . setUp ( ) <EOL> self . _sec_groups_orig = self . security_groups <EOL> self . security_groups = self . q_secgroups <EOL> self . _sec_group_rules_orig = self . security_group_rules <EOL> self . security_group_rules = self . q_secgroup_rules <EOL> sec_group = self . security_groups . first ( ) <EOL> self . detail_url = reverse ( '<STR_LIT>' <EOL> '<STR_LIT>' , <EOL> args = [ sec_group . id ] ) <EOL> self . edit_url = reverse ( '<STR_LIT>' <EOL> '<STR_LIT>' , <EOL> args = [ sec_group . id ] ) <EOL> def tearDown ( self ) : <EOL> self . security_groups = self . _sec_groups_orig <EOL> self . security_group_rules = self . _sec_group_rules_orig <EOL> super ( SecurityGroupsNeutronTests , self ) . tearDown ( ) <EOL> def _get_source_group_rule ( self ) : <EOL> for rule in self . security_group_rules . list ( ) : <EOL> if rule . group : <EOL> return rule <EOL> raise Exception ( "<STR_LIT>" ) <EOL> @ test . create_stubs ( { api . network : ( '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ) } ) <EOL> def test_detail_add_rule_custom_protocol ( self ) : <EOL> sec_group = self . security_groups . first ( ) <EOL> sec_group_list = self . security_groups . list ( ) <EOL> rule = self . security_group_rules . first ( ) <EOL> api . network . security_group_backend ( <EOL> IsA ( http . HttpRequest ) ) . AndReturn ( self . secgroup_backend ) <EOL> api . network . security_group_rule_create ( IsA ( http . HttpRequest ) , <EOL> sec_group . id , '<STR_LIT>' , '<STR_LIT>' , <EOL> <NUM_LIT> , None , None , '<STR_LIT>' , <EOL> None ) . AndReturn ( rule ) <EOL> api . network . security_group_list ( <EOL> IsA ( http . HttpRequest ) ) . AndReturn ( sec_group_list ) <EOL> self . mox . ReplayAll ( ) <EOL> formData = { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:id>' : sec_group . id , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:port>' , <EOL> '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' } <EOL> res = self . client . post ( self . edit_url , formData ) <EOL> self . assertRedirectsNoFollow ( res , self . detail_url ) <EOL> @ test . create_stubs ( { api . network : ( '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ) } ) <EOL> def test_detail_add_rule_egress ( self ) : <EOL> sec_group = self . security_groups . first ( ) <EOL> sec_group_list = self . security_groups . list ( ) <EOL> rule = self . security_group_rules . first ( ) <EOL> api . network . security_group_backend ( <EOL> IsA ( http . HttpRequest ) ) . AndReturn ( self . secgroup_backend ) <EOL> api . network . security_group_rule_create ( IsA ( http . HttpRequest ) , <EOL> sec_group . id , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , <NUM_LIT> , <NUM_LIT> , '<STR_LIT>' , <EOL> None ) . AndReturn ( rule ) <EOL> api . network . security_group_list ( <EOL> IsA ( http . HttpRequest ) ) . AndReturn ( sec_group_list ) <EOL> self . mox . ReplayAll ( ) <EOL> formData = { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:id>' : sec_group . id , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:port>' , <EOL> '<STR_LIT:port>' : <NUM_LIT> , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' } <EOL> res = self . client . post ( self . edit_url , formData ) <EOL> self . assertRedirectsNoFollow ( res , self . detail_url ) <EOL> @ test . create_stubs ( { api . network : ( '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ) } ) <EOL> def test_detail_add_rule_egress_with_all_tcp ( self ) : <EOL> sec_group = self . security_groups . first ( ) <EOL> sec_group_list = self . security_groups . list ( ) <EOL> rule = self . security_group_rules . list ( ) [ <NUM_LIT:3> ] <EOL> api . network . security_group_backend ( <EOL> IsA ( http . HttpRequest ) ) . AndReturn ( self . secgroup_backend ) <EOL> api . network . security_group_rule_create ( IsA ( http . HttpRequest ) , <EOL> sec_group . id , '<STR_LIT>' , '<STR_LIT>' , <EOL> rule . ip_protocol , <EOL> int ( rule . from_port ) , <EOL> int ( rule . to_port ) , <EOL> rule . ip_range [ '<STR_LIT>' ] , <EOL> None ) . AndReturn ( rule ) <EOL> api . network . security_group_list ( <EOL> IsA ( http . HttpRequest ) ) . AndReturn ( sec_group_list ) <EOL> self . mox . ReplayAll ( ) <EOL> formData = { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:id>' : sec_group . id , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : rule . ip_range [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : '<STR_LIT>' } <EOL> res = self . client . post ( self . edit_url , formData ) <EOL> self . assertRedirectsNoFollow ( res , self . detail_url ) <EOL> @ test . create_stubs ( { api . network : ( '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ) } ) <EOL> def test_detail_add_rule_source_group_with_direction_ethertype ( self ) : <EOL> sec_group = self . security_groups . first ( ) <EOL> sec_group_list = self . security_groups . list ( ) <EOL> rule = self . _get_source_group_rule ( ) <EOL> api . network . security_group_backend ( <EOL> IsA ( http . HttpRequest ) ) . AndReturn ( self . secgroup_backend ) <EOL> api . network . security_group_rule_create ( <EOL> IsA ( http . HttpRequest ) , <EOL> sec_group . id , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> rule . ip_protocol , <EOL> int ( rule . from_port ) , <EOL> int ( rule . to_port ) , <EOL> None , <EOL> u'<STR_LIT:%s>' % sec_group . id ) . AndReturn ( rule ) <EOL> api . network . security_group_list ( <EOL> IsA ( http . HttpRequest ) ) . AndReturn ( sec_group_list ) <EOL> self . mox . ReplayAll ( ) <EOL> formData = { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:id>' : sec_group . id , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:port>' , <EOL> '<STR_LIT:port>' : rule . from_port , <EOL> '<STR_LIT>' : rule . ip_protocol , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : sec_group . id , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' } <EOL> res = self . client . post ( self . edit_url , formData ) <EOL> self . assertRedirectsNoFollow ( res , self . detail_url ) </s>
