def test_init_task_in_project_with_invalid_profile_template(
        self, mock_prompt, mock_confirm, mock_get_adapter, project
    ):
        """Test that when an invalid profile_template.yml is provided in the project,
        init command falls back to the target's profile_template.yml"""
        with open(os.path.join(project.project_root, "profile_template.yml"), "w") as f:
            f.write("""invalid template""")

        manager = Mock()
        manager.attach_mock(mock_prompt, "prompt")
        manager.attach_mock(mock_confirm, "confirm")
        manager.confirm.side_effect = ["y"]
        manager.prompt.side_effect = [
            1,
            "localhost",
            5432,
            "test_username",
            "test_password",
            "test_db",
            "test_schema",
            4,
        ]
        mock_get_adapter.return_value = [project.adapter.type()]

        run_dbt(["init"])

        manager.assert_has_calls(
            [
                call.confirm(
                    f"The profile test already exists in {os.path.join(project.profiles_dir, 'profiles.yml')}. Continue and overwrite it?"
                ),
                call.prompt(
                    "Which database would you like to use?\n[1] postgres\n\n(Don't see the one you want? https://docs.getdbt.com/docs/available-adapters)\n\nEnter a number",
                    type=click.INT,
                ),
                call.prompt(
                    "host (hostname for the instance)", default=None, hide_input=False, type=None
                ),
                call.prompt("port", default=5432, hide_input=False, type=click.INT),
                call.prompt("user (dev username)", default=None, hide_input=False, type=None),
                call.prompt("pass (dev password)", default=None, hide_input=True, type=None),
                call.prompt(
                    "dbname (default database that dbt will build objects in)",
                    default=None,
                    hide_input=False,
                    type=None,
                ),
                call.prompt(
                    "schema (default schema that dbt will build objects in)",
                    default=None,
                    hide_input=False,
                    type=None,
                ),
                call.prompt("threads (1 or more)", default=1, hide_input=False, type=click.INT),
            ]
        )

        with open(os.path.join(project.profiles_dir, "profiles.yml"), "r") as f:
            assert (
                f.read()
                == """test:
  outputs:
    dev:
      dbname: test_db
      host: localhost
      pass: test_password
      port: 5432
      schema: test_schema
      threads: 4
      type: postgres
      user: test_username
  target: dev
"""
            )
Test that when an invalid profile_template.yml is provided in the project,
        init command falls back to the target's profile_template.yml
tests/functional/init/test_init.py