Пример #1
0
    def test_success(self, monkeypatch, spec, extension, file_type):
        migrate_mock = Mock()
        spec.migrate_config_file = migrate_mock
        spec.update_defaults = Mock()

        remove_mock = Mock()
        monkeypatch.setattr(os, "remove", remove_mock)

        bg_utils.update_config_file(spec,
                                    ["-c", "/path/to/config." + extension])

        expected = Box({
            "log_file": None,
            "log_level": "INFO",
            "log_config": None,
            "configuration": {
                "file": "/path/to/config." + extension
            },
        })
        migrate_mock.assert_called_once_with(
            expected.configuration.file,
            current_file_type=file_type,
            output_file_name=expected.configuration.file,
            output_file_type=file_type,
            update_defaults=True,
            include_bootstrap=False,
        )
        assert remove_mock.called is False
Пример #2
0
    def test_no_file_specified(self, spec):
        migrate_mock = Mock()
        spec.migrate_config_file = migrate_mock

        with pytest.raises(SystemExit):
            bg_utils.update_config_file(spec, [])

        assert migrate_mock.called is False
Пример #3
0
    def test_change_type_error(self, monkeypatch, spec):
        migrate_mock = Mock(side_effect=ValueError)
        spec.migrate_config_file = migrate_mock
        spec.update_defaults = Mock()

        remove_mock = Mock()
        monkeypatch.setattr(os, "remove", remove_mock)

        with pytest.raises(ValueError):
            bg_utils.update_config_file(
                spec, ["-c", "/path/to/config.json", "-t", "yaml"])
        assert remove_mock.called is False
Пример #4
0
    def test_change_type(self, monkeypatch, spec, current_type, new_type):
        migrate_mock = Mock()
        spec.migrate_config_file = migrate_mock
        spec.update_defaults = Mock()

        remove_mock = Mock()
        monkeypatch.setattr(os, "remove", remove_mock)

        bg_utils.update_config_file(
            spec, ["-c", "/path/to/config." + current_type, "-t", new_type])

        migrate_mock.assert_called_once_with(
            "/path/to/config." + current_type,
            current_file_type=current_type,
            output_file_name="/path/to/config." + new_type,
            output_file_type=new_type,
            update_defaults=True,
            include_bootstrap=False,
        )
        remove_mock.assert_called_once_with("/path/to/config." + current_type)
Пример #5
0
def migrate_config():
    spec = YapconfSpec(SPECIFICATION, env_prefix="BG_")
    bg_utils.update_config_file(spec, sys.argv[1:])