Exemple #1
0
    def test_autofix_eol(self, project_loader):
        project_loader("autofix_eol")

        history = (
            PropertyMigration("docker.compose.network_name",
                              "jsonnet.docker.compose.network_name",
                              since="v1.6.0"),
            PropertyMigration("docker.port_prefix",
                              "jsonnet.docker.expose.port_prefix",
                              since="v1.6.0"),
        )

        migrations.set_history(history)

        features.register(FileFeature())
        features.register(JinjaFeature())
        load_registered_features()
        register_actions_in_event_bus(True)

        action = FileWalkAction()
        action.initialize()
        action.execute()

        with open('docker-compose.properties', 'r') as f:
            rendered = f.read()

        with open('docker-compose.expected.properties', 'r') as f:
            expected = f.read()

        assert rendered == expected
    def test_compat_deep_merge(self, caplog: LogCaptureFixture):
        history = (PropertyMigration("some.namespace.old_property",
                                     "another.namespace.new_property"), )

        migrations.set_history(history)

        data = MigrationsDotty()
        data["another.namespace.new_property"] = "value"
        data["some.namespace.another"] = "foo"

        assert data.get("some.namespace.another") == "foo"
        assert data.get("some.namespace.old_property") == "value"
        assert data.get("another.namespace.new_property") == "value"

        assert data.get("some").get("namespace").get("another") == "foo"
        assert data.get("some").get("namespace").get("old_property") == "value"
        assert data.get("another").get("namespace").get(
            "new_property") == "value"

        logs = caplog.text

        assert re.match(
            r"WARNING .*\"some.namespace.old_property\" configuration property is deprecated and will be removed "
            r"in a future major release\. You should use \"another.namespace.new_property\" instead\.",
            logs)
Exemple #3
0
    def test_autofix_variables_only(self, project_loader):
        project_loader("autofix_variables_only")

        config.args.autofix = True

        history = (
            PropertyMigration("old_property", "new_property", since="v1.1.0"),
            PropertyMigration("some.deep.old.property",
                              "some.another.new.property",
                              since="v1.1.0"),
        )

        migrations.set_history(history)

        features.register(CoreFeature())
        features.register(FileFeature())
        features.register(DockerFeature())
        features.register(JsonnetFeature())
        load_registered_features()
        register_actions_in_event_bus(True)

        action = FileWalkAction()
        action.initialize()
        action.execute()

        assert os.path.exists('variables.json')
        with open('variables.json', 'r') as f:
            rendered = f.read()

        with open('variables.expected.json', 'r') as f:
            expected = f.read()

        assert expected == rendered

        with open('variables.json.jsonnet', 'r') as f:
            source = f.read()

        with open('variables.json.autofix', 'r') as f:
            fixed = f.read()

        assert source == fixed
Exemple #4
0
    def test_autofix_eol2(self, project_loader):
        project_loader("autofix_eol2")

        config.args.autofix = True

        history = (
            PropertyMigration("docker.compose.network_name",
                              "jsonnet.docker.compose.network_name",
                              since="v1.6.0"),
            PropertyMigration("docker.port_prefix",
                              "jsonnet.docker.expose.port_prefix",
                              since="v1.6.0"),
        )

        migrations.set_history(history)

        features.register(FileFeature())
        features.register(JinjaFeature())
        load_registered_features()
        register_actions_in_event_bus(True)

        action = FileWalkAction()
        action.initialize()
        action.execute()

        with open('msmtprc', 'r') as f:
            rendered = f.read()

        with open('msmtprc.expected', 'r') as f:
            expected = f.read()

        assert rendered == expected

        with open('msmtprc.jinja', 'r') as f:
            template = f.read()

        with open('msmtprc.autofix', 'r') as f:
            autofix = f.read()

        assert autofix == template
    def test_warn_deprecated_simple(self, caplog: LogCaptureFixture):
        history = (PropertyMigration("old_property",
                                     "new_property",
                                     since="v1.1.0"), )

        migrations.set_history(history)

        data = MigrationsDotty({"old_property": "value"})

        migrations.migrate(data)

        assert data.get("old_property") == "value"
        assert data.get("new_property") == "value"

        logs = caplog.text

        assert re.match(
            r"WARNING .*\"old_property\" configuration property is deprecated since v1\.1\.0 and will be removed "
            r"in a future major release\. You should use \"new_property\" instead\.",
            logs)