heads_path = _get_active_head_file_path(config)
with open(heads_path, 'w+') as f:
f.write('\n'.join(heads))
+ if _use_separate_migration_branches(config):
+ old_head_file = _get_head_file_path(config)
+ if os.path.exists(old_head_file):
+ os.remove(old_head_file)
def add_command_parsers(subparsers):
mock_open.return_value.read.return_value = (
'\n'.join(file_heads))
- with mock.patch('os.path.isfile') as is_file:
- is_file.return_value = bool(file_heads)
-
- if all(head in file_heads for head in heads):
- cli.validate_heads_file(fake_config)
- else:
- self.assertRaises(
- SystemExit,
- cli.validate_heads_file,
- fake_config
- )
- self.mock_alembic_err.assert_called_once_with(mock.ANY)
+ if all(head in file_heads for head in heads):
+ cli.validate_heads_file(fake_config)
+ else:
+ self.assertRaises(
+ SystemExit,
+ cli.validate_heads_file,
+ fake_config
+ )
+ self.assertTrue(self.mock_alembic_err.called)
+
if branchless:
mock_open.assert_called_with(
cli._get_head_file_path(fake_config))
else:
mock_open.assert_called_with(
cli._get_heads_file_path(fake_config))
+
fc.assert_called_once_with(fake_config)
def test_validate_heads_file_multiple_heads(self):
)
self.mock_alembic_err.assert_called_once_with(mock.ANY)
- def test_update_heads_file_success(self):
+ @mock.patch('os.path.exists')
+ @mock.patch('os.remove')
+ def test_update_heads_file_success(self, *os_mocks):
with mock.patch('alembic.script.ScriptDirectory.from_config') as fc:
heads = ('a', 'b')
fc.return_value.get_heads.return_value = heads
mock_open.return_value.write.assert_called_once_with(
'\n'.join(heads))
+ old_head_file = cli._get_head_file_path(self.configs[0])
+ for mock_ in os_mocks:
+ mock_.assert_called_with(old_head_file)
+
def test_get_project_base(self):
config = alembic_config.Config()
config.set_main_option('script_location', 'a.b.c:d')