Skip to content

Commit

Permalink
prawn-cake#12: Add support of nested paths.
Browse files Browse the repository at this point in the history
Add tests for `_get_path`.
  • Loading branch information
grundic committed Aug 21, 2016
1 parent 7337b4e commit f4c3a79
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions simplemodels/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,40 @@ class Company(Document):
company = Company.create(data)
self.assertIsInstance(company, Company)

def test_get_path(self):
data = {
'level_0_name': 'level_0_name_value',
'level_0_list': [
1, 3, 5, 7
],
'level_0_includes': {
'level_1_name': 'level_1_name_value',
'level_1_list': [
2, 4, 6, 8
],
'level_1_includes': {
'level_2_list':
['foo', 'bar', 'baz']
}
}
}

self.assertEqual(Document._get_path(data, None, 'NON-EXISTING'), None)
self.assertEqual(Document._get_path(data, None, 'level_0_name'), 'level_0_name_value')
self.assertEqual(Document._get_path(data, None, 'level_0_list'), [1, 3, 5, 7])
self.assertEqual(Document._get_path(data, 'level_0_list', 1), 3)
self.assertEqual(Document._get_path(data, ['level_0_list'], 1), 3)
self.assertEqual(Document._get_path(data, 'level_0_includes', 'level_1_name'), 'level_1_name_value')
self.assertEqual(Document._get_path(data, ['level_0_includes'], 'level_1_list'), [2, 4, 6, 8])
self.assertEqual(Document._get_path(data, ['level_0_includes', 'level_1_list'], '3'), 8)
self.assertEqual(Document._get_path(data, 'level_0_includes/level_1_list', '3'), 8)
self.assertEqual(Document._get_path(data, ['level_0_includes', 'level_1_list'], '-1'), 8)
self.assertEqual(Document._get_path(data, ['level_0_includes', 'level_1_list'], -1), 8)
self.assertEqual(Document._get_path(data, ['level_0_includes', 'level_1_includes'], 'level_2_list'),
['foo', 'bar', 'baz'])
self.assertEqual(Document._get_path(data, ['level_0_includes', 'level_1_includes', 'level_2_list'], 0),
'foo')

def test_field_path(self):
class User(Document):
name = CharField()
Expand Down

0 comments on commit f4c3a79

Please sign in to comment.