# Path: django_sharding_library/exceptions.py
# class InvalidMigrationException(DjangoShardingException):
#     pass


from unittest import skip
from django.core.management import call_command
from django.test import TestCase
from mock import patch
from django_sharding_library.exceptions import InvalidMigrationException




@patch('django.core.management.commands.migrate.Command.handle')
class MigrationCommandTestCase(TestCase):
    databases = '__all__'

    def test_defauls_migrates_all_primary_dbs(self, mock_migrate_command):
        call_command('migrate', verbosity=0)
        databases_migrated = [call[1].get('database') for call in mock_migrate_command.call_args_list]
        expected_migrated_databases = ['app_shard_001', 'app_shard_002', 'app_shard_003', 'app_shard_004', 'default']

        self.assertEqual(sorted(databases_migrated), expected_migrated_databases)

    def test_all_option_added_to_databases(self, mock_migrate_command):
        call_command('migrate', database='all', verbosity=0)
        databases_migrated = [call[1].get('database') for call in mock_migrate_command.call_args_list]
        expected_migrated_databases = ['app_shard_001', 'app_shard_002', 'app_shard_003', 'app_shard_004', 'default']

        self.assertEqual(sorted(databases_migrated), expected_migrated_databases)

    def test_migrate_single_db(self, mock_migrate_command):
        call_command('migrate', database='default', verbosity=0)
        databases_migrated = [call[1].get('database') for call in mock_migrate_command.call_args_list]
        expected_migrated_databases = ['default']

        self.assertEqual(sorted(databases_migrated), expected_migrated_databases)

    def test_migrate_replica_raises_exception(self, mock_migrate_command):

# Path: django_sharding_library/exceptions.py
# class InvalidMigrationException(DjangoShardingException):
#     pass


# Path: tests/test_migration_command.py
from unittest import skip
from django.core.management import call_command
from django.test import TestCase
from mock import patch
from django_sharding_library.exceptions import InvalidMigrationException





@patch('django.core.management.commands.migrate.Command.handle')
class MigrationCommandTestCase(TestCase):
    databases = '__all__'

    def test_defauls_migrates_all_primary_dbs(self, mock_migrate_command):
        call_command('migrate', verbosity=0)
        databases_migrated = [call[1].get('database') for call in mock_migrate_command.call_args_list]
        expected_migrated_databases = ['app_shard_001', 'app_shard_002', 'app_shard_003', 'app_shard_004', 'default']

        self.assertEqual(sorted(databases_migrated), expected_migrated_databases)

    def test_all_option_added_to_databases(self, mock_migrate_command):
        call_command('migrate', database='all', verbosity=0)
        databases_migrated = [call[1].get('database') for call in mock_migrate_command.call_args_list]
        expected_migrated_databases = ['app_shard_001', 'app_shard_002', 'app_shard_003', 'app_shard_004', 'default']

        self.assertEqual(sorted(databases_migrated), expected_migrated_databases)

    def test_migrate_single_db(self, mock_migrate_command):
        call_command('migrate', database='default', verbosity=0)
        databases_migrated = [call[1].get('database') for call in mock_migrate_command.call_args_list]
        expected_migrated_databases = ['default']

        self.assertEqual(sorted(databases_migrated), expected_migrated_databases)

    def test_migrate_replica_raises_exception(self, mock_migrate_command):

        with self.assertRaises(InvalidMigrationException):