<s> from testenv . utils import get_resource as resource <EOL> from testenv . utils import deploy_application as deploy <EOL> from testenv import TestCase <EOL> TEST_PACKAGE_NAME = '<STR_LIT>' <EOL> TEST_PACKAGE_VERSION = '<STR_LIT>' <EOL> OLD_TEST_PACKAGE_VERSION = '<STR_LIT>' <EOL> class TestRestServiceListFilters ( TestCase ) : <EOL> def setUp ( self ) : <EOL> super ( TestRestServiceListFilters , self ) . setUp ( ) <EOL> self . first_deployment_id , self . first_blueprint_id , self . sec_deployment_id , self . sec_blueprint_id = self . _put_two_deployments ( ) <EOL> self . deployment_id_filter = { '<STR_LIT>' : self . first_deployment_id } <EOL> self . blueprint_id_filter = { '<STR_LIT>' : self . first_blueprint_id } <EOL> def _put_two_deployments ( self ) : <EOL> dsl_path = resource ( "<STR_LIT>" ) <EOL> first_deployment , _ = deploy ( dsl_path ) <EOL> sec_deployment , _ = deploy ( dsl_path ) <EOL> return first_deployment . id , first_deployment . blueprint_id , sec_deployment . id , sec_deployment . blueprint_id <EOL> def test_nodes_list_with_filters ( self ) : <EOL> filter_params = { '<STR_LIT>' : self . first_blueprint_id , <EOL> '<STR_LIT>' : self . first_deployment_id } <EOL> response = self . client . nodes . list ( ** filter_params ) <EOL> self . assertEquals ( len ( response ) , <NUM_LIT:3> , '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> . format ( self . first_deployment_id , <EOL> self . first_blueprint_id ) ) <EOL> for node in response : <EOL> self . assertEquals ( node . deployment_id , self . first_deployment_id ) <EOL> self . assertEquals ( node . blueprint_id , self . first_blueprint_id ) <EOL> def test_nodes_list_with_filters_and_include ( self ) : <EOL> filter_params = { '<STR_LIT>' : self . first_blueprint_id , <EOL> '<STR_LIT>' : self . first_deployment_id } <EOL> include = [ '<STR_LIT:id>' ] <EOL> response = self . client . nodes . list ( _include = include , ** filter_params ) <EOL> self . assertEquals ( len ( response ) , <NUM_LIT:3> , '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> . format ( self . first_deployment_id , <EOL> self . first_blueprint_id ) ) <EOL> for node in response : <EOL> self . assertIsNone ( node . deployment_id , '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> self . assertIsNotNone ( node . id , '<STR_LIT>' ) <EOL> def test_nodes_list_non_existent_filters ( self ) : <EOL> filter_params = { '<STR_LIT>' : self . first_blueprint_id , <EOL> '<STR_LIT>' : self . sec_deployment_id } <EOL> response = self . client . nodes . list ( ** filter_params ) <EOL> self . assertEquals ( len ( response ) , <NUM_LIT:0> , '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> . format ( self . first_deployment_id , <EOL> self . first_blueprint_id ) ) <EOL> def test_nodes_list_no_filters ( self ) : <EOL> response = self . client . nodes . list ( ) <EOL> self . assertEquals ( len ( response ) , <NUM_LIT:6> , '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> . format ( id = self . first_deployment_id ) ) <EOL> for node in response : <EOL> self . assertIn ( node . deployment_id , <EOL> ( self . first_deployment_id , self . sec_deployment_id ) ) <EOL> self . assertIn ( node . blueprint_id , <EOL> ( self . first_blueprint_id , self . sec_blueprint_id ) ) <EOL> def test_node_instances_list_with_filters ( self ) : <EOL> res = self . client . node_instances . list ( ** self . deployment_id_filter ) <EOL> self . assertEquals ( len ( res ) , <NUM_LIT:3> , '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> . format ( self . first_deployment_id ) ) <EOL> for node_instance in res : <EOL> self . assertEquals ( node_instance . deployment_id , <EOL> self . first_deployment_id ) <EOL> def test_node_instances_list_with_filters_multiple_values ( self ) : <EOL> self . multiple_value_filters = { '<STR_LIT>' : [ self . first_deployment_id , <EOL> self . sec_deployment_id ] , <EOL> '<STR_LIT>' : [ '<STR_LIT>' , <EOL> '<STR_LIT>' ] } <EOL> res = self . client . node_instances . list ( <EOL> ** self . multiple_value_filters ) <EOL> self . assertEquals ( len ( res ) , <NUM_LIT:4> , '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> . format ( self . multiple_value_filters ) ) <EOL> for node_instance in res : <EOL> for key in self . multiple_value_filters : <EOL> self . assertIn ( node_instance [ key ] , <EOL> self . multiple_value_filters [ key ] ) <EOL> def test_node_instances_list_no_filters ( self ) : <EOL> response = self . client . node_instances . list ( ) <EOL> self . assertEquals ( len ( response ) , <NUM_LIT:6> , '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> . format ( self . first_deployment_id ) ) <EOL> for node_instance in response : <EOL> self . assertIn ( node_instance . deployment_id , <EOL> ( self . first_deployment_id , self . sec_deployment_id ) ) <EOL> def test_deployments_list_with_filters ( self ) : <EOL> id_filter = { '<STR_LIT:id>' : self . first_deployment_id } <EOL> response = self . client . deployments . list ( ** id_filter ) <EOL> self . assertEquals ( len ( response ) , <NUM_LIT:1> , '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> . format ( self . first_deployment_id , len ( response ) ) ) <EOL> deployment = response [ <NUM_LIT:0> ] <EOL> self . assertEquals ( deployment [ '<STR_LIT:id>' ] , self . first_deployment_id ) <EOL> def test_deployments_list_no_filters ( self ) : <EOL> response = self . client . deployments . list ( ) <EOL> self . assertEquals ( len ( response ) , <NUM_LIT:2> , '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> . format ( self . first_deployment_id ) ) <EOL> for deployment in response : <EOL> self . assertIn ( deployment [ '<STR_LIT:id>' ] , <EOL> ( self . first_deployment_id , self . sec_deployment_id ) ) <EOL> def test_executions_list_with_filters ( self ) : <EOL> res = self . client . executions . list ( ** self . deployment_id_filter ) <EOL> self . assertEquals ( len ( res ) , <NUM_LIT:2> , '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> . format ( self . first_deployment_id , len ( res ) ) ) <EOL> for execution in res : <EOL> self . assertEquals ( execution . deployment_id , <EOL> self . first_deployment_id ) <EOL> def test_executions_list_no_filters ( self ) : <EOL> response = self . client . executions . list ( ) <EOL> self . assertEquals ( len ( response ) , <NUM_LIT:4> , '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> . format ( self . first_deployment_id , len ( response ) ) ) <EOL> for execution in response : <EOL> self . assertIn ( execution . deployment_id , <EOL> ( self . first_deployment_id , self . sec_deployment_id ) ) <EOL> def test_blueprints_list_with_filters ( self ) : <EOL> id_filter = { '<STR_LIT:id>' : self . first_blueprint_id } <EOL> res = self . client . blueprints . list ( ** id_filter ) <EOL> self . assertEquals ( len ( res ) , <NUM_LIT:1> , '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> . format ( self . first_blueprint_id , len ( res ) ) ) <EOL> blueprint = res [ <NUM_LIT:0> ] <EOL> self . assertEquals ( blueprint . id , self . first_blueprint_id ) <EOL> def test_blueprints_list_no_filters ( self ) : <EOL> res = self . client . blueprints . list ( ) <EOL> self . assertEquals ( len ( res ) , <NUM_LIT:2> , '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> . format ( self . first_blueprint_id , len ( res ) ) ) <EOL> for blueprint in res : <EOL> self . assertIn ( blueprint . id , <EOL> ( self . first_blueprint_id , self . sec_blueprint_id ) ) <EOL> def test_plugins_list_with_filters ( self ) : <EOL> self . upload_plugin ( TEST_PACKAGE_NAME , <EOL> TEST_PACKAGE_VERSION ) <EOL> sec_plugin_id = self . upload_plugin ( TEST_PACKAGE_NAME , <EOL> OLD_TEST_PACKAGE_VERSION ) [ '<STR_LIT:id>' ] <EOL> filter_field = { '<STR_LIT:id>' : sec_plugin_id } <EOL> response = self . client . plugins . list ( ** filter_field ) <EOL> self . assertEqual ( len ( response ) , <NUM_LIT:1> , '<STR_LIT>' <EOL> '<STR_LIT>' . format ( len ( response ) ) ) <EOL> self . assertDictContainsSubset ( filter_field , response [ <NUM_LIT:0> ] , <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> . format ( filter_field , response [ <NUM_LIT:0> ] ) ) <EOL> def test_plugins_list_no_filters ( self ) : <EOL> self . upload_plugin ( TEST_PACKAGE_NAME , <EOL> TEST_PACKAGE_VERSION ) <EOL> self . upload_plugin ( TEST_PACKAGE_NAME , <EOL> OLD_TEST_PACKAGE_VERSION ) <EOL> response = self . client . plugins . list ( ) <EOL> self . assertEqual ( len ( response ) , <NUM_LIT:2> , '<STR_LIT>' <EOL> '<STR_LIT>' . format ( len ( response ) ) ) <EOL> self . assertNotEquals ( response [ <NUM_LIT:0> ] . id , response [ <NUM_LIT:1> ] . id ) </s>
