def test_basic_rate_limited(): data = InMemoryCache() cache = BaseAttachmentCache(data) att = CachedAttachment( name="lol.txt", content_type="text/plain", data=b"Hello World! Bye.", rate_limited=True ) cache.set("c:foo", [att]) (att2,) = cache.get("c:foo") assert att2.key == att.key == "c:foo" assert att2.id == att.id == 0 assert att2.data == att.data == b"Hello World! Bye." assert att2.rate_limited is True
def test_basic_unchunked(): data = InMemoryCache() cache = BaseAttachmentCache(data) att = CachedAttachment(name="lol.txt", content_type="text/plain", data=b"Hello World! Bye.") cache.set("c:foo", [att]) (att2, ) = cache.get("c:foo") assert att2.key == att.key == "c:foo" assert att2.id == att.id == 0 assert att2.data == att.data == b"Hello World! Bye." cache.delete("c:foo") assert not list(cache.get("c:foo"))
def test_basic_chunked(): data = InMemoryCache() cache = BaseAttachmentCache(data) cache.set_chunk("c:foo", 123, 0, b"Hello World! ") cache.set_chunk("c:foo", 123, 1, b"") cache.set_chunk("c:foo", 123, 2, b"Bye.") att = CachedAttachment(key="c:foo", id=123, name="lol.txt", content_type="text/plain", chunks=3) cache.set("c:foo", [att]) (att2, ) = cache.get("c:foo") assert att2.key == att.key == "c:foo" assert att2.id == att.id == 123 assert att2.data == att.data == b"Hello World! Bye." cache.delete("c:foo") assert not list(cache.get("c:foo"))