diff options
| author | Andrew Kuchev <0coming.soon@gmail.com> | 2015-11-05 15:59:56 +0500 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2016-02-23 12:15:08 -0500 |
| commit | e81d1c995c0cc5573d3627de0fe6b803b2f43fb2 (patch) | |
| tree | 1b596d09984d0bd284124bce3a502220094f2174 /tests/template_tests | |
| parent | cdbd8745f6c550422170a6ae5928c0b679fab0df (diff) | |
Fixed #25670 -- Allowed dictsort to sort a list of lists.
Thanks Tim Graham for the review.
Diffstat (limited to 'tests/template_tests')
| -rw-r--r-- | tests/template_tests/filter_tests/test_dictsort.py | 18 | ||||
| -rw-r--r-- | tests/template_tests/filter_tests/test_dictsortreversed.py | 18 |
2 files changed, 36 insertions, 0 deletions
diff --git a/tests/template_tests/filter_tests/test_dictsort.py b/tests/template_tests/filter_tests/test_dictsort.py index 1d937a2dae..00c2bd42cb 100644 --- a/tests/template_tests/filter_tests/test_dictsort.py +++ b/tests/template_tests/filter_tests/test_dictsort.py @@ -33,6 +33,24 @@ class FunctionTests(SimpleTestCase): self.assertEqual([d['foo']['bar'] for d in sorted_data], [3, 2, 1]) + def test_sort_list_of_tuples(self): + data = [('a', '42'), ('c', 'string'), ('b', 'foo')] + expected = [('a', '42'), ('b', 'foo'), ('c', 'string')] + self.assertEqual(dictsort(data, 0), expected) + + def test_sort_list_of_tuple_like_dicts(self): + data = [ + {'0': 'a', '1': '42'}, + {'0': 'c', '1': 'string'}, + {'0': 'b', '1': 'foo'}, + ] + expected = [ + {'0': 'a', '1': '42'}, + {'0': 'b', '1': 'foo'}, + {'0': 'c', '1': 'string'}, + ] + self.assertEqual(dictsort(data, '0'), expected) + def test_invalid_values(self): """ If dictsort is passed something other than a list of dictionaries, diff --git a/tests/template_tests/filter_tests/test_dictsortreversed.py b/tests/template_tests/filter_tests/test_dictsortreversed.py index 92229495fe..ada199e127 100644 --- a/tests/template_tests/filter_tests/test_dictsortreversed.py +++ b/tests/template_tests/filter_tests/test_dictsortreversed.py @@ -19,6 +19,24 @@ class FunctionTests(SimpleTestCase): [('age', 18), ('name', 'Jonny B Goode')]], ) + def test_sort_list_of_tuples(self): + data = [('a', '42'), ('c', 'string'), ('b', 'foo')] + expected = [('c', 'string'), ('b', 'foo'), ('a', '42')] + self.assertEqual(dictsortreversed(data, 0), expected) + + def test_sort_list_of_tuple_like_dicts(self): + data = [ + {'0': 'a', '1': '42'}, + {'0': 'c', '1': 'string'}, + {'0': 'b', '1': 'foo'}, + ] + expected = [ + {'0': 'c', '1': 'string'}, + {'0': 'b', '1': 'foo'}, + {'0': 'a', '1': '42'}, + ] + self.assertEqual(dictsortreversed(data, '0'), expected) + def test_invalid_values(self): """ If dictsortreversed is passed something other than a list of |
