MCPcopy Create free account
hub / github.com/MongoEngine/mongoengine / test_no_cache

Method test_no_cache

tests/queryset/test_queryset.py:5539–5571  ·  view source on GitHub ↗

Ensure you can add meta data to file

(self)

Source from the content-addressed store, hash-verified

5537 assert 1 == len(users._result_cache)
5538
5539 def test_no_cache(self):
5540 """Ensure you can add meta data to file"""
5541
5542 class Noddy(Document):
5543 fields = DictField()
5544
5545 Noddy.drop_collection()
5546 for i in range(100):
5547 noddy = Noddy()
5548 for j in range(20):
5549 noddy.fields["key" + str(j)] = "value " + str(j)
5550 noddy.save()
5551
5552 docs = Noddy.objects.no_cache()
5553
5554 counter = len([1 for i in docs])
5555 assert counter == 100
5556
5557 assert len(list(docs)) == 100
5558
5559 # Can't directly get a length of a no-cache queryset.
5560 with pytest.raises(TypeError):
5561 len(docs)
5562
5563 # Another iteration over the queryset should result in another db op.
5564 with query_counter() as q:
5565 list(docs)
5566 assert q == 1
5567
5568 # ... and another one to double-check.
5569 with query_counter() as q:
5570 list(docs)
5571 assert q == 1
5572
5573 def test_nested_queryset_iterator(self):
5574 # Try iterating the same queryset twice, nested.

Callers

nothing calls this directly

Calls 5

query_counterClass · 0.90
NoddyClass · 0.85
drop_collectionMethod · 0.80
no_cacheMethod · 0.80
saveMethod · 0.45

Tested by

no test coverage detected