<s> from toscaparser . common import exception <EOL> from toscaparser . elements . artifacttype import ArtifactTypeDef <EOL> from toscaparser . elements . entity_type import EntityType <EOL> from toscaparser . elements . grouptype import GroupType <EOL> import toscaparser . elements . interfaces as ifaces <EOL> from toscaparser . elements . nodetype import NodeType <EOL> from toscaparser . elements . policytype import PolicyType <EOL> from toscaparser . tests . base import TestCase <EOL> compute_type = NodeType ( '<STR_LIT>' ) <EOL> component_type = NodeType ( '<STR_LIT>' ) <EOL> network_type = NodeType ( '<STR_LIT>' ) <EOL> network_port_type = NodeType ( '<STR_LIT>' ) <EOL> webserver_type = NodeType ( '<STR_LIT>' ) <EOL> database_type = NodeType ( '<STR_LIT>' ) <EOL> artif_root_type = ArtifactTypeDef ( '<STR_LIT>' ) <EOL> artif_file_type = ArtifactTypeDef ( '<STR_LIT>' ) <EOL> artif_bash_type = ArtifactTypeDef ( '<STR_LIT>' ) <EOL> artif_python_type = ArtifactTypeDef ( '<STR_LIT>' ) <EOL> artif_container_docker_type = ArtifactTypeDef ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> artif_vm_iso_type = ArtifactTypeDef ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> artif_vm_qcow2_type = ArtifactTypeDef ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> policy_root_type = PolicyType ( '<STR_LIT>' ) <EOL> policy_placement_type = PolicyType ( '<STR_LIT>' ) <EOL> policy_scaling_type = PolicyType ( '<STR_LIT>' ) <EOL> policy_update_type = PolicyType ( '<STR_LIT>' ) <EOL> policy_performance_type = PolicyType ( '<STR_LIT>' ) <EOL> group_type = GroupType ( '<STR_LIT>' ) <EOL> class ToscaDefTest ( TestCase ) : <EOL> def test_type ( self ) : <EOL> self . assertEqual ( compute_type . type , "<STR_LIT>" ) <EOL> self . assertRaises ( exception . InvalidTypeError , NodeType , <EOL> '<STR_LIT>' ) <EOL> self . assertEqual ( network_type . type , "<STR_LIT>" ) <EOL> self . assertEqual ( network_port_type . type , "<STR_LIT>" ) <EOL> def test_parent_type ( self ) : <EOL> self . assertEqual ( compute_type . parent_type . type , "<STR_LIT>" ) <EOL> self . assertEqual ( network_type . parent_type . type , "<STR_LIT>" ) <EOL> self . assertEqual ( network_port_type . parent_type . type , <EOL> "<STR_LIT>" ) <EOL> def test_group ( self ) : <EOL> self . assertEqual ( group_type . type , "<STR_LIT>" ) <EOL> self . assertIn ( ifaces . LIFECYCLE_SHORTNAME , group_type . interfaces ) <EOL> def test_capabilities ( self ) : <EOL> self . assertEqual ( <EOL> [ '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ] , <EOL> sorted ( [ c . type for c in compute_type . get_capabilities_objects ( ) ] ) ) <EOL> self . assertEqual ( <EOL> [ '<STR_LIT>' , <EOL> '<STR_LIT>' ] , <EOL> sorted ( [ c . type for c in network_type . get_capabilities_objects ( ) ] ) ) <EOL> endpoint_props_def_objects = self . _get_capability_properties_def_objects ( <EOL> webserver_type . get_capabilities_objects ( ) , <EOL> '<STR_LIT>' ) <EOL> self . assertEqual ( <EOL> [ ( '<STR_LIT>' , False ) , ( '<STR_LIT>' , False ) , ( '<STR_LIT:port>' , False ) , <EOL> ( '<STR_LIT>' , False ) , ( '<STR_LIT>' , False ) , ( '<STR_LIT>' , True ) , <EOL> ( '<STR_LIT>' , False ) , ( '<STR_LIT>' , False ) ] , <EOL> sorted ( [ ( p . name , p . required ) for p in endpoint_props_def_objects ] ) ) <EOL> os_props = self . _get_capability_properties_def_objects ( <EOL> compute_type . get_capabilities_objects ( ) , <EOL> '<STR_LIT>' ) <EOL> self . assertEqual ( <EOL> [ ( '<STR_LIT>' , False ) , ( '<STR_LIT>' , False ) , ( '<STR_LIT:type>' , False ) , <EOL> ( '<STR_LIT:version>' , False ) ] , <EOL> sorted ( [ ( p . name , p . required ) for p in os_props ] ) ) <EOL> host_props = self . _get_capability_properties_def_objects ( <EOL> compute_type . get_capabilities_objects ( ) , <EOL> '<STR_LIT>' ) <EOL> self . assertEqual ( <EOL> [ ( '<STR_LIT>' , False ) , ( '<STR_LIT>' , False ) , <EOL> ( '<STR_LIT>' , False ) , ( '<STR_LIT>' , False ) ] , <EOL> sorted ( [ ( p . name , p . required ) for p in host_props ] ) ) <EOL> endpoint_admin_properties = '<STR_LIT>' <EOL> endpoint_admin_props_def_objects = self . _get_capability_properties_def_objects ( <EOL> webserver_type . get_capabilities_objects ( ) , <EOL> '<STR_LIT>' ) <EOL> self . assertIn ( <EOL> endpoint_admin_properties , <EOL> sorted ( [ p . name for p in endpoint_admin_props_def_objects ] ) ) <EOL> def _get_capability_properties_def_objects ( self , caps , type ) : <EOL> properties_def = None <EOL> for cap in caps : <EOL> if cap . type == type : <EOL> properties_def = cap . get_properties_def_objects ( ) <EOL> break <EOL> return properties_def <EOL> def _get_capability_properties_def ( self , caps , type ) : <EOL> properties_def = None <EOL> for cap in caps : <EOL> if cap . type == type : <EOL> properties_def = cap . get_properties_def ( ) <EOL> break <EOL> return properties_def <EOL> def test_properties_def ( self ) : <EOL> self . assertEqual ( <EOL> [ '<STR_LIT:name>' , '<STR_LIT:password>' , '<STR_LIT:port>' , '<STR_LIT:user>' ] , <EOL> sorted ( database_type . get_properties_def ( ) . keys ( ) ) ) <EOL> def test_attributes_def ( self ) : <EOL> self . assertEqual ( <EOL> [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT:state>' , '<STR_LIT>' , '<STR_LIT>' ] , <EOL> sorted ( compute_type . get_attributes_def ( ) . keys ( ) ) ) <EOL> def test_requirements ( self ) : <EOL> self . assertEqual ( <EOL> [ { '<STR_LIT:host>' : { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' } } , <EOL> { '<STR_LIT>' : { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : [ <NUM_LIT:0> , '<STR_LIT>' ] , <EOL> '<STR_LIT>' : '<STR_LIT>' } } <EOL> ] , <EOL> [ r for r in component_type . requirements ] ) <EOL> def test_relationship ( self ) : <EOL> self . assertEqual ( <EOL> [ ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) ] , <EOL> sorted ( [ ( relation . type , node . type ) for <EOL> relation , node in component_type . relationship . items ( ) ] ) ) <EOL> self . assertIn ( <EOL> ( '<STR_LIT>' , [ '<STR_LIT>' ] ) , <EOL> [ ( relation . type , relation . valid_target_types ) for <EOL> relation in list ( component_type . relationship . keys ( ) ) ] ) <EOL> self . assertIn ( <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> [ ( relation . type , node . type ) for <EOL> relation , node in network_port_type . relationship . items ( ) ] ) <EOL> self . assertIn ( <EOL> ( '<STR_LIT>' , <EOL> '<STR_LIT>' ) , <EOL> [ ( relation . type , node . type ) for <EOL> relation , node in network_port_type . relationship . items ( ) ] ) <EOL> def test_interfaces ( self ) : <EOL> self . assertEqual ( compute_type . interfaces , None ) <EOL> root_node = NodeType ( '<STR_LIT>' ) <EOL> self . assertIn ( ifaces . LIFECYCLE_SHORTNAME , root_node . interfaces ) <EOL> def test_artifacts ( self ) : <EOL> self . assertEqual ( '<STR_LIT>' , <EOL> artif_file_type . parent_type ) <EOL> self . assertEqual ( { } , artif_file_type . parent_artifacts ) <EOL> self . assertEqual ( sorted ( [ '<STR_LIT>' ] , <EOL> key = lambda x : str ( x ) ) , <EOL> sorted ( [ artif_file_type . get_artifact ( name ) <EOL> for name in artif_file_type . defs ] , <EOL> key = lambda x : str ( x ) ) ) <EOL> self . assertEqual ( '<STR_LIT>' , <EOL> artif_bash_type . parent_type ) <EOL> self . assertEqual ( { '<STR_LIT>' : <EOL> { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:description>' : <EOL> '<STR_LIT>' } } , <EOL> artif_bash_type . parent_artifacts ) <EOL> self . assertEqual ( sorted ( [ [ '<STR_LIT>' ] , '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ] , key = lambda x : str ( x ) ) , <EOL> sorted ( [ artif_bash_type . get_artifact ( name ) <EOL> for name in artif_bash_type . defs ] , <EOL> key = lambda x : str ( x ) ) ) <EOL> self . assertEqual ( '<STR_LIT>' , <EOL> artif_python_type . parent_type ) <EOL> self . assertEqual ( { '<STR_LIT>' : <EOL> { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:description>' : <EOL> '<STR_LIT>' } } , <EOL> artif_python_type . parent_artifacts ) <EOL> self . assertEqual ( sorted ( [ [ '<STR_LIT>' ] , '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' , '<STR_LIT>' ] , <EOL> key = lambda x : str ( x ) ) , <EOL> sorted ( [ artif_python_type . get_artifact ( name ) <EOL> for name in artif_python_type . defs ] , <EOL> key = lambda x : str ( x ) ) ) <EOL> self . assertEqual ( '<STR_LIT>' , <EOL> artif_container_docker_type . parent_type ) <EOL> self . assertEqual ( { '<STR_LIT>' : <EOL> { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:description>' : <EOL> '<STR_LIT>' } , <EOL> '<STR_LIT>' : <EOL> { '<STR_LIT>' : '<STR_LIT>' } } , <EOL> artif_container_docker_type . parent_artifacts ) <EOL> self . assertEqual ( sorted ( [ '<STR_LIT>' , <EOL> '<STR_LIT>' ] , <EOL> key = lambda x : str ( x ) ) , <EOL> sorted ( [ artif_container_docker_type . <EOL> get_artifact ( name ) for name in <EOL> artif_container_docker_type . defs ] , <EOL> key = lambda x : str ( x ) ) ) <EOL> self . assertEqual ( '<STR_LIT>' , <EOL> artif_vm_iso_type . parent_type ) <EOL> self . assertEqual ( { '<STR_LIT>' : <EOL> { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:description>' : <EOL> '<STR_LIT>' } , <EOL> '<STR_LIT>' : <EOL> { '<STR_LIT>' : '<STR_LIT>' } } , <EOL> artif_vm_iso_type . parent_artifacts ) <EOL> self . assertEqual ( sorted ( [ '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , [ '<STR_LIT>' ] ] , <EOL> key = lambda x : str ( x ) ) , <EOL> sorted ( [ artif_vm_iso_type . <EOL> get_artifact ( name ) for name in <EOL> artif_vm_iso_type . defs ] , <EOL> key = lambda x : str ( x ) ) ) <EOL> self . assertEqual ( '<STR_LIT>' , <EOL> artif_vm_qcow2_type . parent_type ) <EOL> self . assertEqual ( { '<STR_LIT>' : <EOL> { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:description>' : <EOL> '<STR_LIT>' } , <EOL> '<STR_LIT>' : <EOL> { '<STR_LIT>' : '<STR_LIT>' } } , <EOL> artif_vm_qcow2_type . parent_artifacts ) <EOL> self . assertEqual ( sorted ( [ '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , [ '<STR_LIT>' ] ] , <EOL> key = lambda x : str ( x ) ) , <EOL> sorted ( [ artif_vm_qcow2_type . <EOL> get_artifact ( name ) for name in <EOL> artif_vm_qcow2_type . defs ] , <EOL> key = lambda x : str ( x ) ) ) <EOL> def test_policies ( self ) : <EOL> self . assertEqual ( '<STR_LIT>' , <EOL> policy_placement_type . parent_type ) <EOL> self . assertEqual ( { } , policy_placement_type . parent_policies ) <EOL> self . assertEqual ( sorted ( [ '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ] , <EOL> key = lambda x : str ( x ) ) , <EOL> sorted ( [ policy_placement_type . get_policy ( name ) <EOL> for name in policy_placement_type . defs ] , <EOL> key = lambda x : str ( x ) ) ) <EOL> self . assertEqual ( '<STR_LIT>' , <EOL> policy_scaling_type . parent_type ) <EOL> self . assertEqual ( { } , policy_scaling_type . parent_policies ) <EOL> self . assertEqual ( sorted ( [ '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ] , <EOL> key = lambda x : str ( x ) ) , <EOL> sorted ( [ policy_scaling_type . get_policy ( name ) <EOL> for name in policy_scaling_type . defs ] , <EOL> key = lambda x : str ( x ) ) ) <EOL> self . assertEqual ( '<STR_LIT>' , <EOL> policy_update_type . parent_type ) <EOL> self . assertEqual ( { } , policy_update_type . parent_policies ) <EOL> self . assertEqual ( sorted ( [ '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ] , <EOL> key = lambda x : str ( x ) ) , <EOL> sorted ( [ policy_update_type . get_policy ( name ) <EOL> for name in policy_update_type . defs ] , <EOL> key = lambda x : str ( x ) ) ) <EOL> self . assertEqual ( '<STR_LIT>' , <EOL> policy_performance_type . parent_type ) <EOL> self . assertEqual ( { } , policy_performance_type . parent_policies ) <EOL> self . assertEqual ( sorted ( [ '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ] , <EOL> key = lambda x : str ( x ) ) , <EOL> sorted ( [ policy_performance_type . get_policy ( name ) <EOL> for name in policy_performance_type . defs ] , <EOL> key = lambda x : str ( x ) ) ) <EOL> def test_port_spec ( self ) : <EOL> tosca_def = EntityType . TOSCA_DEF <EOL> port_spec = tosca_def . get ( '<STR_LIT>' ) <EOL> self . assertEqual ( port_spec . get ( '<STR_LIT>' ) , <EOL> '<STR_LIT>' ) <EOL> properties = port_spec . get ( '<STR_LIT>' ) <EOL> self . assertEqual ( <EOL> sorted ( [ '<STR_LIT>' , '<STR_LIT:target>' , '<STR_LIT>' , '<STR_LIT:source>' , <EOL> '<STR_LIT>' ] ) , <EOL> sorted ( properties . keys ( ) ) ) </s>
