Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
migration_mock = mocker.Mock()
migration_mock.app_label = "app"
migration_mock2 = mocker.Mock()
migration_mock2.app_label = "app2"
mock_loader.return_value.graph.nodes = {
"app": migration_mock,
"app2": migration_mock2,
}
app_config_mock = mocker.Mock()
app_config_mock.label = "app"
errors = checks.check_migrations_applied([app_config_mock])
assert len(errors) == 1
assert errors[0].id == health.WARNING_UNAPPLIED_MIGRATION
mock_loader.return_value.migrated_apps = ["app"]
errors = checks.check_migrations_applied([])
assert len(errors) == 1
assert errors[0].id == health.WARNING_UNAPPLIED_MIGRATION
mock_loader.return_value.applied_migrations = ["app"]
errors = checks.check_migrations_applied([])
assert len(errors) == 0
def test_check_migrations_applied_cannot_check_migrations(exception, mocker):
mocker.patch("django.db.migrations.loader.MigrationLoader", side_effect=exception)
errors = checks.check_migrations_applied([])
assert len(errors) == 1
assert errors[0].id == health.INFO_CANT_CHECK_MIGRATIONS