Example #1
0
def test_migrate_command_with_django_table(django_db_setup_no_init, settings):
    """
    This test simulate the case when a project
    was created to be used with django migrations table
    Either because it didn't use septentrion-based django-north,
    or a pre septentrion-base django-north version.
    """
    connection = connections['no_init']

    # We begin with an empty database
    assert migrations.get_current_version(connection) is None

    # We simulate the setup of the database in the past,
    # with a django_migrations table.
    updated_settings = septentrion_settings(connection)
    updated_settings.update({
        "target_version": "1.0",
        "table": "django_migrations",
    })
    septentrion.migrate(**updated_settings)

    # DB is initialized, this doesn't return None
    assert migrations.get_current_version(connections['no_init']) is not None

    # and migrate to newer version
    call_command('migrate', '--database', 'no_init')

    # check if max applied version is target version
    assert settings.NORTH_TARGET_VERSION != "1.0"
    assert (migrations.get_applied_versions(
        connections['no_init'])[-1] == settings.NORTH_TARGET_VERSION)
def test_get_applied_versions(mocker):
    mocker.patch('septentrion.get_known_versions',
                 return_value=['1.0', '1.1', '1.2', '1.3', '1.10'])

    recorder = migrations.MigrationRecorder(connection)
    recorder.record_applied('1.10', 'fake-ddl.sql')
    result = migrations.get_applied_versions(connection)
    assert result == ['1.0', '1.1', '1.2', '1.3', '1.10']
Example #3
0
def test_migrate_command_for_real(django_db_setup_no_init, settings):
    # from scratch, septentrion will create a migrations table itself

    # if DB is not initialized, this return None
    assert migrations.get_current_version(connections['no_init']) is None

    call_command('migrate', '--database', 'no_init')

    assert migrations.get_current_version(connections['no_init']) is not None

    # check if max applied version is target version
    assert (migrations.get_applied_versions(
        connections['no_init'])[-1] == settings.NORTH_TARGET_VERSION)