Update Tests:

* don't use the project fixtures anymore but the one Django project
* update and refactor cache tests to be less brittle
* explicitly test mysql, postgresql and sqlite3 databases
* remove 'multiple_call' tests since it is not possible anymore
(with the Django singleton)
* update Travis and tox (dropping Python 3.4)
This commit is contained in:
David Wobrock committed 2019-05-12 15:32:57 +02:00
1 parent f35c9177f4
commit 5390fd507f
9 files changed
+303 -668

No files matched your search

+59 -62
View File
@@ -11,100 +11,97 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import os
import unittest
from django.conf import settings
from django_migration_linter import MigrationLinter
from tests import fixtures
class BaseBackwardCompatibilityDetection(object):
def tearDown(self, *args, **kwargs):
fixtures.clear_all_git_projects()
super(
BaseBackwardCompatibilityDetection,
self).tearDown(*args, **kwargs)
def setUp(self, *args, **kwargs):
self.test_project_path = os.path.dirname(settings.BASE_DIR)
return super(BaseBackwardCompatibilityDetection, self).setUp(*args, **kwargs)
def _test_linter_finds_errors(self, path, commit_id=None):
linter = MigrationLinter(path, database=self.DATABASE, no_cache=True)
linter.lint_all_migrations(git_commit_id=commit_id)
def _test_linter_finds_errors(self, app=None, commit_id=None):
linter = self._launch_linter(app, commit_id)
self.assertTrue(linter.has_errors)
self.assertNotEqual(linter.nb_valid + linter.nb_erroneous, 0)
def _test_linter_finds_no_errors(self, path, commit_id=None):
linter = MigrationLinter(path, database=self.DATABASE, no_cache=True)
linter.lint_all_migrations(git_commit_id=commit_id)
def _test_linter_finds_no_errors(self, app=None, commit_id=None):
linter = self._launch_linter(app, commit_id)
self.assertFalse(linter.has_errors)
self.assertNotEqual(linter.nb_valid + linter.nb_erroneous, 0)
def _launch_linter(self, app=None, commit_id=None):
if app is not None:
app = [app]
linter = MigrationLinter(
self.test_project_path,
include_apps=app,
database=next(iter(self.databases)),
no_cache=True,
)
linter.lint_all_migrations(git_commit_id=commit_id)
return linter
# *** Tests ***
def test_create_table_with_not_null_column(self):
test_project_path = fixtures.CREATE_TABLE_WITH_NOT_NULL_COLUMN_PROJECT
self._test_linter_finds_no_errors(test_project_path)
app = fixtures.CREATE_TABLE_WITH_NOT_NULL_COLUMN
self._test_linter_finds_no_errors(app)
def test_detect_adding_not_null_column(self):
test_project_path = fixtures.ADD_NOT_NULL_COLUMN_PROJECT
self._test_linter_finds_errors(test_project_path)
app = fixtures.ADD_NOT_NULL_COLUMN
self._test_linter_finds_errors(app)
def test_detect_drop_column(self):
test_project_path = fixtures.DROP_COLUMN_PROJECT
self._test_linter_finds_errors(test_project_path)
app = fixtures.DROP_COLUMN
self._test_linter_finds_errors(app)
def test_detect_rename_column(self):
test_project_path = fixtures.RENAME_COLUMN_PROJECT
self._test_linter_finds_errors(test_project_path)
app = fixtures.RENAME_COLUMN
self._test_linter_finds_errors(app)
def test_detect_rename_table(self):
test_project_path = fixtures.RENAME_TABLE_PROJECT
self._test_linter_finds_errors(test_project_path)
app = fixtures.RENAME_TABLE
self._test_linter_finds_errors(app)
def test_ignore_migration(self):
test_project_path = fixtures.IGNORE_MIGRATION_PROJECT
self._test_linter_finds_no_errors(test_project_path)
app = fixtures.IGNORE_MIGRATION
self._test_linter_finds_no_errors(app)
def test_accept_not_null_column_followed_by_adding_default(self):
test_project_path = \
fixtures.ADD_NOT_NULL_COLUMN_FOLLOWED_BY_DEFAULT_PROJECT
self._test_linter_finds_no_errors(test_project_path)
app = fixtures.ADD_NOT_NULL_COLUMN_FOLLOWED_BY_DEFAULT
self._test_linter_finds_no_errors(app)
def test_detect_alter_column(self):
test_project_path = fixtures.ALTER_COLUMN_PROJECT
self._test_linter_finds_errors(test_project_path)
app = fixtures.ALTER_COLUMN
self._test_linter_finds_errors(app)
def test_no_specify_git_hash(self):
test_project_path = fixtures.MULTI_COMMIT_PROJECT
fixtures.prepare_git_project(test_project_path)
self._test_linter_finds_errors(test_project_path, commit_id=None)
def test_specify_git_hash_by_commit_hash(self):
test_project_path = fixtures.MULTI_COMMIT_PROJECT
fixtures.prepare_git_project(test_project_path)
self._test_linter_finds_no_errors(
test_project_path,
commit_id='d7125d5f4f0cc9623f670a66c54f131acc50032d')
#def test_specify_git_hash_by_tag(self):
# test_project_path = fixtures.MULTI_COMMIT_PROJECT
# fixtures.prepare_git_project(test_project_path)
# self._test_linter_finds_no_errors(test_project_path, commit_id='tag1')
def test_with_git_ref(self):
self._test_linter_finds_errors(commit_id="v0.1.4")
class MySqlBackwardCompatibilityDetectionTest(unittest.TestCase, BaseBackwardCompatibilityDetection):
DATABASE = "mysql"
class SqliteBackwardCompatibilityDetectionTest(unittest.TestCase, BaseBackwardCompatibilityDetection):
DATABASE = "sqlite"
class SqliteBackwardCompatibilityDetectionTestCase(
BaseBackwardCompatibilityDetection, unittest.TestCase
):
databases = ["sqlite"]
def test_accept_not_null_column_followed_by_adding_default(self):
test_project_path = \
fixtures.ADD_NOT_NULL_COLUMN_FOLLOWED_BY_DEFAULT_PROJECT
self._test_linter_finds_errors(test_project_path)
def test_specify_git_hash_by_commit_hash(self):
test_project_path = fixtures.MULTI_COMMIT_PROJECT
fixtures.prepare_git_project(test_project_path)
self._test_linter_finds_errors(
test_project_path,
commit_id='d7125d5f4f0cc9623f670a66c54f131acc50032d')
app = fixtures.ADD_NOT_NULL_COLUMN_FOLLOWED_BY_DEFAULT
self._test_linter_finds_errors(app)
class PostgresqlBackwardCompatibilityDetectionTest(unittest.TestCase, BaseBackwardCompatibilityDetection):
DATABASE = "postgresql"
class MySqlBackwardCompatibilityDetectionTestCase(
BaseBackwardCompatibilityDetection, unittest.TestCase
):
databases = ["mysql"]
class PostgresqlBackwardCompatibilityDetectionTestCase(
BaseBackwardCompatibilityDetection, unittest.TestCase
):
databases = ["postgresql"]