# Path: seedbox/db/models.py
# class Model(object):
# class Torrent(Model):
# class MediaFile(Model):
# class AppState(Model):
#     PK_NAME = 'id'
#     PK_NAME = 'torrent_id'
#     PK_NAME = 'media_id'
#     PK_NAME = 'name'
#     def __init__(self, **kwds):
#     def as_dict(self):
#     def items(self):
#     def __eq__(self, other):
#     def __iter__(self):
#     def __getitem__(self, name):
#     def __setitem__(self, name, value):
#     def __contains__(self, name):
#     def __str__(self):
#     def pk_filter(cls, value=None):
#     def make_empty(cls):
#     def __init__(self, torrent_id, name, created_at=None, updated_at=None,
#                  state=None, retry_count=None, failed=None, error_msg=None,
#                  invalid=None, purged=None, media_files=None):
#     def __init__(self, media_id, torrent_id, filename, file_ext,
#                  file_path=None, size=None, compressed=None, synced=None,
#                  missing=None, skipped=None, error_msg=None, total_time=None):
#     def __init__(self, name, value):
# 
# Path: seedbox/db/sqlalchemy/model_util.py
# LOG = logging.getLogger(__name__)
# def from_db(db_item):
# def to_db(api_item, db_item=None):
# 
# Path: seedbox/db/sqlalchemy/models.py
# NONE_TYPE = 'none'
# BOOL_TYPE = 'bool'
# DATE_TYPE = 'datetime'
# INT_TYPE = 'int'
# STR_TYPE = 'str'
# VAL_TYPES = [NONE_TYPE, BOOL_TYPE, DATE_TYPE, INT_TYPE, STR_TYPE]
# def to_table_name(klass_name):
#     def __tablename__(cls):
#     def save(self, session):
#     def __repr__(self):
#     def __setitem__(self, key, value):
#     def __getitem__(self, key):
#     def get(self, key, default=None):
#     def __iter__(self):
#     def __next__(self):
#     def next(self):
#     def update(self, values):
#     def iteritems(self):
#     def __init__(self, id, value=None):
#     def __setitem__(self, key, value):
#     def __getitem__(self, key):
#     def get(self, key, default=None):
#     def update(self, values):
#     def get_value(self):
#     def set_value(self, value):
#     def reset_value(self):
#     def __repr__(self):
# def verify_tables(engine):
# def purge_all_tables(engine):
#     def __init__(self, table, query):
#     def _handle_complex_op(self, complex_op, nodes):
#     def _handle_simple_op(self, simple_op, nodes):
#     def _transform(self, sub_tree):
#     def apply_filter(self, expression_tree):
# class Base(six.Iterator):
# class HasId(object):
# class HasTimestamp(object):
# class Torrent(Base, HasId, HasTimestamp):
# class MediaFile(Base, HasId):
# class AppState(Base):
# class QueryTransformer(object):
# 
# Path: seedbox/db/sqlalchemy/session.py
# @property
# def session(self):
#     """Get a Session instance."""
#     return self._session_maker()
# 
# Path: seedbox/tests/test.py
# class ConfiguredBaseTestCase(BaseTestCase):
#     def setUp(self):
#     def tearDown(self):
#     def _make_dir(self, dirname):
#     def set_required_options(self):


from seedbox.db import models as api_model
from seedbox.db.sqlalchemy import model_util
from seedbox.db.sqlalchemy import models as db_model
from seedbox.db.sqlalchemy import session
from seedbox.tests import test
        db_model.purge_all_tables(self.facade.engine)
        super(ModelUtilTestCase, self).tearDown()

    def test_from_db(self):
        self.assertIsNone(model_util.from_db(None))

        _tor = db_model.Torrent()
        _tor['name'] = 'fake.torrent'

        _pub_tor = model_util.from_db(_tor)
        self.assertIsInstance(_pub_tor, api_model.Torrent)

        _mf = db_model.MediaFile()
        _mf['filename'] = 'media.mp4'
        _mf['file_ext'] = '.mp4'
        _mf['torrent_id'] = _tor.id

        _pub_mf = model_util.from_db(_mf)
        self.assertIsInstance(_pub_mf, api_model.MediaFile)

    def test_to_db(self):
        self.assertIsNone(model_util.to_db(None))

        _tor = api_model.Torrent.make_empty()
        _tor.torrent_id = 1
        _tor.name = 'fake.torrent'

        _db_tor = model_util.to_db(_tor)
        self.assertIsInstance(_db_tor, db_model.Torrent)


# Path: seedbox/db/models.py
# class Model(object):
# class Torrent(Model):
# class MediaFile(Model):
# class AppState(Model):
#     PK_NAME = 'id'
#     PK_NAME = 'torrent_id'
#     PK_NAME = 'media_id'
#     PK_NAME = 'name'
#     def __init__(self, **kwds):
#     def as_dict(self):
#     def items(self):
#     def __eq__(self, other):
#     def __iter__(self):
#     def __getitem__(self, name):
#     def __setitem__(self, name, value):
#     def __contains__(self, name):
#     def __str__(self):
#     def pk_filter(cls, value=None):
#     def make_empty(cls):
#     def __init__(self, torrent_id, name, created_at=None, updated_at=None,
#                  state=None, retry_count=None, failed=None, error_msg=None,
#                  invalid=None, purged=None, media_files=None):
#     def __init__(self, media_id, torrent_id, filename, file_ext,
#                  file_path=None, size=None, compressed=None, synced=None,
#                  missing=None, skipped=None, error_msg=None, total_time=None):
#     def __init__(self, name, value):
# 
# Path: seedbox/db/sqlalchemy/model_util.py
# LOG = logging.getLogger(__name__)
# def from_db(db_item):
# def to_db(api_item, db_item=None):
# 
# Path: seedbox/db/sqlalchemy/models.py
# NONE_TYPE = 'none'
# BOOL_TYPE = 'bool'
# DATE_TYPE = 'datetime'
# INT_TYPE = 'int'
# STR_TYPE = 'str'
# VAL_TYPES = [NONE_TYPE, BOOL_TYPE, DATE_TYPE, INT_TYPE, STR_TYPE]
# def to_table_name(klass_name):
#     def __tablename__(cls):
#     def save(self, session):
#     def __repr__(self):
#     def __setitem__(self, key, value):
#     def __getitem__(self, key):
#     def get(self, key, default=None):
#     def __iter__(self):
#     def __next__(self):
#     def next(self):
#     def update(self, values):
#     def iteritems(self):
#     def __init__(self, id, value=None):
#     def __setitem__(self, key, value):
#     def __getitem__(self, key):
#     def get(self, key, default=None):
#     def update(self, values):
#     def get_value(self):
#     def set_value(self, value):
#     def reset_value(self):
#     def __repr__(self):
# def verify_tables(engine):
# def purge_all_tables(engine):
#     def __init__(self, table, query):
#     def _handle_complex_op(self, complex_op, nodes):
#     def _handle_simple_op(self, simple_op, nodes):
#     def _transform(self, sub_tree):
#     def apply_filter(self, expression_tree):
# class Base(six.Iterator):
# class HasId(object):
# class HasTimestamp(object):
# class Torrent(Base, HasId, HasTimestamp):
# class MediaFile(Base, HasId):
# class AppState(Base):
# class QueryTransformer(object):
# 
# Path: seedbox/db/sqlalchemy/session.py
# @property
# def session(self):
#     """Get a Session instance."""
#     return self._session_maker()
# 
# Path: seedbox/tests/test.py
# class ConfiguredBaseTestCase(BaseTestCase):
#     def setUp(self):
#     def tearDown(self):
#     def _make_dir(self, dirname):
#     def set_required_options(self):


# Path: seedbox/tests/db/sqlalchemy/test_model_util.py
from seedbox.db import models as api_model
from seedbox.db.sqlalchemy import model_util
from seedbox.db.sqlalchemy import models as db_model
from seedbox.db.sqlalchemy import session
from seedbox.tests import test

        db_model.purge_all_tables(self.facade.engine)
        super(ModelUtilTestCase, self).tearDown()

    def test_from_db(self):
        self.assertIsNone(model_util.from_db(None))

        _tor = db_model.Torrent()
        _tor['name'] = 'fake.torrent'

        _pub_tor = model_util.from_db(_tor)
        self.assertIsInstance(_pub_tor, api_model.Torrent)

        _mf = db_model.MediaFile()
        _mf['filename'] = 'media.mp4'
        _mf['file_ext'] = '.mp4'
        _mf['torrent_id'] = _tor.id

        _pub_mf = model_util.from_db(_mf)
        self.assertIsInstance(_pub_mf, api_model.MediaFile)

    def test_to_db(self):
        self.assertIsNone(model_util.to_db(None))

        _tor = api_model.Torrent.make_empty()
        _tor.torrent_id = 1
        _tor.name = 'fake.torrent'

        _db_tor = model_util.to_db(_tor)
        self.assertIsInstance(_db_tor, db_model.Torrent)


        _mf = api_model.MediaFile.make_empty()