def test_filter_by(self): ''' Test for Return the first match in a dictionary of target patterns ''' with patch.object(__builtin__, 'dict', MagicMock()): self.assertEqual(match.filter_by({'key': 'value'}, minion_id=101), 'value') self.assertEqual(match.filter_by({'key': 'value'}), 'value') self.assertEqual(match.filter_by({}), None)
def test_filter_by_merge_lists_rep(self): ''' Tests if filter_by merges list values by replacing the original list values with the merged list values. ''' lookup = { 'foo*': { 'list_key': [] }, 'bar*': { 'list_key': [ 'val1', 'val2' ] } } mdict = { 'list_key': [ 'val3', 'val4' ] } # list replacement specified by the merge_lists=False option result = { 'list_key': [ 'val3', 'val4' ] } self.assertDictEqual(match.filter_by(lookup, merge=mdict, merge_lists=False), result)
def test_filter_by_merge_lists_agg(self): ''' Tests if filter_by merges list values by aggregating them. ''' lookup = { 'foo*': { 'list_key': [] }, 'bar*': { 'list_key': [ 'val1', 'val2' ] } } mdict = { 'list_key': [ 'val3', 'val4' ] } # list aggregation specified by the merge_lists=True option result = { 'list_key': [ 'val1', 'val2', 'val3', 'val4' ] } self.assertDictEqual(match.filter_by(lookup, merge=mdict, merge_lists=True), result)
def test_filter_by_merge_with_none(self): """ Tests if filter_by merges a None object with a merge dictionary. """ lookup = {"foo*": {"key1": "fooval1", "key2": "fooval2"}, "bar*": None} # mdict should also be the returned dictionary # since a merge is done with None mdict = {"key1": "mergeval1"} self.assertDictEqual(match.filter_by(lookup, merge=mdict), mdict)
def test_filter_by(): """ Tests if filter_by returns the correct dictionary. """ lookup = { "foo*": {"key1": "fooval1", "key2": "fooval2"}, "bar*": {"key1": "barval1", "key2": "barval2"}, } result = {"key1": "barval1", "key2": "barval2"} assert match.filter_by(lookup) == result
def test_filter_by_merge_with_none(self): ''' Tests if filter_by merges a None object with a merge dictionary. ''' lookup = {'foo*': {'key1': 'fooval1', 'key2': 'fooval2'}, 'bar*': None} # mdict should also be the returned dictionary # since a merge is done with None mdict = {'key1': 'mergeval1'} self.assertDictEqual(match.filter_by(lookup, merge=mdict), mdict)
def test_filter_by(self): """ Tests if filter_by returns the correct dictionary. """ lookup = { "foo*": {"key1": "fooval1", "key2": "fooval2"}, "bar*": {"key1": "barval1", "key2": "barval2"}, } result = {"key1": "barval1", "key2": "barval2"} self.assertDictEqual(match.filter_by(lookup), result)
def test_filter_by_merge_lists_agg(): """ Tests if filter_by merges list values by aggregating them. """ lookup = {"foo*": {"list_key": []}, "bar*": {"list_key": ["val1", "val2"]}} mdict = {"list_key": ["val3", "val4"]} # list aggregation specified by the merge_lists=True option result = {"list_key": ["val1", "val2", "val3", "val4"]} assert match.filter_by(lookup, merge=mdict, merge_lists=True) == result
def test_filter_by_merge(): """ Tests if filter_by returns a dictionary merged with another dictionary. """ lookup = { "foo*": {"key1": "fooval1", "key2": "fooval2"}, "bar*": {"key1": "barval1", "key2": "barval2"}, } mdict = {"key1": "mergeval1"} result = {"key1": "mergeval1", "key2": "barval2"} assert match.filter_by(lookup, merge=mdict) == result
def test_filter_by_merge_lists_rep(): """ Tests if filter_by merges list values by replacing the original list values with the merged list values. """ lookup = {"foo*": {"list_key": []}, "bar*": {"list_key": ["val1", "val2"]}} mdict = {"list_key": ["val3", "val4"]} # list replacement specified by the merge_lists=False option result = {"list_key": ["val3", "val4"]} assert match.filter_by(lookup, merge=mdict, merge_lists=False) == result
def test_filter_by(self): ''' Tests if filter_by returns the correct dictionary. ''' lookup = { 'foo*': { 'key1': 'fooval1', 'key2': 'fooval2' }, 'bar*': { 'key1': 'barval1', 'key2': 'barval2' } } result = {'key1': 'barval1', 'key2': 'barval2'} self.assertDictEqual(match.filter_by(lookup), result)
def test_filter_by_merge(self): ''' Tests if filter_by returns a dictionary merged with another dictionary. ''' lookup = { 'foo*': { 'key1': 'fooval1', 'key2': 'fooval2' }, 'bar*': { 'key1': 'barval1', 'key2': 'barval2' } } mdict = {'key1': 'mergeval1'} result = {'key1': 'mergeval1', 'key2': 'barval2'} self.assertDictEqual(match.filter_by(lookup, merge=mdict), result)