コード例 #1
0
ファイル: storage.py プロジェクト: rmdouglas/dragonchain
def put(key: str,
        value: bytes,
        cache_expire: Optional[int] = None,
        should_cache: bool = True) -> None:
    """Puts an object into storage with optional cache write-thru
    Args:
        key: The key of the object being written in S3
        value: The value of the bytes object being written in S3
        cache_expire: The amount of time (in seconds) until the key expires in the cache
    Raises:
        exceptions.StorageError on any unexpected error interacting with storage
    """
    try:
        storage.put(STORAGE_LOCATION, key, value)
        if should_cache:
            redis.cache_put(key, value, cache_expire)
    except Exception:
        raise exceptions.StorageError(
            "Uncaught exception while performing storage put")
コード例 #2
0
 def test_put_calls_with_correct_params(self, mock_put_object):
     s3.put("test", "thing", b"hi")
     mock_put_object.assert_called_once_with(Bucket="test",
                                             Key="thing",
                                             Body=b"hi")