# 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/api.py
# LOG = logging.getLogger(__name__)
# class Connection(base.Connection):
#     def __init__(self, conf):
#     def upgrade(self):
#     def clear(self):
#     def backup(self):
#     def shrink_db(self):
#     def save(self, instance):
#     def bulk_create(self, instances):
#     def bulk_update(self, value_map, entity_type, qfilter):
#     def delete_by(self, entity_type, qfilter):
#     def delete(self, instance):
#     def fetch_by(self, entity_type, qfilter):
#     def fetch(self, entity_type, pk):
# 
# 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/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 api
from seedbox.db.sqlalchemy import models as db_model
from seedbox.tests import test

        _saved_torrent = self.dbconn.save(torrent)
        self.assertIsInstance(_saved_torrent, api_model.Torrent)

        self.assertIsNone(torrent.created_at)
        self.assertIsNotNone(_saved_torrent.created_at)

        _saved_torrent.state = 'active'
        torrent = self.dbconn.save(_saved_torrent)
        # self.assertIsNotNone(torrent.updated_at)
        self.assertIsNone(_saved_torrent.updated_at)

    def test_bulk_create(self):

        torrent = api_model.Torrent(torrent_id=None, name='fake2.torrent')
        torrent = self.dbconn.save(torrent)

        _medias = []
        for i in range(1, 11):
            media = api_model.MediaFile.make_empty()
            media.filename = 'movie-{0}.mp4'.format(i)
            media.file_ext = '.mp4'
            media.file_path = '/tmp/media'
            media.torrent_id = torrent.torrent_id
            _medias.append(media)
        _results = self.dbconn.bulk_create(_medias)
        self.assertEqual(len(list(_results)), 10)

    def test_bulk_update(self):


# 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/api.py
# LOG = logging.getLogger(__name__)
# class Connection(base.Connection):
#     def __init__(self, conf):
#     def upgrade(self):
#     def clear(self):
#     def backup(self):
#     def shrink_db(self):
#     def save(self, instance):
#     def bulk_create(self, instances):
#     def bulk_update(self, value_map, entity_type, qfilter):
#     def delete_by(self, entity_type, qfilter):
#     def delete(self, instance):
#     def fetch_by(self, entity_type, qfilter):
#     def fetch(self, entity_type, pk):
# 
# 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/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_api.py
from seedbox.db import models as api_model
from seedbox.db.sqlalchemy import api
from seedbox.db.sqlalchemy import models as db_model
from seedbox.tests import test


        _saved_torrent = self.dbconn.save(torrent)
        self.assertIsInstance(_saved_torrent, api_model.Torrent)

        self.assertIsNone(torrent.created_at)
        self.assertIsNotNone(_saved_torrent.created_at)

        _saved_torrent.state = 'active'
        torrent = self.dbconn.save(_saved_torrent)
        # self.assertIsNotNone(torrent.updated_at)
        self.assertIsNone(_saved_torrent.updated_at)

    def test_bulk_create(self):

        torrent = api_model.Torrent(torrent_id=None, name='fake2.torrent')
        torrent = self.dbconn.save(torrent)

        _medias = []
        for i in range(1, 11):
            media = api_model.MediaFile.make_empty()
            media.filename = 'movie-{0}.mp4'.format(i)
            media.file_ext = '.mp4'
            media.file_path = '/tmp/media'
            media.torrent_id = torrent.torrent_id
            _medias.append(media)
        _results = self.dbconn.bulk_create(_medias)
        self.assertEqual(len(list(_results)), 10)

    def test_bulk_update(self):


        torrent = api_model.Torrent(torrent_id=None, name='fake3.torrent')