Add tests from command line directly

* Test options
* Syntax error fix
* Ajust the commit id for a test (was wrongly set)
This commit is contained in:
David Wobrock committed 2017-11-30 17:44:12 +01:00
1 parent fc8f405801
commit 15b2fbb9e1
3 files changed
+104 -10

No files matched your search

+2 -2
View File
@@ -56,7 +56,7 @@ class MigrationLinter(object):
if self.should_ignore_migration(app_name, migration_name):
print('IGNORE')
self.nb_ignore += 1
self.nb_ignored += 1
return
sql_statements = self.get_sql(
@@ -105,7 +105,7 @@ class MigrationLinter(object):
self.nb_total,
self.nb_valid,
self.nb_erroneous,
self.nb_ignore))
self.nb_ignored))
@property
def has_errors(self):
+101 -1
View File
@@ -1,4 +1,104 @@
import unittest
from subprocess import Popen, PIPE
from django_migration_linter import utils
from tests import fixtures
class CallLinterFromCommandLineTest(unittest.TestCase):
pass
def test_call_linter_cmd_line_working(self):
cmd = 'django-migration-linter {0}'.format(fixtures.CORRECT_PROJECT)
process = Popen(
cmd, shell=True, stdout=PIPE, stderr=PIPE)
process.wait()
self.assertEqual(process.returncode, 0)
lines = list(map(utils.clean_bytes_to_str, process.stdout.readlines()))
self.assertEqual(len(lines), 5)
self.assertTrue(lines[0].endswith('OK'))
self.assertTrue(lines[1].endswith('OK'))
self.assertTrue(lines[2].endswith('OK'))
def test_call_linter_cmd_line_errors(self):
cmd = 'django-migration-linter {0}'.format(
fixtures.ADD_NOT_NULL_COLUMN_PROJECT)
process = Popen(
cmd, shell=True, stdout=PIPE, stderr=PIPE)
process.wait()
self.assertNotEqual(process.returncode, 0)
lines = list(map(utils.clean_bytes_to_str, process.stdout.readlines()))
self.assertEqual(len(lines), 5)
print(lines)
self.assertTrue(lines[0].endswith('OK'))
self.assertTrue(lines[1].endswith('ERR'))
self.assertTrue('RENAMING tables' in lines[2])
def test_call_linter_cmd_line_exclude_apps(self):
cmd = 'django-migration-linter {0} --exclude-apps test_app2'.format(
fixtures.CORRECT_PROJECT)
process = Popen(
cmd, shell=True, stdout=PIPE, stderr=PIPE)
process.wait()
self.assertEqual(process.returncode, 0)
lines = list(map(utils.clean_bytes_to_str, process.stdout.readlines()))
self.assertEqual(len(lines), 5)
self.assertTrue(lines[0].endswith('OK'))
self.assertTrue(lines[1].endswith('OK'))
self.assertTrue(lines[2].endswith('IGNORE'))
def test_call_linter_cmd_line_include_apps(self):
cmd = 'django-migration-linter {0} --include-apps test_app2'.format(
fixtures.CORRECT_PROJECT)
process = Popen(
cmd, shell=True, stdout=PIPE, stderr=PIPE)
process.wait()
self.assertEqual(process.returncode, 0)
lines = list(map(utils.clean_bytes_to_str, process.stdout.readlines()))
self.assertEqual(len(lines), 5)
self.assertTrue(lines[0].endswith('IGNORE'))
self.assertTrue(lines[1].endswith('IGNORE'))
self.assertTrue(lines[2].endswith('OK'))
def test_call_linter_cmd_line_ignore_name(self):
cmd = 'django-migration-linter {0} --ignore-name 0001_initial'.format(
fixtures.CORRECT_PROJECT)
process = Popen(
cmd, shell=True, stdout=PIPE, stderr=PIPE)
process.wait()
self.assertEqual(process.returncode, 0)
lines = list(map(utils.clean_bytes_to_str, process.stdout.readlines()))
self.assertEqual(len(lines), 5)
self.assertTrue(lines[0].endswith('IGNORE'))
self.assertTrue(lines[1].endswith('OK'))
self.assertTrue(lines[2].endswith('OK'))
def test_call_linter_cmd_line_ignore_name_contains(self):
cmd = 'django-migration-linter {0} --ignore-name-contains 0001'.format(
fixtures.CORRECT_PROJECT)
process = Popen(
cmd, shell=True, stdout=PIPE, stderr=PIPE)
process.wait()
self.assertEqual(process.returncode, 0)
lines = list(map(utils.clean_bytes_to_str, process.stdout.readlines()))
self.assertEqual(len(lines), 5)
self.assertTrue(lines[0].endswith('IGNORE'))
self.assertTrue(lines[1].endswith('OK'))
self.assertTrue(lines[2].endswith('IGNORE'))
def test_call_linter_cmd_line_git_id(self):
cmd = 'django-migration-linter {0} d7125d5f4f0cc9623f670a66c54f131acc50032d'.format(
fixtures.MULTI_COMMIT_PROJECT)
fixtures.prepare_git_project(fixtures.MULTI_COMMIT_PROJECT)
process = Popen(
cmd, shell=True, stdout=PIPE, stderr=PIPE)
process.wait()
self.assertEqual(process.returncode, 0)
lines = list(map(utils.clean_bytes_to_str, process.stdout.readlines()))
self.assertEqual(len(lines), 3)
self.assertTrue(lines[0].endswith('OK'))
self.assertTrue(lines[1].startswith('*** Summary'))
+1 -7
View File
@@ -27,33 +27,27 @@ class BackwardcompatibilityDetectionTest(unittest.TestCase):
def test_create_table_with_not_null_column(self):
test_project_path = fixtures.CREATE_TABLE_WITH_NOT_NULL_COLUMN_PROJECT
fixtures.prepare_git_project(test_project_path)
self._test_linter_finds_no_errors(test_project_path)
def test_detect_adding_not_null_column(self):
test_project_path = fixtures.ADD_NOT_NULL_COLUMN_PROJECT
fixtures.prepare_git_project(test_project_path)
self._test_linter_finds_errors(test_project_path)
def test_detect_drop_column(self):
test_project_path = fixtures.DROP_COLUMN_PROJECT
fixtures.prepare_git_project(test_project_path)
self._test_linter_finds_errors(test_project_path)
def test_detect_rename_column(self):
test_project_path = fixtures.RENAME_COLUMN_PROJECT
fixtures.prepare_git_project(test_project_path)
self._test_linter_finds_errors(test_project_path)
def test_detect_rename_table(self):
test_project_path = fixtures.RENAME_TABLE_PROJECT
fixtures.prepare_git_project(test_project_path)
self._test_linter_finds_errors(test_project_path)
def test_accept_not_null_column_followed_by_adding_default(self):
test_project_path = \
fixtures.ADD_NOT_NULL_COLUMN_FOLLOWED_BY_DEFAULT_PROJECT
fixtures.prepare_git_project(test_project_path)
self._test_linter_finds_no_errors(test_project_path)
def test_no_specify_git_hash(self):
@@ -66,7 +60,7 @@ class BackwardcompatibilityDetectionTest(unittest.TestCase):
fixtures.prepare_git_project(test_project_path)
self._test_linter_finds_no_errors(
test_project_path,
commit_id='1021d98b5943db56122c1f848f371ddc38788d0f')
commit_id='d7125d5f4f0cc9623f670a66c54f131acc50032d')
#def test_specify_git_hash_by_tag(self):
# test_project_path = fixtures.MULTI_COMMIT_PROJECT