added tests for the new with_keys option.

modified:   README.rst
	modified:   nested_lookup/nested_lookup.py
	modified:   test_nested_loopkup.py
This commit is contained in:
Russell Ballestrini 2018-04-24 12:50:00 -07:00
parent 7bfbf5ada4
commit 756ad31763
3 changed files with 79 additions and 53 deletions

View file

@ -6,6 +6,15 @@ class TestNestedLookup(TestCase):
def setUp(self):
self.subject_dict = {'a':1,'b':{'d':100},'c':{'d':200}}
self.subject_dict2 = {
'name' : 'Russell Ballestrini',
'email_address' : 'test1@example.com',
'other' : {
'secondary_email' : 'test2@example.com',
'EMAIL_RECOVERY' : 'test3@example.com',
'email_address' : 'test4@example.com',
},
}
def test_nested_lookup(self):
results = nested_lookup('d', self.subject_dict)
@ -37,18 +46,32 @@ class TestNestedLookup(TestCase):
def test_wild_nested_lookup(self):
results = nested_lookup(
key = 'mail',
document = {
'name' : 'Russell Ballestrini',
'email_address' : 'test1@example.com',
'other' : {
'secondary_email' : 'test2@example.com',
'EMAIL_RECOVERY' : 'test3@example.com',
},
},
key = 'mail',
document = self.subject_dict2
wild = True,
)
self.assertEqual(3, len(results))
self.assertEqual(4, len(results))
self.assertIn('test1@example.com', results)
self.assertIn('test2@example.com', results)
self.assertIn('test3@example.com', results)
def test_wild_with_keys_nested_lookup(self):
matches = nested_lookup(
key = 'mail',
document = self.subject_dict2,
wild = True,
with_keys = True,
)
self.assertEqual(3, len(matches))
self.assertIn('email_address', matches)
self.assertIn('secondary_email', matches)
self.assertIn('EMAIL_RECOVERY', matches)
self.assertSetEqual({'test1@example.com','test4@example.com'}, set(matches['email_address']))
self.assertIn('test2@example.com', matches['secondary_email'])
def test_nested_lookup_with_keys(self):
matches = nested_lookup('d', self.subject_dict, with_keys=True)
self.assertIn('d', matches)
self.assertEqual(2, len(matches['d']))
self.assertSetEqual({100,200}, set(matches['d']))