Fix test : do not consider deleted migrations
* Change way to detect deleted migrations (diff-filter of 'git diff' command)
This commit is contained in:
1 parent
fffdf5714e
commit
698e658faa
15 files changed
+46
-14
No files matched your search
@@ -152,8 +152,10 @@ class MigrationLinter(object):
|
||||
def _gather_migrations_git(self, git_commit_id):
|
||||
migrations = []
|
||||
# Get changes since specified commit
|
||||
git_diff_command = 'cd {0} && git diff --name-status {1}'.format(
|
||||
self.django_path, git_commit_id)
|
||||
git_diff_command = (
|
||||
'cd {0} && '
|
||||
'git diff --name-only --diff-filter=A {1}').format(
|
||||
self.django_path, git_commit_id)
|
||||
log.info('Executing {0}'.format(git_diff_command))
|
||||
diff_process = Popen(
|
||||
git_diff_command, shell=True, stdout=PIPE, stderr=PIPE)
|
||||
@@ -161,10 +163,9 @@ class MigrationLinter(object):
|
||||
utils.clean_bytes_to_str, diff_process.stdout.readlines()):
|
||||
# Only gather lines that include added migrations
|
||||
if re.search(
|
||||
'^A.*\/{0}\/.*\.py'.format(self.MIGRATION_FOLDER_NAME),
|
||||
'\/{0}\/.*\.py'.format(self.MIGRATION_FOLDER_NAME),
|
||||
line) and \
|
||||
'__init__' not in line:
|
||||
line = line.split()[-1] # Remove the status letter
|
||||
app_name, migration_name = self._split_migration_path(line)
|
||||
migrations.append((app_name, migration_name))
|
||||
diff_process.wait()
|
||||
|
||||
@@ -116,6 +116,21 @@ class CallLinterFromCommandLineTest(unittest.TestCase):
|
||||
self.assertTrue(lines[2].endswith('IGNORE'))
|
||||
|
||||
def test_call_linter_cmd_line_git_id(self):
|
||||
cmd = '{0} {1} d7125d5f4f0cc9623f670a66c54f131acc50032d'.format(
|
||||
self.linter_exec,
|
||||
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'))
|
||||
|
||||
def test_call_linter_with_deleted_migrations(self):
|
||||
cmd = '{0} {1} 154ecf6119325cc3b1f3f5a4e709bfbd61a4a4ba'.format(
|
||||
self.linter_exec,
|
||||
fixtures.DELETED_MIGRATION_PROJECT)
|
||||
|
||||
@@ -1 +1,16 @@
|
||||
Delete file and insert new
|
||||
|
||||
# Please enter the commit message for your changes. Lines starting
|
||||
# with '#' will be ignored, and an empty message aborts the commit.
|
||||
#
|
||||
# Date: Thu Jan 18 23:27:37 2018 +0100
|
||||
#
|
||||
# On branch master
|
||||
# Changes to be committed:
|
||||
# deleted: test_app/migrations/0002_new_not_null_field.py
|
||||
# new file: test_app/migrations/0003_new_nullable_field.py
|
||||
# modified: test_app/models.py
|
||||
#
|
||||
# Untracked files:
|
||||
# git/
|
||||
#
|
||||
Binary file not shown.
@@ -1,3 +1,4 @@
|
||||
0000000000000000000000000000000000000000 0395cbee60f2ea1b97f42ebdd43991c8f5d8d76e David-Wobrock <david.wobrock@gmail.com> 1516314144 +0100 commit (initial): Project init
|
||||
0395cbee60f2ea1b97f42ebdd43991c8f5d8d76e 154ecf6119325cc3b1f3f5a4e709bfbd61a4a4ba David-Wobrock <david.wobrock@gmail.com> 1516314322 +0100 commit: Add backward incompatible migration
|
||||
154ecf6119325cc3b1f3f5a4e709bfbd61a4a4ba be2fae887ee7ecd2d1e6371af1a865c17414bde9 David-Wobrock <david.wobrock@gmail.com> 1516314457 +0100 commit: Delete file and insert new
|
||||
be2fae887ee7ecd2d1e6371af1a865c17414bde9 4bdc4ba9e7695893423be1b54f3101d6ccbd11c7 David-Wobrock <david.wobrock@gmail.com> 1516459290 +0100 commit (amend): Delete file and insert new
|
||||
@@ -1,3 +1,4 @@
|
||||
0000000000000000000000000000000000000000 0395cbee60f2ea1b97f42ebdd43991c8f5d8d76e David-Wobrock <david.wobrock@gmail.com> 1516314144 +0100 commit (initial): Project init
|
||||
0395cbee60f2ea1b97f42ebdd43991c8f5d8d76e 154ecf6119325cc3b1f3f5a4e709bfbd61a4a4ba David-Wobrock <david.wobrock@gmail.com> 1516314322 +0100 commit: Add backward incompatible migration
|
||||
154ecf6119325cc3b1f3f5a4e709bfbd61a4a4ba be2fae887ee7ecd2d1e6371af1a865c17414bde9 David-Wobrock <david.wobrock@gmail.com> 1516314457 +0100 commit: Delete file and insert new
|
||||
be2fae887ee7ecd2d1e6371af1a865c17414bde9 4bdc4ba9e7695893423be1b54f3101d6ccbd11c7 David-Wobrock <david.wobrock@gmail.com> 1516459290 +0100 commit (amend): Delete file and insert new
|
||||
BIN
Binary file not shown.
BIN
Binary file not shown.
+2
@@ -0,0 +1,2 @@
|
||||
x�ޱ
|
||||
Â0E]íW¼± RAÈ …‚ƒ›{Hš×´ò’H’¢ŸocÄÉñ^Îá^E^A]ïW}ðôU:ã™V0Ú› ¬×H±(:’1±\2;çº:k7‰~DÒÀß0;¹„C›Û2ü&¬fïÂù$þ“ZIñcuƒ/M*B‘0¦ßÑf&–E+‚Й4ðÝv_ž<4Si
|
||||
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
@@ -1 +1 @@
|
||||
be2fae887ee7ecd2d1e6371af1a865c17414bde9
|
||||
4bdc4ba9e7695893423be1b54f3101d6ccbd11c7
|
||||
+5
-8
@@ -1,18 +1,15 @@
|
||||
# Generated by Django 2.0.1 on 2018-01-18 22:26
|
||||
|
||||
from django.db import migrations, models
|
||||
from django.db import migrations
|
||||
from django.db import models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('test_app', '0001_initial'),
|
||||
]
|
||||
dependencies = [('test_app', '0001_initial'),]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='a',
|
||||
name='new_nullable_field',
|
||||
field=models.IntegerField(null=True),
|
||||
name='new_char_nullable_test_field',
|
||||
field=models.CharField(max_length=30, null=True),
|
||||
),
|
||||
]
|
||||
@@ -3,4 +3,4 @@ from django.db import models
|
||||
class A(models.Model):
|
||||
null_field = models.IntegerField(null=True)
|
||||
new_not_null_field = models.IntegerField(null=False)
|
||||
new_nullable_field = models.IntegerField(null=True)
|
||||
new_char_nullable_test_field = models.CharField(max_length=30, null=True)
|
||||
Reference in new issue
Block a user