Пример #1
0
def test_meta_basic():
    att = CachedAttachment(key="c:foo", id=123, name="lol.txt", content_type="text/plain", chunks=3)

    # Regression test to verify that we do not add additional attributes. Note
    # that ``rate_limited`` is missing from this dict.
    assert att.meta() == {
        "chunks": 3,
        "content_type": "text/plain",
        "id": 123,
        "name": "lol.txt",
        "type": "event.attachment",
    }
Пример #2
0
def test_meta_rate_limited():
    att = CachedAttachment(
        key="c:foo", id=123, name="lol.txt", content_type="text/plain", chunks=3, rate_limited=True
    )

    assert att.meta() == {
        "chunks": 3,
        "content_type": "text/plain",
        "id": 123,
        "name": "lol.txt",
        "rate_limited": True,
        "type": "event.attachment",
    }
Пример #3
0
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
Пример #4
0
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"))
Пример #5
0
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."
    assert att2.rate_limited is None

    cache.delete("c:foo")
    assert not list(cache.get("c:foo"))