# Path: test/mocks/mock_repository.py
# class MockRepository(object):
#     
#     def __init__(self):
#         self.name = "mock_repo"
#         self._repository = {
# 
#         }
# 
#     def upload_content(self, object_name, content, content_type="text/plain"):
#        self._repository[object_name] = {
#            "content": content,
#            "metadata": _make_metadata(content.encode("utf-8"), content_type)
#        }
# 
#     def upload_file(self,object_name, file_obj):
#         cnt = file_obj.read()
#         self._repository[object_name] = {
#            "content": cnt,
#            "metadata": _make_metadata(cnt, "application/octet-stream")
#         }
# 
#     def download_content(self, object_name):
#         if not self.exists(object_name):
#             raise NotFound()
#         return self._repository[object_name]["content"]
# 
#     def download_file(self, object_name, file_obj):
#         if not self.exists(object_name):
#             raise NotFound()
#         file_obj.write(self._repository[object_name]["content"])
# 
#     def delete(self, object_name):
#         if self.exists(object_name):
#            del self._repository[object_name]
# 
#     def exists(self, object_name):
#        return object_name in self._repository
# 
#     def metadata(self, object_name):
#         if not self.exists(object_name):
#             raise NotFound()
#         return self._repository[object_name]["metadata"]
# 
#     def list(self, prefix=""):
#         return list(filter(lambda x: x.startswith(prefix) ,self._repository.keys()))


from .mocks.mock_repository import MockRepository as Repository
from io import BytesIO
import six
import time
from __future__ import unicode_literals #for BytesIO automatic conversion to unicode string in python 2


def test_content():
    repo = Repository()
    repo.upload_content("object/x", "hello world")
    assert repo.exists("object/x")
    assert repo.download_content("object/x") == "hello world"

def test_file():
    repo = Repository()
    io = BytesIO("hello world".encode("utf-8"))
    repo.upload_file("object/x", io)
    assert repo.exists("object/x")
    assert repo.download_content("object/x").decode("utf-8") == "hello world"

def test_list():

# Path: test/mocks/mock_repository.py
# class MockRepository(object):
#     
#     def __init__(self):
#         self.name = "mock_repo"
#         self._repository = {
# 
#         }
# 
#     def upload_content(self, object_name, content, content_type="text/plain"):
#        self._repository[object_name] = {
#            "content": content,
#            "metadata": _make_metadata(content.encode("utf-8"), content_type)
#        }
# 
#     def upload_file(self,object_name, file_obj):
#         cnt = file_obj.read()
#         self._repository[object_name] = {
#            "content": cnt,
#            "metadata": _make_metadata(cnt, "application/octet-stream")
#         }
# 
#     def download_content(self, object_name):
#         if not self.exists(object_name):
#             raise NotFound()
#         return self._repository[object_name]["content"]
# 
#     def download_file(self, object_name, file_obj):
#         if not self.exists(object_name):
#             raise NotFound()
#         file_obj.write(self._repository[object_name]["content"])
# 
#     def delete(self, object_name):
#         if self.exists(object_name):
#            del self._repository[object_name]
# 
#     def exists(self, object_name):
#        return object_name in self._repository
# 
#     def metadata(self, object_name):
#         if not self.exists(object_name):
#             raise NotFound()
#         return self._repository[object_name]["metadata"]
# 
#     def list(self, prefix=""):
#         return list(filter(lambda x: x.startswith(prefix) ,self._repository.keys()))


# Path: test/repository_test.py
from .mocks.mock_repository import MockRepository as Repository
from io import BytesIO
import six
import time

from __future__ import unicode_literals #for BytesIO automatic conversion to unicode string in python 2


def test_content():
    repo = Repository()
    repo.upload_content("object/x", "hello world")
    assert repo.exists("object/x")
    assert repo.download_content("object/x") == "hello world"

def test_file():
    repo = Repository()
    io = BytesIO("hello world".encode("utf-8"))
    repo.upload_file("object/x", io)
    assert repo.exists("object/x")
    assert repo.download_content("object/x").decode("utf-8") == "hello world"

def test_list():

    repo = Repository()