示例#1
0
    def _test_validate_heads_file_helper(self, heads, file_heads=None,
                                         branchless=False):
        if file_heads is None:
            file_heads = []
        fake_config = FakeConfig()
        with mock.patch('alembic.script.ScriptDirectory.from_config') as fc:
            fc.return_value.get_heads.return_value = heads
            with mock.patch('six.moves.builtins.open') as mock_open:
                mock_open.return_value.__enter__ = lambda s: s
                mock_open.return_value.__exit__ = mock.Mock()
                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 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_helper(self, heads, file_heads=None,
                                         branchless=False):
        if file_heads is None:
            file_heads = []
        fake_config = self.configs[0]
        with mock.patch('alembic.script.ScriptDirectory.from_config') as fc,\
                mock.patch.object(cli, '_use_separate_migration_branches',
                                  return_value=not branchless):
            fc.return_value.get_heads.return_value = heads
            with mock.patch.object(cli, 'open') as mock_open:
                mock_open.return_value.__enter__ = lambda s: s
                mock_open.return_value.__exit__ = mock.Mock()
                mock_open.return_value.read.return_value = (
                    '\n'.join(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.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)
示例#3
0
    def _test_validate_heads_file_helper(self, heads, file_heads=None,
                                         branchless=False):
        if file_heads is None:
            file_heads = []
        fake_config = self.configs[0]
        with mock.patch('alembic.script.ScriptDirectory.from_config') as fc,\
                mock.patch.object(cli, '_use_separate_migration_branches',
                                  return_value=not branchless):
            fc.return_value.get_heads.return_value = heads
            with mock.patch('six.moves.builtins.open') as mock_open:
                mock_open.return_value.__enter__ = lambda s: s
                mock_open.return_value.__exit__ = mock.Mock()
                mock_open.return_value.read.return_value = (
                    '\n'.join(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.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)
示例#4
0
    def _test_validate_heads_file_helper(self,
                                         heads,
                                         file_heads=None,
                                         branchless=False):
        if file_heads is None:
            file_heads = []
        fake_config = FakeConfig()
        with mock.patch('alembic.script.ScriptDirectory.from_config') as fc:
            fc.return_value.get_heads.return_value = heads
            with mock.patch('six.moves.builtins.open') as mock_open:
                mock_open.return_value.__enter__ = lambda s: s
                mock_open.return_value.__exit__ = mock.Mock()
                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 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)
示例#5
0
    def _test_validate_heads_file_helper(self, heads, file_content=None):
        with mock.patch("alembic.script.ScriptDirectory.from_config") as fc:
            fc.return_value.get_heads.return_value = heads
            fc.return_value.get_current_head.return_value = heads[0]
            with mock.patch("six.moves.builtins.open") as mock_open:
                mock_open.return_value.__enter__ = lambda s: s
                mock_open.return_value.__exit__ = mock.Mock()
                mock_open.return_value.read.return_value = file_content

                with mock.patch("os.path.isfile") as is_file:
                    is_file.return_value = file_content is not None

                    if file_content in heads:
                        cli.validate_heads_file(mock.sentinel.config)
                    else:
                        self.assertRaises(SystemExit, cli.validate_heads_file, mock.sentinel.config)
                        self.mock_alembic_err.assert_called_once_with(mock.ANY)
            fc.assert_called_once_with(mock.sentinel.config)
示例#6
0
    def _test_validate_heads_file_helper(self, heads, file_content=None):
        with mock.patch('alembic.script.ScriptDirectory.from_config') as fc:
            fc.return_value.get_heads.return_value = heads
            fc.return_value.get_current_head.return_value = heads[0]
            with mock.patch('six.moves.builtins.open') as mock_open:
                mock_open.return_value.__enter__ = lambda s: s
                mock_open.return_value.__exit__ = mock.Mock()
                mock_open.return_value.read.return_value = file_content

                with mock.patch('os.path.isfile') as is_file:
                    is_file.return_value = file_content is not None

                    if file_content in heads:
                        cli.validate_heads_file(mock.sentinel.config)
                    else:
                        self.assertRaises(
                            SystemExit,
                            cli.validate_heads_file,
                            mock.sentinel.config
                        )
                        self.mock_alembic_err.assert_called_once_with(mock.ANY)
            fc.assert_called_once_with(mock.sentinel.config)