def test_recursive_dicts(self): """This is useful for filtering USofA data""" small = { 'account1': { 'owner': 'me' } } small2 = { 'account1': { 'owner': 'somebodyelse' } } small3 = { 'missing_in_big': { 'foo': 42 } } big = { 'account1': { 'id': 42, 'owner': 'me', }, 'account2': { 'id': 43, 'owner': 'notme' } } self.assertEqual(dict_is_subset(big, big), True) self.assertEqual(dict_is_subset(small, big), True) self.assertEqual(dict_is_subset(small2, big), False) self.assertEqual(dict_is_subset(small3, big), False)
def test_flat_dicts_that_are_not_subsets(self): small = {'a': 43} small2 = {'b': 42} small3 = {'a': '42'} small4 = {'c': 42} big = {'a':42, 'b': 43} self.assertEqual(dict_is_subset(small, big), False) self.assertEqual(dict_is_subset(small2, big), False) self.assertEqual(dict_is_subset(small3, big), False) self.assertEqual(dict_is_subset(small4, big), False)
def test_flat_dicts_that_are_not_subsets(self): small = {'a': 43} small2 = {'b': 42} small3 = {'a': '42'} small4 = {'c': 42} big = {'a': 42, 'b': 43} self.assertEqual(dict_is_subset(small, big), False) self.assertEqual(dict_is_subset(small2, big), False) self.assertEqual(dict_is_subset(small3, big), False) self.assertEqual(dict_is_subset(small4, big), False)
def get_usofa_data(self): s3_connection = boto3.resource('s3', self.region_name) key = s3_connection.Object(self.usofa_bucket, self.usofa_key) account_data = json.loads(key.get()['Body'].read().decode('utf-8')) filtered_data = {name: data for name, data in account_data.items() if dict_is_subset(self.usofa_filter, data)} return filtered_data
def test_recursing_meets_non_dict_container(self): small = { 'foo': {'bar': 42} } big = { 'foo': ['bar'] } self.assertEqual(dict_is_subset(small, big), False)
def test_recursive_dicts(self): """This is useful for filtering USofA data""" small = {'account1': {'owner': 'me'}} small2 = {'account1': {'owner': 'somebodyelse'}} small3 = {'missing_in_big': {'foo': 42}} big = { 'account1': { 'id': 42, 'owner': 'me', }, 'account2': { 'id': 43, 'owner': 'notme' } } self.assertEqual(dict_is_subset(big, big), True) self.assertEqual(dict_is_subset(small, big), True) self.assertEqual(dict_is_subset(small2, big), False) self.assertEqual(dict_is_subset(small3, big), False)
def test_flat_dicts_that_are_subsets(self): small = {'a': 42} big = {'a':42, 'b': 43} self.assertEqual(dict_is_subset(small, big), True) self.assertEqual(dict_is_subset(big, big), True)
def test_empty_dict_is_always_a_subset(self): self.assertEqual(dict_is_subset({}, {}), True) self.assertEqual(dict_is_subset({}, {'foo': 'bar'}), True)
def test_recursing_meets_non_dict_container(self): small = {'foo': {'bar': 42}} big = {'foo': ['bar']} self.assertEqual(dict_is_subset(small, big), False)
def test_flat_dicts_that_are_subsets(self): small = {'a': 42} big = {'a': 42, 'b': 43} self.assertEqual(dict_is_subset(small, big), True) self.assertEqual(dict_is_subset(big, big), True)