Skip to content

Commit 358abbc

Browse files
Increased test coverage. (#88)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent fa13ea9 commit 358abbc

File tree

6 files changed

+27
-9
lines changed

6 files changed

+27
-9
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ jobs:
5151
git fetch origin feature/migration-test-02:feature/migration-test-02
5252
git fetch origin feature/migration-test-03:feature/migration-test-03
5353
git fetch origin feature/migration-test-04:feature/migration-test-04
54+
git fetch origin feature/migration-test-05:feature/migration-test-05
5455
working-directory: migration_fixer/tests/demo
5556

5657
- name: Install dependencies

migration_fixer/tests/management/commands/_constants.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,5 @@
77
TEST_03_MIGRATION_BRANCH = "feature/migration-test-03"
88
# Single merge to main after 01 is merged (named module)
99
TEST_04_MIGRATION_BRANCH = "feature/migration-test-04"
10+
# Multiple migrations with a named migration file
11+
TEST_05_MIGRATION_BRANCH = "feature/migration-test-05"

migration_fixer/tests/management/commands/test_makemigrations.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
TEST_02_MIGRATION_BRANCH,
1010
TEST_03_MIGRATION_BRANCH,
1111
TEST_04_MIGRATION_BRANCH,
12+
TEST_05_MIGRATION_BRANCH,
1213
)
1314
from migration_fixer.tests.management.commands._utils import (
1415
execute_command,
@@ -164,7 +165,7 @@ def test_run_makemigrations_with_fix_is_valid_for_multiple_file_conflicts_verbos
164165

165166
@pytest.mark.env("test_04")
166167
@pytest.mark.django_db
167-
def test_run_makemigrations_fix_with_invlaid_module(git_repo):
168+
def test_run_makemigrations_fix_with_an_invalid_module(git_repo):
168169
expected_output = """Error: Unable to fix migration for "demo" app: testmodel_dob.py
169170
NOTE: It needs to begin with a number. eg. 0001_*
170171
"""
@@ -179,3 +180,22 @@ def test_run_makemigrations_fix_with_invlaid_module(git_repo):
179180

180181
assert target_branch.name == TEST_04_MIGRATION_BRANCH
181182
assert expected_output == output
183+
184+
185+
@pytest.mark.env("test_05")
186+
@pytest.mark.django_db
187+
def test_run_makemigrations_fix_with_mixed_invalid_modules(git_repo):
188+
expected_output = """Error: Unable to fix migration for "demo" app: custom_migration.py
189+
NOTE: It needs to begin with a number. eg. 0001_*
190+
"""
191+
cmd = Command(repo=git_repo.api)
192+
193+
with temporary_checkout(
194+
git_repo,
195+
default_branch_name=TEST_01_MIGRATION_BRANCH,
196+
target_branch_name=TEST_05_MIGRATION_BRANCH,
197+
) as target_branch:
198+
output = execute_command(cmd, default_branch=TEST_01_MIGRATION_BRANCH, fix=True)
199+
200+
assert target_branch.name == TEST_05_MIGRATION_BRANCH
201+
assert expected_output == output

migration_fixer/utils.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,7 @@ def fix_numbered_migration(
8383
conflict_path = migration_path / basename
8484
conflict_parts = basename.split("_")
8585

86-
if str(conflict_parts[0]).isdigit():
87-
conflict_parts[0] = next_
88-
else:
89-
raise ValueError(
90-
f'Unable to fix migration: "{conflict_path.name}"\n'
91-
f"NOTE: It needs to begin with a number. eg. 0001_*",
92-
)
86+
conflict_parts[0] = next_
9387

9488
new_conflict_name = "_".join(conflict_parts)
9589

tox.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ commands =
4848
coverage run -a -m pytest --basetemp={envtmpdir} -E test_02
4949
coverage run -a -m pytest --basetemp={envtmpdir} -E test_03
5050
coverage run -a -m pytest --basetemp={envtmpdir} -E test_04
51+
coverage run -a -m pytest --basetemp={envtmpdir} -E test_05
5152
coverage xml
5253

5354
[testenv:flake8]

0 commit comments

Comments
 (0)