'Tests that token functions work properly'

@execute_count(15)
def test_token_function(self):

    assert (TokenTestModel.objects.count() == 0)
    for i in range(10):
        TokenTestModel.create(key=i, val=i)
    assert (TokenTestModel.objects.count() == 10)
    seen_keys = set()
    last_token = None
    for instance in TokenTestModel.objects().limit(5):
        last_token = instance.key
        seen_keys.add(last_token)
    assert (len(seen_keys) == 5)
    for instance in TokenTestModel.objects(pk__token__gt=functions.Token(last_token)):
        seen_keys.add(instance.key)
    assert (len(seen_keys) == 10)
    assert all([(i in seen_keys) for i in range(10)])
    r = TokenTestModel.objects(pk__token=functions.Token(last_token))
    self.assertEqual(len(r), 1)
