Skip to content

Commit

Permalink
WIP: fixing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Filienko committed Apr 25, 2024
1 parent 6b2a56b commit bcc7f5f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
2 changes: 1 addition & 1 deletion migrations/migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def get_previous_migration_id(self, filename: str) -> str:
for line in migration_file:
match = re.match(r"# Previous version: (.+)", line)
if match:
prev_migration_id = match.group(1)
prev_migration_id = match.group(1) if match != 'None' else None
break
return prev_migration_id

Expand Down
15 changes: 8 additions & 7 deletions tests/migration_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ def test_build_migration_sequence_with_dependencies(mock_get_previous_migration_
with patch.object(Migration, 'get_migration_files', return_value=mock_filenames):
# Mock the output of get_previous_migration_id
mock_get_previous_migration_id.side_effect = {
'migration2.py': 'migration1',
'migration3.py': 'migration2',
'migration1.py': None
'migration2': 'migration1',
'migration3': 'migration2',
'migration1': None
}.get

# Instantiate YourClass
Expand All @@ -51,16 +51,17 @@ def test_build_migration_sequence_with_circular_dependency(mock_get_previous_mig
with patch.object(Migration, 'get_migration_files', return_value=mock_filenames):
# Mock the output of get_previous_migration_id to create circular dependency
mock_get_previous_migration_id.side_effect = {
'migration2.py': 'migration1',
'migration1.py': 'migration2'
'migration2': 'migration1',
'migration1': 'migration2'
}.get

# Instantiate YourClass
your_instance = Migration()

# Call the method to test
with pytest.raises(ValueError):
# Call the method to test and assert the raised ValueError with the expected message
with pytest.raises(ValueError) as exc_info:
your_instance.build_migration_sequence()
assert str(exc_info.value) == "Cycle detected in migration sequence for migration1.py"

def test_build_migration_sequence(migration_instance):
migration_sequence = migration_instance.build_migration_sequence()
Expand Down

0 comments on commit bcc7f5f

Please sign in to comment.