code: def test_tb_init_and_url_valid_studio_medatada_file(
      mock_metadata_file_present, mock_client
  ):
      """
      Test TensorBoardApp URL for the case when metadata file is present,
      and contains valid domain id and user profile name.
      """
      mock_metadata_file_present.return_value = True
      mock_client.return_value = boto3.client("sagemaker")
      with patch(
          "builtins.open", mock_open(read_data=TEST_NOTEBOOK_METADATA)
      ):
          tb_app = TensorBoardApp(TEST_REGION)
          assert tb_app.region == TEST_REGION
          assert tb_app._domain_id == TEST_DOMAIN
          assert tb_app._user_profile_name == TEST_USER_PROFILE
          assert tb_app._in_studio_env is True
  
          # test url without job redirect
          assert (
              tb_app.get_app_url(open_in_default_web_browser=False)
              == BASE_URL_STUDIO_FORMAT.format(TEST_DOMAIN, TEST_REGION)
              + "/#sagemaker_data_manager"
          )
  
          # test url with valid job redirect
          assert tb_app.get_app_url(
              TEST_TRAINING_JOB, open_in_default_web_browser=False
          ) == BASE_URL_STUDIO_FORMAT.format(
              TEST_DOMAIN, TEST_REGION
          ) + REDIRECT_STUDIO_FORMAT.format(
              TEST_TRAINING_JOB
          )
  
          # test url with invalid job redirect
          with pytest.raises(ValueError):
              tb_app.get_app_url("invald_job_name!")
  
          # test url when opened in web browser
          with patch("webbrowser.open") as mock_web_browser_open:
              url = tb_app.get_app_url(
                  open_in_default_web_browser=True,
              )
              mock_web_browser_open.assert_called_with(
                  BASE_URL_STUDIO_FORMAT.format(
                      TEST_DOMAIN, TEST_REGION
                  )
                  + "/#sagemaker_data_manager"
              )
              assert url == ""
  
imports: from __future__ import absolute_import
  import json
  from unittest.mock import patch, Mock, mock_open, PropertyMock
  import boto3
  import botocore
  import pytest
  from sagemaker.interactive_apps.tensorboard import TensorBoardApp
label_desc: Use image node_id 3 for calling a global function with example usage: test_tb_init_and_url_valid_studio_medatada_file(mock_metadata_file_present, mock_client) without return types