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:
1 parent
fc8f405801
commit
15b2fbb9e1
3 files changed
+104
-10
No files matched your search
@@ -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'))
|
||||
@@ -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
|
||||
|
||||
Reference in new issue
Block a user