def find_query(self, wanted, orderings, default): """ Given the list of order statements and a query that is currently found in the request's querystring returns the next in line, or falls back to the given default. """ for current, next in cycle_pairs(orderings): if current == wanted: return next return default
def test_cycle_pairs(self): self.assertEqual(list(cycle_pairs([1, 2, 3])), [(1, 2), (2, 3), (3, 1)])