def describe_checked(region, criteria): instances = TEST_FLEET or fleet.Fleet(region) is_included = filters.compile(criteria) matches = filter(is_included, instances) for match in matches: click.echo(describe_instance(match))
def test_multiple_criteria(self): is_included = filters.compile([ 'role:hammer', 'target:nail', ]) assert is_included({'role': 'hammer', 'target': 'nail', 'other': 'whocares'}) assert not is_included({'role': 'hammer'}) assert not is_included({'role': 'hammer', 'target': 'other'}) assert not is_included({'role': 'other', 'target': 'nail'})
def list_checked(region, criteria, public=False, private=False): instances = TEST_FLEET or fleet.Fleet(region) is_included = filters.compile(criteria) matches = filter(is_included, instances) if public: show = lambda i: i['PublicDnsName'] elif private: show = lambda i: i['PrivateDnsName'] else: show = lambda i: i['Id'] for i in matches: s = show(i) if s: click.echo(s)
def test_single_criteria(self): is_included = filters.compile(['name:bob']) assert is_included({'name': 'bob'}) assert is_included({'name': 'bob', 'other': 'whocares'}) assert not is_included({'name': 'bub', 'other': 'whocares'})
def test_empty_criteria_accepts_all(self): is_included = filters.compile([]) assert is_included('cheese') assert is_included(None)
def test_compiling_multi_colon_filter(self): is_included = filters.compile(['Name::::::']) assert is_included({'Name': ':::::'}) assert not is_included({'Name': 'dog'})
def test_compiling_bad_filter(self): with self.assertRaises(filters.InvalidCriteria): filters.compile(['dog'])