# Path: chamber/storages/boto3.py
# def force_bytes_content(content, blocksize=1024):
#     """Returns a tuple of content (file-like object) and bool indicating wheter the content has been casted or not"""
#     block = content.read(blocksize)
#     content.seek(0)
# 
#     if not isinstance(block, bytes):
#         _content = bytes(
#             content.read(),
#             'utf-8' if not hasattr(content, 'encoding') or content.encoding is None else content.encoding,
#         )
#         return ContentFile(_content), True
#     return content, False


from django.core.files.base import ContentFile
from django.test import TestCase
from chamber.storages.boto3 import force_bytes_content
from germanium.decorators import data_provider




class S3StorageTestCase(TestCase):

    TEST_DATA = (
        ('Hello, this is str content.', b'Hello, this is str content.', True),
        (b'Hello, this is bytes content.', b'Hello, this is bytes content.', False),
    )

    @data_provider(TEST_DATA)
    def test_s3storage_casts_content_to_bytes_if_needed(self, content, content_result, should_cast):
        file = ContentFile(content)

# Path: chamber/storages/boto3.py
# def force_bytes_content(content, blocksize=1024):
#     """Returns a tuple of content (file-like object) and bool indicating wheter the content has been casted or not"""
#     block = content.read(blocksize)
#     content.seek(0)
# 
#     if not isinstance(block, bytes):
#         _content = bytes(
#             content.read(),
#             'utf-8' if not hasattr(content, 'encoding') or content.encoding is None else content.encoding,
#         )
#         return ContentFile(_content), True
#     return content, False


# Path: example/dj/apps/test_chamber/tests/storages/boto3.py
from django.core.files.base import ContentFile
from django.test import TestCase
from chamber.storages.boto3 import force_bytes_content
from germanium.decorators import data_provider





class S3StorageTestCase(TestCase):

    TEST_DATA = (
        ('Hello, this is str content.', b'Hello, this is str content.', True),
        (b'Hello, this is bytes content.', b'Hello, this is bytes content.', False),
    )

    @data_provider(TEST_DATA)
    def test_s3storage_casts_content_to_bytes_if_needed(self, content, content_result, should_cast):
        file = ContentFile(content)

        result, casted = force_bytes_content(file)