From 698e658faabec08d380c42ef723c9d4766f95643 Mon Sep 17 00:00:00 2001 From: David-Wobrock Date: Sat, 20 Jan 2018 15:50:45 +0100 Subject: [PATCH] Fix test : do not consider deleted migrations * Change way to detect deleted migrations (diff-filter of 'git diff' command) --- django_migration_linter/migration_linter.py | 9 +++++---- tests/functional/test_cmd_line_call.py | 15 +++++++++++++++ .../git/COMMIT_EDITMSG | 15 +++++++++++++++ .../test_deleted_migration_project/git/index | Bin 1581 -> 1581 bytes .../git/logs/HEAD | 1 + .../git/logs/refs/heads/master | 1 + .../20/6a76068032bb321ca63f561a230675d2645182 | Bin 0 -> 136 bytes .../39/0459eae1e9c3eecaac732d51867c8b8ed5102f | Bin 0 -> 239 bytes .../4b/330bb1c7154afb23f170218d170dae079c437f | 2 ++ .../4b/dc4ba9e7695893423be1b54f3101d6ccbd11c7 | Bin 0 -> 183 bytes .../87/39ba2b3bc1f8efddd5806ec429405150505b81 | Bin 0 -> 173 bytes .../fb/cc4dab70fb36389f806bb72fd5056f5034f572 | Bin 0 -> 216 bytes .../git/refs/heads/master | 2 +- .../migrations/0003_new_nullable_field.py | 13 +++++-------- .../test_app/models.py | 2 +- 15 files changed, 46 insertions(+), 14 deletions(-) create mode 100644 tests/test_project_fixtures/test_deleted_migration_project/git/objects/20/6a76068032bb321ca63f561a230675d2645182 create mode 100644 tests/test_project_fixtures/test_deleted_migration_project/git/objects/39/0459eae1e9c3eecaac732d51867c8b8ed5102f create mode 100644 tests/test_project_fixtures/test_deleted_migration_project/git/objects/4b/330bb1c7154afb23f170218d170dae079c437f create mode 100644 tests/test_project_fixtures/test_deleted_migration_project/git/objects/4b/dc4ba9e7695893423be1b54f3101d6ccbd11c7 create mode 100644 tests/test_project_fixtures/test_deleted_migration_project/git/objects/87/39ba2b3bc1f8efddd5806ec429405150505b81 create mode 100644 tests/test_project_fixtures/test_deleted_migration_project/git/objects/fb/cc4dab70fb36389f806bb72fd5056f5034f572 diff --git a/django_migration_linter/migration_linter.py b/django_migration_linter/migration_linter.py index 7ecbf98..00a44eb 100644 --- a/django_migration_linter/migration_linter.py +++ b/django_migration_linter/migration_linter.py @@ -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() diff --git a/tests/functional/test_cmd_line_call.py b/tests/functional/test_cmd_line_call.py index ac62575..a3afd33 100644 --- a/tests/functional/test_cmd_line_call.py +++ b/tests/functional/test_cmd_line_call.py @@ -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) diff --git a/tests/test_project_fixtures/test_deleted_migration_project/git/COMMIT_EDITMSG b/tests/test_project_fixtures/test_deleted_migration_project/git/COMMIT_EDITMSG index 974dd96..e513fa5 100644 --- a/tests/test_project_fixtures/test_deleted_migration_project/git/COMMIT_EDITMSG +++ b/tests/test_project_fixtures/test_deleted_migration_project/git/COMMIT_EDITMSG @@ -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/ +# diff --git a/tests/test_project_fixtures/test_deleted_migration_project/git/index b/tests/test_project_fixtures/test_deleted_migration_project/git/index index b3e362d0e1ceeeda1718673cb37a52dd4f808748..a41e52a9d31bcca1caae10b6449e970defe30e4a 100644 GIT binary patch delta 626 zcmZ3>vzAB2#WTp6fq{Vui20+E1KW(vW!}JOpcoGWAUQdaf>H6SSv4UyXH zG_k}GEERj111trkp;8GG_c(&3YC?a2rGPY4DrK?=BgDiOfd^nYAPtqvn4E%BE_d=4 z#z5=jkgwLvzAB2#WTp6fq{Vui20)e|7NIL7e0W|KrtQ$_LkC#Dwg7jvRn9O2waGQ(h#Zk znG;J4#eur?zZdKP=>pMUDZx(piF+KeOLc6VEW&7sU9MAVatcr`QEq}|!fJ~sC=E4o z$>c4Jf!2xgo+?`>y@*Pbw_@%(X8@Jk!@$tE1jvR0#+uEHna^+jlRw3?*2umPP-$f1yRTZE 1516314144 +0100 commit (initial): Project init 0395cbee60f2ea1b97f42ebdd43991c8f5d8d76e 154ecf6119325cc3b1f3f5a4e709bfbd61a4a4ba David-Wobrock 1516314322 +0100 commit: Add backward incompatible migration 154ecf6119325cc3b1f3f5a4e709bfbd61a4a4ba be2fae887ee7ecd2d1e6371af1a865c17414bde9 David-Wobrock 1516314457 +0100 commit: Delete file and insert new +be2fae887ee7ecd2d1e6371af1a865c17414bde9 4bdc4ba9e7695893423be1b54f3101d6ccbd11c7 David-Wobrock 1516459290 +0100 commit (amend): Delete file and insert new diff --git a/tests/test_project_fixtures/test_deleted_migration_project/git/logs/refs/heads/master b/tests/test_project_fixtures/test_deleted_migration_project/git/logs/refs/heads/master index 236e554..5377828 100644 --- a/tests/test_project_fixtures/test_deleted_migration_project/git/logs/refs/heads/master +++ b/tests/test_project_fixtures/test_deleted_migration_project/git/logs/refs/heads/master @@ -1,3 +1,4 @@ 0000000000000000000000000000000000000000 0395cbee60f2ea1b97f42ebdd43991c8f5d8d76e David-Wobrock 1516314144 +0100 commit (initial): Project init 0395cbee60f2ea1b97f42ebdd43991c8f5d8d76e 154ecf6119325cc3b1f3f5a4e709bfbd61a4a4ba David-Wobrock 1516314322 +0100 commit: Add backward incompatible migration 154ecf6119325cc3b1f3f5a4e709bfbd61a4a4ba be2fae887ee7ecd2d1e6371af1a865c17414bde9 David-Wobrock 1516314457 +0100 commit: Delete file and insert new +be2fae887ee7ecd2d1e6371af1a865c17414bde9 4bdc4ba9e7695893423be1b54f3101d6ccbd11c7 David-Wobrock 1516459290 +0100 commit (amend): Delete file and insert new diff --git a/tests/test_project_fixtures/test_deleted_migration_project/git/objects/20/6a76068032bb321ca63f561a230675d2645182 b/tests/test_project_fixtures/test_deleted_migration_project/git/objects/20/6a76068032bb321ca63f561a230675d2645182 new file mode 100644 index 0000000000000000000000000000000000000000..40a0fd72288df09ba30d2e972055fa35f666b706 GIT binary patch literal 136 zcmV;30C)d*0V^p=O;s>7He)a}FfcPQQ7|wtFpSU4%Ph%E%+V{TWYE5ETwZP2{onr- zAJnWZ!?Se4cXiEud?O` qn0zgQ>WT-O9v=@<_H6E>*_$q2bN24mTvr}-5HDfR|FfcPQQHYPv%*!l^kJl@xWOz3B(d zXRX2%krtd}m%UX!-NXP06mm1uixNvR^Ye-s6tc?L8jN-u$t<%ElTv0Yy_6Ez1T`l& zKP5E>Y?8Mz_r~L*UcZ$;7AW?L^R8o`<6I9_RFYa;0#;M=l=;xz>ANZ->+`=ou{1O) pH7))IRa2IkS`Jn-@s-OWiQkvLa5!^DYS^<#o>b(t0{|*MV-k}Ha3}x( literal 0 HcmV?d00001 diff --git a/tests/test_project_fixtures/test_deleted_migration_project/git/objects/4b/330bb1c7154afb23f170218d170dae079c437f b/tests/test_project_fixtures/test_deleted_migration_project/git/objects/4b/330bb1c7154afb23f170218d170dae079c437f new file mode 100644 index 0000000..d261e11 --- /dev/null +++ b/tests/test_project_fixtures/test_deleted_migration_project/git/objects/4b/330bb1c7154afb23f170218d170dae079c437f @@ -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 \ No newline at end of file diff --git a/tests/test_project_fixtures/test_deleted_migration_project/git/objects/4b/dc4ba9e7695893423be1b54f3101d6ccbd11c7 b/tests/test_project_fixtures/test_deleted_migration_project/git/objects/4b/dc4ba9e7695893423be1b54f3101d6ccbd11c7 new file mode 100644 index 0000000000000000000000000000000000000000..4b414329e06d85a1b4a1a695c0c20df9ba984357 GIT binary patch literal 183 zcmV;o07(CM0hNwHPQ)+_MOo(*-XlhF;plPjX(|(9^e&|21&c3% zNoO0SNS=_1N!ak`cxxT5{8jVQOOxKxJDl?mp67GiNX~FfcPQQP4}zEXhpI%P&f0NS>~6S+o4xGho5 literal 0 HcmV?d00001 diff --git a/tests/test_project_fixtures/test_deleted_migration_project/git/objects/fb/cc4dab70fb36389f806bb72fd5056f5034f572 b/tests/test_project_fixtures/test_deleted_migration_project/git/objects/fb/cc4dab70fb36389f806bb72fd5056f5034f572 new file mode 100644 index 0000000000000000000000000000000000000000..5807b0bd305a2bcc4a4426bea3387455ffffbe82 GIT binary patch literal 216 zcmV;}04M)=0d-G1Yr`-Q?yO&Nn`|&fCD5Uup%l7x>lT7ITNg(`FC>NZ=Qonmq%HKO z}i)ylDMq$m;HP zY=l}+d2}Q>^5NHQMLnI>e88mq$y%H&sn%v+z5WOqCSCh^e7$JaK!=~ol3&U}Zo~l9 SM}DLe_4l~zx?^7<7;y?WPir~= literal 0 HcmV?d00001 diff --git a/tests/test_project_fixtures/test_deleted_migration_project/git/refs/heads/master b/tests/test_project_fixtures/test_deleted_migration_project/git/refs/heads/master index 953a67e..c422dbc 100644 --- a/tests/test_project_fixtures/test_deleted_migration_project/git/refs/heads/master +++ b/tests/test_project_fixtures/test_deleted_migration_project/git/refs/heads/master @@ -1 +1 @@ -be2fae887ee7ecd2d1e6371af1a865c17414bde9 +4bdc4ba9e7695893423be1b54f3101d6ccbd11c7 diff --git a/tests/test_project_fixtures/test_deleted_migration_project/test_app/migrations/0003_new_nullable_field.py b/tests/test_project_fixtures/test_deleted_migration_project/test_app/migrations/0003_new_nullable_field.py index b30169e..fbcc4da 100644 --- a/tests/test_project_fixtures/test_deleted_migration_project/test_app/migrations/0003_new_nullable_field.py +++ b/tests/test_project_fixtures/test_deleted_migration_project/test_app/migrations/0003_new_nullable_field.py @@ -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), ), ] diff --git a/tests/test_project_fixtures/test_deleted_migration_project/test_app/models.py b/tests/test_project_fixtures/test_deleted_migration_project/test_app/models.py index 928f993..4b330bb 100644 --- a/tests/test_project_fixtures/test_deleted_migration_project/test_app/models.py +++ b/tests/test_project_fixtures/test_deleted_migration_project/test_app/models.py @@ -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)