hookmeup

A Git hook to automate your Pipenv and Django workflow
git clone git://git.danielmoch.com/hookmeup.git
Log | Files | Refs | README | LICENSE

commit b6d50752c716138bcccb02cef5de687de6d305d4
parent 4ea727b23fd94f2dffe812abe43d64ee92325f79
Author: Daniel Moch <daniel@danielmoch.com>
Date:   Mon, 20 Aug 2018 22:24:45 -0400

Add tests for Django migration

Diffstat:
Mtests/test_hookmeup.py | 70++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 70 insertions(+), 0 deletions(-)

diff --git a/tests/test_hookmeup.py b/tests/test_hookmeup.py @@ -172,3 +172,73 @@ def test_adjust_pipenv_failure(mocker): ) with pytest.raises(hookmeup.hookmeup.HookMeUpError): hookmeup.hookmeup.adjust_pipenv() + +def test_migrate_up(mocker): + """Test a nominal Django migration""" + completed_process = subprocess.CompletedProcess( + args=['git', 'diff', '--name-status'], + returncode=0, + stdout=b'\ + A app1/migrations/0002_auto.py\n\ + A app2/migrations/0003_test.py\n\ + A other_file.py\n', + stderr=b'' + ) + mocker.patch( + 'subprocess.run', + new=mocker.MagicMock(return_value=completed_process) + ) + +def test_migrate_down(mocker): + """Test a nominal Django migration downgrade""" + completed_process = subprocess.CompletedProcess( + args=['git', 'diff', '--name-status'], + returncode=0, + stdout=b'\ + D app1/migrations/0002_auto.py\n\ + D app2/migrations/0003_test.py\n\ + A other_file.py\n', + stderr=b'' + ) + mocker.patch( + 'subprocess.run', + new=mocker.MagicMock(return_value=completed_process) + ) + +def test_squashed_migrate_up(mocker): + """Test a Django migration upgrade with an intervening squash""" + completed_process = subprocess.CompletedProcess( + args=['git', 'diff', '--name-status'], + returncode=0, + stdout=b'\ + A app1/migrations/0002_auto.py\n\ + A app2/migrations/0003_test.py\n\ + D app3/migrations/0001_initial.py\n\ + D app3/migrations/0002_auto.py\n\ + A app3/migrations/0001_squashed.py\n\ + A other_file.py\n', + stderr=b'' + ) + mocker.patch( + 'subprocess.run', + new=mocker.MagicMock(return_value=completed_process) + ) + +def test_squashed_migrate_down(mocker): + """Test a Django migration downgrade with an intervening squash""" + completed_process = subprocess.CompletedProcess( + args=['git', 'diff', '--name-status'], + returncode=0, + stdout=b'\ + A app1/migrations/0002_auto.py\n\ + A app2/migrations/0003_test.py\n\ + A app3/migrations/0001_initial.py\n\ + A app3/migrations/0002_auto.py\n\ + D app3/migrations/0001_squashed.py\n\ + A other_file.py\n', + stderr=b'' + ) + mocker.patch( + 'subprocess.run', + new=mocker.MagicMock(return_value=completed_process) + )