# Path: tests/test_case.py
# class TestCase:
#     """
#     Created TestCase to avoid duplicated code in the other tests
#     """
#     TEST_DB = SqliteDatabase(':memory:')
# 
#     @classmethod
#     def setup_class(cls):
#         """
#         When a Test is created override the ``database`` attribute for all
#         the tables with a SqliteDatabase in memory.
#         """
#         for table in TABLES:
#             table._meta.database = cls.TEST_DB
#             table.create_table(fail_silently=True)
# 
#         cls.app = app.test_client()
# 
#     def setup_method(self):
#         """
#         When setting up a new test method clear all the tables
#         """
#         for table in TABLES:
#             table.delete().execute()
# 
# Path: models.py
# class Item(BaseModel):
#     """
#     Item describes a product for the e-commerce platform.
# 
#     Attributes:
#         uuid (UUID): Item UUID
#         name (str): Name for the product
#         price (decimal.Decimal): Price for a single product
#         description (str): Product description
#         availability (int): Quantity of items available
#         category (str): Category group of the item
# 
#     """
#     uuid = UUIDField(unique=True)
#     name = CharField()
#     price = DecimalField(auto_round=True)
#     description = TextField()
#     availability = IntegerField()
#     category = TextField()
#     _schema = ItemSchema
#     _search_attributes = ['name', 'category', 'description']
# 
#     def __str__(self):
#         return '{}, {}, {}, {}'.format(
#             self.uuid,
#             self.name,
#             self.price,
#             self.description)
# 
#     def is_favorite(self, item):
#         for f in self.favorites:
#             if f.item_id == item.id:
#                 return True
#         return False
# 
# class Picture(BaseModel):
#     """
#     A Picture model describes and points to a stored image file. Allows linkage
#     between the image files and one :any:`Item` resource.
# 
#     Attributes:
#         uuid (UUID): Picture's uuid
#         extension (str): Extension of the image file the Picture's model refer to
#         item (:any:`Item`): Foreign key referencing the Item related to the Picture.
#             A ``pictures`` field can be used from ``Item`` to access the Item resource
#             pictures
#     """
#     uuid = UUIDField(unique=True)
#     extension = CharField()
#     item = ForeignKeyField(Item, related_name='pictures')
#     _schema = PictureSchema
# 
#     @property
#     def filename(self):
#         """Full name (uuid.ext) of the file that the Picture model reference."""
#         return '{}.{}'.format(
#             self.uuid,
#             self.extension)
# 
#     def __str__(self):
#         return '{}.{} -> item: {}'.format(
#             self.uuid,
#             self.extension,
#             self.item.uuid)
# 
# Path: tests/test_utils.py
# def mock_uuid_generator():
# def mock_datetime(*args):
#     def __init__(self, cls):
#     def __call__(self, created_at=mock_datetime(), uuid=None, **query):
# def get_all_models_names():
# def add_user(email, password, id=None, first_name='John', last_name='Doe'):
# def add_admin_user(email, psw, id=None):
# def add_address(user, country='Italy', city='Pistoia', post_code='51100',
#                 address='Via Verdi 12', phone='3294882773', id=None):
# def add_favorite(user, item, id=None):
# def json_favorite(item):
# def add_item(name='Item Test', price='15.99',
#              description='test test test', id=None, category='scarpe'):
# def open_with_auth(app, url, method, username, password, content_type, data):
# def clean_images():
# def setup_images():
# def count_order_items(order):
# def format_jsonapi_request(type_, data):
# def assert_valid_response(data, expected):
#     def sort_data_lists(data, attribute, key):
#     def included_sorter(i): return i['type']
#     def errors_sorter(e): return e['source']['pointer']
# def wrong_dump(data):
# class MockModelCreate:
#     AUTH_TYPE = 'Basic'
#     RESULTS = json.load(fo)


from tests.test_case import TestCase
from io import BytesIO
from models import Item, Picture
from tests import test_utils
import json
import os
import uuid
import http.client as client
import utils

TEST_ITEM2 = {
    'uuid': 'd46b13a1-f4bb-4cfb-8076-6953358145f3',
    'name': 'GINO',
    'price': 30.20,
    'description': 'svariati GINIIIII',
    'availability': 1,
    'category': 'accessori',
}

TEST_PICTURE = {
    'uuid': 'df690434-a488-419f-899e-8853cba1a22b',
    'extension': 'jpg'
}

TEST_PICTURE2 = {
    'uuid': 'c0001a48-10a3-43c1-b87b-eabac0b2d42f',
    'extension': 'png'
}

WRONG_UUID = 'e8e42371-46de-4f5e-8927-e2cc34826269'


class TestPictures(TestCase):

    @classmethod
    def setup_class(cls):
        super(TestPictures, cls).setup_class()
        utils.get_image_folder = lambda: os.path.join(utils.get_project_root(),
                                                      TEST_IMAGE_FOLDER)

# Path: tests/test_case.py
# class TestCase:
#     """
#     Created TestCase to avoid duplicated code in the other tests
#     """
#     TEST_DB = SqliteDatabase(':memory:')
# 
#     @classmethod
#     def setup_class(cls):
#         """
#         When a Test is created override the ``database`` attribute for all
#         the tables with a SqliteDatabase in memory.
#         """
#         for table in TABLES:
#             table._meta.database = cls.TEST_DB
#             table.create_table(fail_silently=True)
# 
#         cls.app = app.test_client()
# 
#     def setup_method(self):
#         """
#         When setting up a new test method clear all the tables
#         """
#         for table in TABLES:
#             table.delete().execute()
# 
# Path: models.py
# class Item(BaseModel):
#     """
#     Item describes a product for the e-commerce platform.
# 
#     Attributes:
#         uuid (UUID): Item UUID
#         name (str): Name for the product
#         price (decimal.Decimal): Price for a single product
#         description (str): Product description
#         availability (int): Quantity of items available
#         category (str): Category group of the item
# 
#     """
#     uuid = UUIDField(unique=True)
#     name = CharField()
#     price = DecimalField(auto_round=True)
#     description = TextField()
#     availability = IntegerField()
#     category = TextField()
#     _schema = ItemSchema
#     _search_attributes = ['name', 'category', 'description']
# 
#     def __str__(self):
#         return '{}, {}, {}, {}'.format(
#             self.uuid,
#             self.name,
#             self.price,
#             self.description)
# 
#     def is_favorite(self, item):
#         for f in self.favorites:
#             if f.item_id == item.id:
#                 return True
#         return False
# 
# class Picture(BaseModel):
#     """
#     A Picture model describes and points to a stored image file. Allows linkage
#     between the image files and one :any:`Item` resource.
# 
#     Attributes:
#         uuid (UUID): Picture's uuid
#         extension (str): Extension of the image file the Picture's model refer to
#         item (:any:`Item`): Foreign key referencing the Item related to the Picture.
#             A ``pictures`` field can be used from ``Item`` to access the Item resource
#             pictures
#     """
#     uuid = UUIDField(unique=True)
#     extension = CharField()
#     item = ForeignKeyField(Item, related_name='pictures')
#     _schema = PictureSchema
# 
#     @property
#     def filename(self):
#         """Full name (uuid.ext) of the file that the Picture model reference."""
#         return '{}.{}'.format(
#             self.uuid,
#             self.extension)
# 
#     def __str__(self):
#         return '{}.{} -> item: {}'.format(
#             self.uuid,
#             self.extension,
#             self.item.uuid)
# 
# Path: tests/test_utils.py
# def mock_uuid_generator():
# def mock_datetime(*args):
#     def __init__(self, cls):
#     def __call__(self, created_at=mock_datetime(), uuid=None, **query):
# def get_all_models_names():
# def add_user(email, password, id=None, first_name='John', last_name='Doe'):
# def add_admin_user(email, psw, id=None):
# def add_address(user, country='Italy', city='Pistoia', post_code='51100',
#                 address='Via Verdi 12', phone='3294882773', id=None):
# def add_favorite(user, item, id=None):
# def json_favorite(item):
# def add_item(name='Item Test', price='15.99',
#              description='test test test', id=None, category='scarpe'):
# def open_with_auth(app, url, method, username, password, content_type, data):
# def clean_images():
# def setup_images():
# def count_order_items(order):
# def format_jsonapi_request(type_, data):
# def assert_valid_response(data, expected):
#     def sort_data_lists(data, attribute, key):
#     def included_sorter(i): return i['type']
#     def errors_sorter(e): return e['source']['pointer']
# def wrong_dump(data):
# class MockModelCreate:
#     AUTH_TYPE = 'Basic'
#     RESULTS = json.load(fo)


# Path: tests/test_pictures.py
from tests.test_case import TestCase
from io import BytesIO
from models import Item, Picture
from tests import test_utils
import json
import os
import uuid
import http.client as client
import utils


TEST_ITEM2 = {
    'uuid': 'd46b13a1-f4bb-4cfb-8076-6953358145f3',
    'name': 'GINO',
    'price': 30.20,
    'description': 'svariati GINIIIII',
    'availability': 1,
    'category': 'accessori',
}

TEST_PICTURE = {
    'uuid': 'df690434-a488-419f-899e-8853cba1a22b',
    'extension': 'jpg'
}

TEST_PICTURE2 = {
    'uuid': 'c0001a48-10a3-43c1-b87b-eabac0b2d42f',
    'extension': 'png'
}

WRONG_UUID = 'e8e42371-46de-4f5e-8927-e2cc34826269'


class TestPictures(TestCase):

    @classmethod
    def setup_class(cls):
        super(TestPictures, cls).setup_class()
        utils.get_image_folder = lambda: os.path.join(utils.get_project_root(),
                                                      TEST_IMAGE_FOLDER)

        test_utils.get_image_folder = utils.get_image_folder