authentic/tests/test_migrations.py

52 lines
2.0 KiB
Python

# authentic2 - versatile identity manager
# Copyright (C) 2010-2019 Entr'ouvert
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import mock
from django.db.utils import ProgrammingError
def test_migration_0019_add_user_deleted(transactional_db, migration):
old_apps = migration.before([
('authentic2', '0026_token'),
('custom_user', '0018_user_last_account_deletion_alert'),
])
User = old_apps.get_model('custom_user', 'User')
DeletedUser = old_apps.get_model('authentic2', 'DeletedUser')
user = User.objects.create()
DeletedUser.objects.create(user=user)
new_apps = migration.before([
('authentic2', '0027_remove_deleteduser'),
('custom_user', '0019_add_user_deleted'),
])
NewUser = new_apps.get_model('custom_user', 'User')
new_user = NewUser.objects.get(id=user.id)
assert new_user.deleted
def test_migration_0028_trigram_unaccent_index(transactional_db, migration):
migration.before([('authentic2', '0027_remove_deleteduser')])
def programming_error(*args, **kwargs):
raise ProgrammingError
# when an error occurs, ensure migration runs anyway without complaining
with mock.patch('django.db.backends.postgresql.schema.DatabaseSchemaEditor.execute') as mocked:
mocked.side_effect = programming_error
migration.apply([('authentic2', '0028_trigram_unaccent_index')])