# Path: solvebio/test/helper.py
# class SolveBioTestCase(unittest.TestCase):
#     TEST_DATASET_FULL_PATH = 'solvebio:public:/HGNC/3.3.0-2020-10-29/HGNC'
#     TEST_DATASET_FULL_PATH_2 = 'solvebio:public:/ClinVar/5.1.0-20200720/Variants-GRCH38'
#     TEST_FILE_FULL_PATH = 'solvebio:public:/HGNC/3.3.0-2020-10-29/hgnc_1000_rows.txt'
# 
#     def setUp(self):
#         super(SolveBioTestCase, self).setUp()
#         api_key = os.environ.get('SOLVEBIO_API_KEY', None)
#         api_host = os.environ.get('SOLVEBIO_API_HOST', None)
#         self.client = solvebio.SolveClient(host=api_host, token=api_key)
# 
#     def check_response(self, response, expect, msg):
#         subset = [(key, response[key]) for
#                   key in [x[0] for x in expect]]
#         self.assertEqual(subset, expect)
# 
#     # Python < 2.7 compatibility
#     def assertRaisesRegexp(self, exception, regexp, callable, *args, **kwargs):
#         try:
#             callable(*args, **kwargs)
#         except exception as err:
#             if regexp is None:
#                 return True
# 
#             if isinstance(regexp, six.string_types):
#                 regexp = re.compile(regexp)
#             if not regexp.search(str(err)):
#                 raise self.failureException('\'%s\' does not match \'%s\'' %
#                                             (regexp.pattern, str(err)))
#         else:
#             raise self.failureException(
#                 '%s was not raised' % (exception.__name__,))
# 
# Path: solvebio/test/client_mocks.py
# def fake_migration_create(*args, **kwargs):
#     return FakeMigrationResponse(kwargs).create()


import mock
from .helper import SolveBioTestCase
from solvebio.test.client_mocks import fake_migration_create

        source = self.client.Dataset(1)
        target = self.client.Object(2, object_type='dataset')

        query = source\
            .query(limit=10, fields=['my_field'])\
            .filter(my_field=999)
        migration = query.migrate(target=target.id,
                                  commit_mode='overwrite',
                                  follow=False)
        self.assertEqual(migration.source_id, source.id)
        self.assertEqual(migration.target_id, target.id)
        self.assertEqual(migration.commit_mode, 'overwrite')
        self.assertEqual(migration.source_params['filters'],
                         [('my_field', 999)])

    @mock.patch('solvebio.resource.DatasetMigration.create')
    def test_migration_target_dataset_id(self, Create):
        Create.side_effect = fake_migration_create

        source = self.client.Dataset(1)
        target = self.client.Dataset(2)
        migration = source.migrate(target=target.id, follow=False)
        self.assertEqual(migration.source_id, source.id)
        self.assertEqual(migration.target_id, target.id)
        self.assertEqual(migration.commit_mode, 'append')

    @mock.patch('solvebio.resource.DatasetMigration.create')
    def test_migration_target_dataset_dataset(self, Create):
        """Target is a Dataset object"""

# Path: solvebio/test/helper.py
# class SolveBioTestCase(unittest.TestCase):
#     TEST_DATASET_FULL_PATH = 'solvebio:public:/HGNC/3.3.0-2020-10-29/HGNC'
#     TEST_DATASET_FULL_PATH_2 = 'solvebio:public:/ClinVar/5.1.0-20200720/Variants-GRCH38'
#     TEST_FILE_FULL_PATH = 'solvebio:public:/HGNC/3.3.0-2020-10-29/hgnc_1000_rows.txt'
# 
#     def setUp(self):
#         super(SolveBioTestCase, self).setUp()
#         api_key = os.environ.get('SOLVEBIO_API_KEY', None)
#         api_host = os.environ.get('SOLVEBIO_API_HOST', None)
#         self.client = solvebio.SolveClient(host=api_host, token=api_key)
# 
#     def check_response(self, response, expect, msg):
#         subset = [(key, response[key]) for
#                   key in [x[0] for x in expect]]
#         self.assertEqual(subset, expect)
# 
#     # Python < 2.7 compatibility
#     def assertRaisesRegexp(self, exception, regexp, callable, *args, **kwargs):
#         try:
#             callable(*args, **kwargs)
#         except exception as err:
#             if regexp is None:
#                 return True
# 
#             if isinstance(regexp, six.string_types):
#                 regexp = re.compile(regexp)
#             if not regexp.search(str(err)):
#                 raise self.failureException('\'%s\' does not match \'%s\'' %
#                                             (regexp.pattern, str(err)))
#         else:
#             raise self.failureException(
#                 '%s was not raised' % (exception.__name__,))
# 
# Path: solvebio/test/client_mocks.py
# def fake_migration_create(*args, **kwargs):
#     return FakeMigrationResponse(kwargs).create()


# Path: solvebio/test/test_dataset_migrations.py
import mock
from .helper import SolveBioTestCase
from solvebio.test.client_mocks import fake_migration_create


        source = self.client.Dataset(1)
        target = self.client.Object(2, object_type='dataset')

        query = source\
            .query(limit=10, fields=['my_field'])\
            .filter(my_field=999)
        migration = query.migrate(target=target.id,
                                  commit_mode='overwrite',
                                  follow=False)
        self.assertEqual(migration.source_id, source.id)
        self.assertEqual(migration.target_id, target.id)
        self.assertEqual(migration.commit_mode, 'overwrite')
        self.assertEqual(migration.source_params['filters'],
                         [('my_field', 999)])

    @mock.patch('solvebio.resource.DatasetMigration.create')
    def test_migration_target_dataset_id(self, Create):
        Create.side_effect = fake_migration_create

        source = self.client.Dataset(1)
        target = self.client.Dataset(2)
        migration = source.migrate(target=target.id, follow=False)
        self.assertEqual(migration.source_id, source.id)
        self.assertEqual(migration.target_id, target.id)
        self.assertEqual(migration.commit_mode, 'append')

    @mock.patch('solvebio.resource.DatasetMigration.create')
    def test_migration_target_dataset_dataset(self, Create):
        """Target is a Dataset object"""

        Create.side_effect = fake_migration_create