<s> import json <EOL> import re <EOL> from django . conf import settings <EOL> from django . core import exceptions <EOL> from django . core . urlresolvers import reverse <EOL> from django import http <EOL> from django . test . utils import override_settings <EOL> from django . utils import html <EOL> from mox3 . mox import IsA <EOL> import six <EOL> from heatclient . common import template_format as hc_format <EOL> from openstack_dashboard import api <EOL> from openstack_dashboard . test import helpers as test <EOL> from openstack_dashboard . dashboards . project . stacks import forms <EOL> from openstack_dashboard . dashboards . project . stacks import mappings <EOL> from openstack_dashboard . dashboards . project . stacks import tables <EOL> INDEX_URL = reverse ( '<STR_LIT>' ) <EOL> DETAIL_URL = '<STR_LIT>' <EOL> class MockResource ( object ) : <EOL> def __init__ ( self , resource_type , physical_resource_id ) : <EOL> self . resource_type = resource_type <EOL> self . physical_resource_id = physical_resource_id <EOL> class MappingsTests ( test . TestCase ) : <EOL> def test_mappings ( self ) : <EOL> def assertMappingUrl ( url , resource_type , physical_resource_id ) : <EOL> mock = MockResource ( resource_type , physical_resource_id ) <EOL> mock_url = mappings . resource_to_url ( mock ) <EOL> self . assertEqual ( url , mock_url ) <EOL> assertMappingUrl ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ) <EOL> assertMappingUrl ( <EOL> None , <EOL> '<STR_LIT>' , <EOL> None ) <EOL> assertMappingUrl ( <EOL> None , <EOL> None , <EOL> None ) <EOL> assertMappingUrl ( <EOL> None , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ) <EOL> assertMappingUrl ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ) <EOL> assertMappingUrl ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ) <EOL> assertMappingUrl ( <EOL> None , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ) <EOL> assertMappingUrl ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ) <EOL> assertMappingUrl ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ) <EOL> def test_stack_output ( self ) : <EOL> self . assertEqual ( u'<STR_LIT>' , mappings . stack_output ( '<STR_LIT:foo>' ) ) <EOL> self . assertEqual ( u'<STR_LIT>' , mappings . stack_output ( None ) ) <EOL> outputs = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> if six . PY3 : <EOL> expected_text = """<STR_LIT>""" <EOL> else : <EOL> expected_text = """<STR_LIT>""" <EOL> self . assertEqual ( u'<STR_LIT>' % html . escape ( expected_text ) , <EOL> mappings . stack_output ( outputs ) ) <EOL> outputs = { '<STR_LIT:foo>' : '<STR_LIT:bar>' } <EOL> expected_text = """<STR_LIT>""" <EOL> self . assertEqual ( u'<STR_LIT>' % html . escape ( expected_text ) , <EOL> mappings . stack_output ( outputs ) ) <EOL> self . assertEqual ( <EOL> u'<STR_LIT>' <EOL> '<STR_LIT>' , <EOL> mappings . stack_output ( '<STR_LIT>' ) ) <EOL> class StackTests ( test . TestCase ) : <EOL> @ override_settings ( API_RESULT_PAGE_SIZE = <NUM_LIT:2> ) <EOL> @ test . create_stubs ( { api . heat : ( '<STR_LIT>' , ) } ) <EOL> def test_index_paginated ( self ) : <EOL> stacks = self . stacks . list ( ) [ : <NUM_LIT:5> ] <EOL> api . heat . stacks_list ( IsA ( http . HttpRequest ) , <EOL> marker = None , <EOL> paginate = True , <EOL> sort_dir = '<STR_LIT>' ) . AndReturn ( [ stacks , True , True ] ) <EOL> api . heat . stacks_list ( IsA ( http . HttpRequest ) , <EOL> marker = None , <EOL> paginate = True , <EOL> sort_dir = '<STR_LIT>' ) . AndReturn ( [ stacks [ : <NUM_LIT:2> ] , True , True ] ) <EOL> api . heat . stacks_list ( IsA ( http . HttpRequest ) , <EOL> marker = stacks [ <NUM_LIT:2> ] . id , <EOL> paginate = True , <EOL> sort_dir = '<STR_LIT>' ) . AndReturn ( [ stacks [ <NUM_LIT:2> : <NUM_LIT:4> ] , True , True ] ) <EOL> api . heat . stacks_list ( IsA ( http . HttpRequest ) , <EOL> marker = stacks [ <NUM_LIT:4> ] . id , <EOL> paginate = True , <EOL> sort_dir = '<STR_LIT>' ) . AndReturn ( [ stacks [ <NUM_LIT:4> : ] , True , True ] ) <EOL> self . mox . ReplayAll ( ) <EOL> url = reverse ( '<STR_LIT>' ) <EOL> res = self . client . get ( url ) <EOL> self . assertEqual ( len ( res . context [ '<STR_LIT>' ] . data ) , <EOL> len ( stacks ) ) <EOL> self . assertTemplateUsed ( res , '<STR_LIT>' ) <EOL> res = self . client . get ( url ) <EOL> self . assertEqual ( len ( res . context [ '<STR_LIT>' ] . data ) , <EOL> settings . API_RESULT_PAGE_SIZE ) <EOL> url = "<STR_LIT>" % ( reverse ( '<STR_LIT>' ) , <EOL> tables . StacksTable . _meta . pagination_param , <EOL> stacks [ <NUM_LIT:2> ] . id ) <EOL> res = self . client . get ( url ) <EOL> self . assertEqual ( len ( res . context [ '<STR_LIT>' ] . data ) , <EOL> settings . API_RESULT_PAGE_SIZE ) <EOL> url = "<STR_LIT>" % ( reverse ( '<STR_LIT>' ) , <EOL> tables . StacksTable . _meta . pagination_param , <EOL> stacks [ <NUM_LIT:4> ] . id ) <EOL> res = self . client . get ( url ) <EOL> self . assertEqual ( len ( res . context [ '<STR_LIT>' ] . data ) , <EOL> <NUM_LIT:1> ) <EOL> @ override_settings ( API_RESULT_PAGE_SIZE = <NUM_LIT:2> ) <EOL> @ test . create_stubs ( { api . heat : ( '<STR_LIT>' , ) } ) <EOL> def test_index_prev_paginated ( self ) : <EOL> stacks = self . stacks . list ( ) [ : <NUM_LIT:3> ] <EOL> api . heat . stacks_list ( IsA ( http . HttpRequest ) , <EOL> marker = None , <EOL> paginate = True , <EOL> sort_dir = '<STR_LIT>' ) . AndReturn ( [ stacks , True , False ] ) <EOL> api . heat . stacks_list ( IsA ( http . HttpRequest ) , <EOL> marker = None , <EOL> paginate = True , <EOL> sort_dir = '<STR_LIT>' ) . AndReturn ( [ stacks [ : <NUM_LIT:2> ] , True , True ] ) <EOL> api . heat . stacks_list ( IsA ( http . HttpRequest ) , <EOL> marker = stacks [ <NUM_LIT:2> ] . id , <EOL> paginate = True , <EOL> sort_dir = '<STR_LIT>' ) . AndReturn ( [ stacks [ <NUM_LIT:2> : ] , True , True ] ) <EOL> api . heat . stacks_list ( IsA ( http . HttpRequest ) , <EOL> marker = stacks [ <NUM_LIT:2> ] . id , <EOL> paginate = True , <EOL> sort_dir = '<STR_LIT>' ) . AndReturn ( [ stacks [ : <NUM_LIT:2> ] , True , True ] ) <EOL> self . mox . ReplayAll ( ) <EOL> url = reverse ( '<STR_LIT>' ) <EOL> res = self . client . get ( url ) <EOL> self . assertEqual ( len ( res . context [ '<STR_LIT>' ] . data ) , <EOL> len ( stacks ) ) <EOL> self . assertTemplateUsed ( res , '<STR_LIT>' ) <EOL> res = self . client . get ( url ) <EOL> self . assertEqual ( len ( res . context [ '<STR_LIT>' ] . data ) , <EOL> settings . API_RESULT_PAGE_SIZE ) <EOL> url = "<STR_LIT>" % ( reverse ( '<STR_LIT>' ) , <EOL> tables . StacksTable . _meta . pagination_param , <EOL> stacks [ <NUM_LIT:2> ] . id ) <EOL> res = self . client . get ( url ) <EOL> self . assertEqual ( len ( res . context [ '<STR_LIT>' ] . data ) , <NUM_LIT:1> ) <EOL> url = "<STR_LIT>" % ( reverse ( '<STR_LIT>' ) , <EOL> tables . StacksTable . _meta . prev_pagination_param , <EOL> stacks [ <NUM_LIT:2> ] . id ) <EOL> res = self . client . get ( url ) <EOL> self . assertEqual ( len ( res . context [ '<STR_LIT>' ] . data ) , <EOL> settings . API_RESULT_PAGE_SIZE ) <EOL> @ test . create_stubs ( { api . heat : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> api . neutron : ( '<STR_LIT>' , ) } ) <EOL> def test_launch_stack ( self ) : <EOL> template = self . stack_templates . first ( ) <EOL> stack = self . stacks . first ( ) <EOL> api . heat . template_validate ( IsA ( http . HttpRequest ) , <EOL> files = { } , <EOL> template = hc_format . parse ( template . data ) ) . AndReturn ( json . loads ( template . validate ) ) <EOL> api . heat . stack_create ( IsA ( http . HttpRequest ) , <EOL> stack_name = stack . stack_name , <EOL> timeout_mins = <NUM_LIT> , <EOL> disable_rollback = True , <EOL> template = None , <EOL> parameters = IsA ( dict ) , <EOL> password = '<STR_LIT:password>' , <EOL> files = None ) <EOL> api . neutron . network_list_for_tenant ( IsA ( http . HttpRequest ) , <EOL> self . tenant . id ) . AndReturn ( self . networks . list ( ) ) <EOL> api . neutron . network_list_for_tenant ( IsA ( http . HttpRequest ) , <EOL> self . tenant . id ) . AndReturn ( self . networks . list ( ) ) <EOL> self . mox . ReplayAll ( ) <EOL> url = reverse ( '<STR_LIT>' ) <EOL> res = self . client . get ( url ) <EOL> self . assertTemplateUsed ( res , '<STR_LIT>' ) <EOL> form_data = { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : template . data , <EOL> '<STR_LIT>' : forms . TemplateForm . __name__ } <EOL> res = self . client . post ( url , form_data ) <EOL> self . assertTemplateUsed ( res , '<STR_LIT>' ) <EOL> url = reverse ( '<STR_LIT>' ) <EOL> form_data = { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : template . data , <EOL> '<STR_LIT:password>' : '<STR_LIT:password>' , <EOL> '<STR_LIT>' : template . validate , <EOL> '<STR_LIT>' : stack . stack_name , <EOL> "<STR_LIT>" : <NUM_LIT> , <EOL> "<STR_LIT>" : True , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT:test>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : self . networks . list ( ) [ <NUM_LIT:0> ] [ '<STR_LIT:id>' ] , <EOL> '<STR_LIT>' : forms . CreateStackForm . __name__ } <EOL> res = self . client . post ( url , form_data ) <EOL> self . assertRedirectsNoFollow ( res , INDEX_URL ) <EOL> @ test . create_stubs ( { api . heat : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> api . neutron : ( '<STR_LIT>' , ) } ) <EOL> def test_launch_stack_with_environment ( self ) : <EOL> template = self . stack_templates . first ( ) <EOL> environment = self . stack_environments . first ( ) <EOL> stack = self . stacks . first ( ) <EOL> api . heat . template_validate ( IsA ( http . HttpRequest ) , <EOL> files = { } , <EOL> template = hc_format . parse ( template . data ) , <EOL> environment = environment . data ) . AndReturn ( json . loads ( template . validate ) ) <EOL> api . heat . stack_create ( IsA ( http . HttpRequest ) , <EOL> stack_name = stack . stack_name , <EOL> timeout_mins = <NUM_LIT> , <EOL> disable_rollback = True , <EOL> template = None , <EOL> environment = environment . data , <EOL> parameters = IsA ( dict ) , <EOL> password = '<STR_LIT:password>' , <EOL> files = None ) <EOL> api . neutron . network_list_for_tenant ( IsA ( http . HttpRequest ) , <EOL> self . tenant . id ) . AndReturn ( self . networks . list ( ) ) <EOL> api . neutron . network_list_for_tenant ( IsA ( http . HttpRequest ) , <EOL> self . tenant . id ) . AndReturn ( self . networks . list ( ) ) <EOL> self . mox . ReplayAll ( ) <EOL> url = reverse ( '<STR_LIT>' ) <EOL> res = self . client . get ( url ) <EOL> self . assertTemplateUsed ( res , '<STR_LIT>' ) <EOL> form_data = { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : template . data , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : environment . data , <EOL> '<STR_LIT>' : forms . TemplateForm . __name__ } <EOL> res = self . client . post ( url , form_data ) <EOL> self . assertTemplateUsed ( res , '<STR_LIT>' ) <EOL> url = reverse ( '<STR_LIT>' ) <EOL> form_data = { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : template . data , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : environment . data , <EOL> '<STR_LIT:password>' : '<STR_LIT:password>' , <EOL> '<STR_LIT>' : template . validate , <EOL> '<STR_LIT>' : stack . stack_name , <EOL> "<STR_LIT>" : <NUM_LIT> , <EOL> "<STR_LIT>" : True , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT:test>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : self . networks . list ( ) [ <NUM_LIT:0> ] [ '<STR_LIT:id>' ] , <EOL> '<STR_LIT>' : forms . CreateStackForm . __name__ } <EOL> res = self . client . post ( url , form_data ) <EOL> self . assertRedirectsNoFollow ( res , INDEX_URL ) <EOL> @ test . create_stubs ( { api . heat : ( '<STR_LIT>' , ) } ) <EOL> def test_launch_stack_with_hidden_parameters ( self ) : <EOL> template = { <EOL> '<STR_LIT:data>' : ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:false>' <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:true>' <EOL> } <EOL> } <EOL> } <EOL> } <EOL> api . heat . template_validate ( IsA ( http . HttpRequest ) , <EOL> files = { } , <EOL> template = hc_format . parse ( template [ '<STR_LIT:data>' ] ) ) . AndReturn ( template [ '<STR_LIT>' ] ) <EOL> self . mox . ReplayAll ( ) <EOL> url = reverse ( '<STR_LIT>' ) <EOL> res = self . client . get ( url ) <EOL> self . assertTemplateUsed ( res , '<STR_LIT>' ) <EOL> form_data = { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : template [ '<STR_LIT:data>' ] , <EOL> '<STR_LIT>' : forms . TemplateForm . __name__ } <EOL> res = self . client . post ( url , form_data ) <EOL> self . assertTemplateUsed ( res , '<STR_LIT>' ) <EOL> self . assertContains ( res , <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' , html = True ) <EOL> self . assertContains ( res , <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' , html = True ) <EOL> @ test . create_stubs ( { api . heat : ( '<STR_LIT>' , ) } ) <EOL> def test_launch_stack_with_parameter_group ( self ) : <EOL> template = { <EOL> '<STR_LIT:data>' : ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:false>' <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:false>' <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:true>' <EOL> } <EOL> } , <EOL> '<STR_LIT>' : [ <EOL> { <EOL> '<STR_LIT>' : [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> ] <EOL> } <EOL> ] <EOL> } <EOL> } <EOL> api . heat . template_validate ( IsA ( http . HttpRequest ) , <EOL> files = { } , <EOL> template = hc_format . parse ( template [ '<STR_LIT:data>' ] ) ) . AndReturn ( template [ '<STR_LIT>' ] ) <EOL> self . mox . ReplayAll ( ) <EOL> url = reverse ( '<STR_LIT>' ) <EOL> res = self . client . get ( url ) <EOL> self . assertTemplateUsed ( res , '<STR_LIT>' ) <EOL> form_data = { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : template [ '<STR_LIT:data>' ] , <EOL> '<STR_LIT>' : forms . TemplateForm . __name__ } <EOL> res = self . client . post ( url , form_data ) <EOL> self . assertTemplateUsed ( res , '<STR_LIT>' ) <EOL> regex = re . compile ( '<STR_LIT>' , <EOL> flags = re . DOTALL ) <EOL> self . assertRegexpMatches ( res . content . decode ( '<STR_LIT:utf-8>' ) , regex ) <EOL> @ test . create_stubs ( { api . heat : ( '<STR_LIT>' , '<STR_LIT>' ) } ) <EOL> def test_launch_stack_parameter_types ( self ) : <EOL> template = { <EOL> '<STR_LIT:data>' : ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) , <EOL> '<STR_LIT>' : { <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT:false>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" <EOL> } , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT:false>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" <EOL> } , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT:false>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" <EOL> } , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT:false>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" <EOL> } , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT:false>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" <EOL> } <EOL> } <EOL> } <EOL> } <EOL> stack = self . stacks . first ( ) <EOL> api . heat . template_validate ( IsA ( http . HttpRequest ) , <EOL> files = { } , <EOL> template = hc_format . parse ( template [ '<STR_LIT:data>' ] ) ) . AndReturn ( template [ '<STR_LIT>' ] ) <EOL> api . heat . stack_create ( IsA ( http . HttpRequest ) , <EOL> stack_name = stack . stack_name , <EOL> timeout_mins = <NUM_LIT> , <EOL> disable_rollback = True , <EOL> template = hc_format . parse ( template [ '<STR_LIT:data>' ] ) , <EOL> parameters = { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : True } , <EOL> password = '<STR_LIT:password>' , <EOL> files = { } ) <EOL> self . mox . ReplayAll ( ) <EOL> url = reverse ( '<STR_LIT>' ) <EOL> res = self . client . get ( url ) <EOL> self . assertTemplateUsed ( res , '<STR_LIT>' ) <EOL> form_data = { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : template [ '<STR_LIT:data>' ] , <EOL> '<STR_LIT>' : forms . TemplateForm . __name__ } <EOL> res = self . client . post ( url , form_data ) <EOL> self . assertTemplateUsed ( res , '<STR_LIT>' ) <EOL> self . assertContains ( res , <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' , html = True ) <EOL> self . assertContains ( res , <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' , html = True ) <EOL> self . assertContains ( res , <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' , html = True ) <EOL> self . assertContains ( res , <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' , html = True ) <EOL> self . assertContains ( res , <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' , html = True ) <EOL> url = reverse ( '<STR_LIT>' ) <EOL> form_data = { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : template [ '<STR_LIT:data>' ] , <EOL> '<STR_LIT:password>' : '<STR_LIT:password>' , <EOL> '<STR_LIT>' : json . dumps ( template [ '<STR_LIT>' ] ) , <EOL> '<STR_LIT>' : stack . stack_name , <EOL> "<STR_LIT>" : <NUM_LIT> , <EOL> "<STR_LIT>" : True , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : <NUM_LIT> , <EOL> "<STR_LIT>" : '<STR_LIT>' , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : True , <EOL> '<STR_LIT>' : forms . CreateStackForm . __name__ } <EOL> res = self . client . post ( url , form_data ) <EOL> self . assertRedirectsNoFollow ( res , INDEX_URL ) <EOL> @ test . create_stubs ( { api . heat : ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' ) , <EOL> api . neutron : ( '<STR_LIT>' , ) } ) <EOL> def test_edit_stack_template ( self ) : <EOL> template = self . stack_templates . first ( ) <EOL> stack = self . stacks . first ( ) <EOL> api . heat . stack_get ( IsA ( http . HttpRequest ) , <EOL> stack . id ) . AndReturn ( stack ) <EOL> api . heat . template_validate ( IsA ( http . HttpRequest ) , <EOL> files = { } , <EOL> template = hc_format . parse ( template . data ) ) . AndReturn ( json . loads ( template . validate ) ) <EOL> api . heat . stack_get ( IsA ( http . HttpRequest ) , <EOL> stack . id ) . AndReturn ( stack ) <EOL> api . heat . template_get ( IsA ( http . HttpRequest ) , <EOL> stack . id ) . AndReturn ( json . loads ( template . validate ) ) <EOL> api . heat . stack_get ( IsA ( http . HttpRequest ) , <EOL> stack . id ) . AndReturn ( stack ) <EOL> fields = { <EOL> '<STR_LIT>' : stack . stack_name , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT:password>' : '<STR_LIT:password>' , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : IsA ( dict ) , <EOL> '<STR_LIT>' : None <EOL> } <EOL> api . heat . stack_update ( IsA ( http . HttpRequest ) , <EOL> stack_id = stack . id , <EOL> ** fields ) <EOL> api . neutron . network_list_for_tenant ( IsA ( http . HttpRequest ) , <EOL> self . tenant . id ) . AndReturn ( self . networks . list ( ) ) <EOL> self . mox . ReplayAll ( ) <EOL> url = reverse ( '<STR_LIT>' , <EOL> args = [ stack . id ] ) <EOL> res = self . client . get ( url ) <EOL> self . assertTemplateUsed ( res , '<STR_LIT>' ) <EOL> form_data = { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : template . data , <EOL> '<STR_LIT>' : forms . ChangeTemplateForm . __name__ } <EOL> res = self . client . post ( url , form_data ) <EOL> url = reverse ( '<STR_LIT>' , <EOL> args = [ stack . id , ] ) <EOL> form_data = { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : template . data , <EOL> '<STR_LIT:password>' : '<STR_LIT:password>' , <EOL> '<STR_LIT>' : template . validate , <EOL> '<STR_LIT>' : stack . stack_name , <EOL> '<STR_LIT>' : stack . id , <EOL> "<STR_LIT>" : <NUM_LIT> , <EOL> "<STR_LIT>" : True , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT:test>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : self . networks . list ( ) [ <NUM_LIT:0> ] [ '<STR_LIT:id>' ] , <EOL> '<STR_LIT>' : forms . EditStackForm . __name__ } <EOL> res = self . client . post ( url , form_data ) <EOL> self . assertRedirectsNoFollow ( res , INDEX_URL ) <EOL> def test_launch_stack_form_invalid_name_digit ( self ) : <EOL> self . _test_launch_stack_invalid_name ( '<STR_LIT>' ) <EOL> def test_launch_stack_form_invalid_name_underscore ( self ) : <EOL> self . _test_launch_stack_invalid_name ( '<STR_LIT>' ) <EOL> def test_launch_stack_form_invalid_name_point ( self ) : <EOL> self . _test_launch_stack_invalid_name ( '<STR_LIT>' ) <EOL> @ test . create_stubs ( { api . neutron : ( '<STR_LIT>' , ) } ) <EOL> def _test_launch_stack_invalid_name ( self , name ) : <EOL> api . neutron . network_list_for_tenant ( IsA ( http . HttpRequest ) , <EOL> self . tenant . id ) . AndReturn ( self . networks . list ( ) ) <EOL> self . mox . ReplayAll ( ) <EOL> template = self . stack_templates . first ( ) <EOL> url = reverse ( '<STR_LIT>' ) <EOL> form_data = { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : template . data , <EOL> '<STR_LIT:password>' : '<STR_LIT:password>' , <EOL> '<STR_LIT>' : template . validate , <EOL> '<STR_LIT>' : name , <EOL> "<STR_LIT>" : <NUM_LIT> , <EOL> "<STR_LIT>" : True , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT:test>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : self . networks . list ( ) [ <NUM_LIT:0> ] [ '<STR_LIT:id>' ] , <EOL> '<STR_LIT>' : forms . CreateStackForm . __name__ } <EOL> res = self . client . post ( url , form_data ) <EOL> error = ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> self . assertFormErrors ( res , <NUM_LIT:1> ) <EOL> self . assertFormError ( res , "<STR_LIT>" , '<STR_LIT>' , error ) <EOL> def _test_stack_action ( self , action ) : <EOL> stack = self . stacks . first ( ) <EOL> api . heat . stacks_list ( IsA ( http . HttpRequest ) , <EOL> marker = None , <EOL> paginate = True , <EOL> sort_dir = '<STR_LIT>' ) . AndReturn ( [ self . stacks . list ( ) , True , True ] ) <EOL> getattr ( api . heat , '<STR_LIT>' % action ) ( IsA ( http . HttpRequest ) , <EOL> stack . id ) . AndReturn ( stack ) <EOL> self . mox . ReplayAll ( ) <EOL> form_data = { "<STR_LIT:action>" : "<STR_LIT>" % ( action , stack . id ) } <EOL> res = self . client . post ( INDEX_URL , form_data ) <EOL> self . assertNoFormErrors ( res ) <EOL> self . assertRedirectsNoFollow ( res , INDEX_URL ) <EOL> @ test . create_stubs ( { api . heat : ( '<STR_LIT>' , '<STR_LIT>' , ) } ) <EOL> def test_check_stack ( self ) : <EOL> self . _test_stack_action ( '<STR_LIT>' ) <EOL> @ test . create_stubs ( { api . heat : ( '<STR_LIT>' , '<STR_LIT>' , ) } ) <EOL> def test_suspend_stack ( self ) : <EOL> self . _test_stack_action ( '<STR_LIT>' ) <EOL> @ test . create_stubs ( { api . heat : ( '<STR_LIT>' , '<STR_LIT>' , ) } ) <EOL> def test_resume_stack ( self ) : <EOL> self . _test_stack_action ( '<STR_LIT>' ) <EOL> @ test . create_stubs ( { api . heat : ( '<STR_LIT>' , '<STR_LIT>' ) } ) <EOL> def test_preview_stack ( self ) : <EOL> template = self . stack_templates . first ( ) <EOL> stack = self . stacks . first ( ) <EOL> api . heat . template_validate ( IsA ( http . HttpRequest ) , <EOL> files = { } , <EOL> template = hc_format . parse ( template . data ) ) . AndReturn ( json . loads ( template . validate ) ) <EOL> api . heat . stack_preview ( IsA ( http . HttpRequest ) , <EOL> stack_name = stack . stack_name , <EOL> timeout_mins = <NUM_LIT> , <EOL> disable_rollback = True , <EOL> template = None , <EOL> parameters = IsA ( dict ) , <EOL> files = None ) . AndReturn ( stack ) <EOL> self . mox . ReplayAll ( ) <EOL> url = reverse ( '<STR_LIT>' ) <EOL> res = self . client . get ( url ) <EOL> self . assertTemplateUsed ( res , '<STR_LIT>' ) <EOL> form_data = { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : template . data , <EOL> '<STR_LIT>' : forms . PreviewTemplateForm . __name__ } <EOL> res = self . client . post ( url , form_data ) <EOL> self . assertTemplateUsed ( res , '<STR_LIT>' ) <EOL> url = reverse ( '<STR_LIT>' ) <EOL> form_data = { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : template . data , <EOL> '<STR_LIT>' : template . validate , <EOL> '<STR_LIT>' : stack . stack_name , <EOL> "<STR_LIT>" : <NUM_LIT> , <EOL> "<STR_LIT>" : True , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT:test>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> '<STR_LIT>' : forms . PreviewStackForm . __name__ } <EOL> res = self . client . post ( url , form_data ) <EOL> self . assertTemplateUsed ( res , '<STR_LIT>' ) <EOL> self . assertEqual ( res . context [ '<STR_LIT>' ] [ '<STR_LIT>' ] , <EOL> stack . stack_name ) <EOL> @ test . create_stubs ( { api . heat : ( '<STR_LIT>' , '<STR_LIT>' ) } ) <EOL> def test_detail_stack_topology ( self ) : <EOL> stack = self . stacks . first ( ) <EOL> template = self . stack_templates . first ( ) <EOL> api . heat . stack_get ( IsA ( http . HttpRequest ) , stack . id ) . MultipleTimes ( ) . AndReturn ( stack ) <EOL> api . heat . template_get ( IsA ( http . HttpRequest ) , stack . id ) . AndReturn ( json . loads ( template . validate ) ) <EOL> self . mox . ReplayAll ( ) <EOL> url = '<STR_LIT:?>' . join ( [ reverse ( DETAIL_URL , args = [ stack . id ] ) , <EOL> '<STR_LIT:=>' . join ( [ '<STR_LIT>' , '<STR_LIT>' ] ) ] ) <EOL> res = self . client . get ( url ) <EOL> tab = res . context [ '<STR_LIT>' ] . get_tab ( '<STR_LIT>' ) <EOL> d3_data = tab . data [ '<STR_LIT>' ] <EOL> self . assertEqual ( tab . template_name , <EOL> '<STR_LIT>' ) <EOL> self . assertIn ( '<STR_LIT>' , d3_data ) <EOL> self . assertIn ( '<STR_LIT>' , d3_data ) <EOL> self . assertIn ( '<STR_LIT>' , d3_data ) <EOL> @ test . create_stubs ( { api . heat : ( '<STR_LIT>' , '<STR_LIT>' ) } ) <EOL> def test_detail_stack_overview ( self ) : <EOL> stack = self . stacks . first ( ) <EOL> template = self . stack_templates . first ( ) <EOL> api . heat . stack_get ( IsA ( http . HttpRequest ) , stack . id ) . MultipleTimes ( ) . AndReturn ( stack ) <EOL> api . heat . template_get ( IsA ( http . HttpRequest ) , stack . id ) . AndReturn ( json . loads ( template . validate ) ) <EOL> self . mox . ReplayAll ( ) <EOL> url = '<STR_LIT:?>' . join ( [ reverse ( DETAIL_URL , args = [ stack . id ] ) , <EOL> '<STR_LIT:=>' . join ( [ '<STR_LIT>' , '<STR_LIT>' ] ) ] ) <EOL> res = self . client . get ( url ) <EOL> tab = res . context [ '<STR_LIT>' ] . get_tab ( '<STR_LIT>' ) <EOL> overview_data = tab . data [ '<STR_LIT>' ] <EOL> self . assertEqual ( tab . template_name , <EOL> '<STR_LIT>' ) <EOL> self . assertEqual ( stack . stack_name , overview_data . stack_name ) <EOL> @ test . create_stubs ( { api . heat : ( '<STR_LIT>' , '<STR_LIT>' ) } ) <EOL> def test_detail_stack_resources ( self ) : <EOL> stack = self . stacks . first ( ) <EOL> template = self . stack_templates . first ( ) <EOL> api . heat . stack_get ( IsA ( http . HttpRequest ) , stack . id ) . MultipleTimes ( ) . AndReturn ( stack ) <EOL> api . heat . template_get ( IsA ( http . HttpRequest ) , stack . id ) . AndReturn ( json . loads ( template . validate ) ) <EOL> self . mox . ReplayAll ( ) <EOL> url = '<STR_LIT:?>' . join ( [ reverse ( DETAIL_URL , args = [ stack . id ] ) , <EOL> '<STR_LIT:=>' . join ( [ '<STR_LIT>' , '<STR_LIT>' ] ) ] ) <EOL> res = self . client . get ( url ) <EOL> tab = res . context [ '<STR_LIT>' ] . get_tab ( '<STR_LIT>' ) <EOL> self . assertEqual ( tab . template_name , <EOL> '<STR_LIT>' ) <EOL> @ test . create_stubs ( { api . heat : ( '<STR_LIT>' , '<STR_LIT>' ) } ) <EOL> def test_detail_stack_template ( self ) : <EOL> stack = self . stacks . first ( ) <EOL> template = self . stack_templates . first ( ) <EOL> api . heat . stack_get ( IsA ( http . HttpRequest ) , stack . id ) . AndReturn ( stack ) <EOL> api . heat . template_get ( IsA ( http . HttpRequest ) , stack . id ) . AndReturn ( json . loads ( template . validate ) ) <EOL> self . mox . ReplayAll ( ) <EOL> url = '<STR_LIT:?>' . join ( [ reverse ( DETAIL_URL , args = [ stack . id ] ) , <EOL> '<STR_LIT:=>' . join ( [ '<STR_LIT>' , '<STR_LIT>' ] ) ] ) <EOL> res = self . client . get ( url ) <EOL> tab = res . context [ '<STR_LIT>' ] . get_tab ( '<STR_LIT>' ) <EOL> template_data = tab . data [ '<STR_LIT>' ] <EOL> self . assertEqual ( tab . template_name , <EOL> '<STR_LIT>' ) <EOL> self . assertIn ( json . loads ( template . validate ) [ '<STR_LIT>' ] , <EOL> template_data ) <EOL> @ test . create_stubs ( { api . heat : ( '<STR_LIT>' , '<STR_LIT>' ) } ) <EOL> def test_resource_view ( self ) : <EOL> stack = self . stacks . first ( ) <EOL> resource = self . heat_resources . first ( ) <EOL> metadata = { } <EOL> api . heat . resource_get ( <EOL> IsA ( http . HttpRequest ) , stack . id , resource . resource_name ) . AndReturn ( resource ) <EOL> api . heat . resource_metadata_get ( <EOL> IsA ( http . HttpRequest ) , stack . id , resource . resource_name ) . AndReturn ( metadata ) <EOL> self . mox . ReplayAll ( ) <EOL> url = reverse ( '<STR_LIT>' , <EOL> args = [ stack . id , resource . resource_name ] ) <EOL> res = self . client . get ( url ) <EOL> self . assertTemplateUsed ( res , '<STR_LIT>' ) <EOL> self . assertTemplateUsed ( res , '<STR_LIT>' ) <EOL> self . assertEqual ( res . context [ '<STR_LIT>' ] . logical_resource_id , <EOL> resource . logical_resource_id ) <EOL> class TemplateFormTests ( test . TestCase ) : <EOL> class SimpleFile ( object ) : <EOL> def __init__ ( self , name , data ) : <EOL> self . name = name <EOL> self . data = data <EOL> def read ( self ) : <EOL> return self . data <EOL> def test_create_upload_form_attributes ( self ) : <EOL> attrs = forms . create_upload_form_attributes ( <EOL> '<STR_LIT>' , '<STR_LIT:url>' , '<STR_LIT>' ) <EOL> self . assertEqual ( attrs [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> def test_clean_file_upload_form_url ( self ) : <EOL> kwargs = { '<STR_LIT>' : '<STR_LIT>' } <EOL> t = forms . TemplateForm ( { } , ** kwargs ) <EOL> precleaned = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> t . clean_uploaded_files ( '<STR_LIT>' , '<STR_LIT>' , precleaned , { } ) <EOL> self . assertEqual ( precleaned [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> def test_clean_file_upload_form_multiple ( self ) : <EOL> kwargs = { '<STR_LIT>' : '<STR_LIT>' } <EOL> t = forms . TemplateForm ( { } , ** kwargs ) <EOL> precleaned = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> self . assertRaises ( <EOL> exceptions . ValidationError , <EOL> t . clean_uploaded_files , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> precleaned , <EOL> { } ) <EOL> def test_clean_file_upload_form_invalid_json ( self ) : <EOL> kwargs = { '<STR_LIT>' : '<STR_LIT>' } <EOL> t = forms . TemplateForm ( { } , ** kwargs ) <EOL> precleaned = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> json_str = '<STR_LIT>' <EOL> files = { '<STR_LIT>' : <EOL> self . SimpleFile ( '<STR_LIT>' , json_str ) } <EOL> self . assertRaises ( <EOL> exceptions . ValidationError , <EOL> t . clean_uploaded_files , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> precleaned , <EOL> files ) <EOL> def test_clean_file_upload_form_valid_data ( self ) : <EOL> kwargs = { '<STR_LIT>' : '<STR_LIT>' } <EOL> t = forms . TemplateForm ( { } , ** kwargs ) <EOL> precleaned = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> json_str = '<STR_LIT>' <EOL> files = { '<STR_LIT>' : <EOL> self . SimpleFile ( '<STR_LIT>' , json_str ) } <EOL> t . clean_uploaded_files ( '<STR_LIT>' , '<STR_LIT>' , precleaned , files ) <EOL> self . assertEqual ( <EOL> json_str , <EOL> precleaned [ '<STR_LIT>' ] ) </s>
