def test_simple_script_run_no_discard(settings, mocker):
    root = os.path.dirname(__file__)
    settings.NORTH_MIGRATIONS_ROOT = os.path.join(root, 'test_data/sql')
    settings.NORTH_DISCARD_ALL = False

    mock_simple_run = mocker.patch(
        'django_north.management.runner.SimpleBlock.run')
    mock_run = mocker.patch('django_north.management.runner.Block.run')
    mock_meta_run = mocker.patch(
        'django_north.management.runner.MetaBlock.run')
    mock_discard_run = mocker.patch(
        'django_north.management.runner.DiscardBlock.run')

    # Simple script
    path = os.path.join(settings.NORTH_MIGRATIONS_ROOT,
                        '16.12/16.12-0-version-dml.sql')
    with io.open(path, 'r', encoding='utf8') as f:
        script = Script(f)
    assert len(script.block_list) == 1

    script.run('foo')
    assert mock_simple_run.call_args_list == [mocker.call('foo')]
    assert mock_run.called is False
    assert mock_meta_run.called is False
    # The most important result here: we don't run the discard command.
    assert mock_discard_run.called is False
Beispiel #2
0
    def emit_post_migrate(verbosity, interactive, database, current_version):
        # custom: do what was done on post_migrate
        # clear contenttype cache
        ContentType.objects.clear_cache()

        # reload fixtures
        connection = connections[database]
        fixtures_version = get_fixtures_for_init(current_version)
        fixtures_path = os.path.join(
            settings.NORTH_MIGRATIONS_ROOT, 'fixtures',
            getattr(settings, 'NORTH_FIXTURES_TPL',
                    fixtures_default_tpl).format(fixtures_version))
        with io.open(fixtures_path, 'r', encoding='utf8') as f:
            script = Script(f)
            script.run(connection)
Beispiel #3
0
def test_manual_script_run(settings, mocker):
    root = os.path.dirname(__file__)
    settings.NORTH_MIGRATIONS_ROOT = os.path.join(root, 'test_data/sql')

    mock_simple_run = mocker.patch(
        'django_north.management.runner.SimpleBlock.run')
    mock_run = mocker.patch('django_north.management.runner.Block.run')
    mock_meta_run = mocker.patch(
        'django_north.management.runner.MetaBlock.run')

    # Manual script with metablocks
    path = os.path.join(settings.NORTH_MIGRATIONS_ROOT,
                        '17.01/manual/17.01-feature_a-040-dml.sql')
    with io.open(path, 'r', encoding='utf8') as f:
        script = Script(f)
    assert len(script.block_list) == 3

    script.run('foo')
    assert mock_simple_run.called is False
    assert mock_run.call_args_list == [mocker.call('foo'), mocker.call('foo')]
    assert mock_meta_run.call_args_list == [mocker.call('foo')]
Beispiel #4
0
 def run_script(self, path):
     with io.open(path, 'r', encoding='utf8') as f:
         script = Script(f)
         script.run(self.connection)