From 758468cbb8fa26398b7a6c90eabb8bad9d764702 Mon Sep 17 00:00:00 2001 From: Tobias Kroenke Date: Mon, 13 May 2019 10:45:31 +0200 Subject: [PATCH] hopefully correctly test new ignoring mechanism --- tests/functional/test_cache.py | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/tests/functional/test_cache.py b/tests/functional/test_cache.py index 855eba9..8a7d411 100644 --- a/tests/functional/test_cache.py +++ b/tests/functional/test_cache.py @@ -22,6 +22,7 @@ from django_migration_linter import ( MigrationLinter, analyse_sql_statements, get_migration_abspath, + IgnoreMigration, ) if sys.version_info >= (3, 3): @@ -30,6 +31,10 @@ else: import mock +class OperationsIgnoreMigration(Migration): + operations = [IgnoreMigration()] + + class CacheTestCase(unittest.TestCase): def setUp(self): self.test_project_path = os.path.dirname(settings.BASE_DIR) @@ -155,10 +160,10 @@ class CacheTestCase(unittest.TestCase): "django_migration_linter.MigrationLinter._gather_all_migrations", return_value=[ Migration("0001_initial", "app_ignore_migration"), - Migration("0002_ignore_migration", "app_ignore_migration"), + OperationsIgnoreMigration("0002_ignore_migration", "app_ignore_migration"), ], ) - def test_cache_ignored(self, *args): + def test_ignored_via_operation_not_analysed_or_cached(self, *args): linter = MigrationLinter(self.test_project_path, ignore_name_contains="0001") linter.old_cache.clear() linter.old_cache.save() @@ -168,22 +173,12 @@ class CacheTestCase(unittest.TestCase): wraps=analyse_sql_statements, ) as analyse_sql_statements_mock: linter.lint_all_migrations() - self.assertEqual(1, analyse_sql_statements_mock.call_count) + analyse_sql_statements_mock.assert_not_called() cache = linter.new_cache cache.load() - self.assertEqual("IGNORE", cache["0fab48322ba76570da1a3c193abb77b5"]["result"]) - - # Start the Linter again -> should use cache now. - linter = MigrationLinter(self.test_project_path) - - with mock.patch( - "django_migration_linter.migration_linter.analyse_sql_statements", - wraps=analyse_sql_statements, - ) as analyse_sql_statements_mock: - linter.lint_all_migrations() - self.assertEqual(1, analyse_sql_statements_mock.call_count) + self.assertFalse(cache) @mock.patch( "django_migration_linter.MigrationLinter._gather_all_migrations",