# Path: google/datalab/contrib/pipeline/composer/_api.py
# class Api(object):
#   """A helper class to issue Composer HTTP requests."""
# 
#   _ENDPOINT = 'https://composer.googleapis.com/v1alpha1'
#   _ENVIRONMENTS_PATH_FORMAT = '/projects/%s/locations/%s/environments/%s'
# 
#   @staticmethod
#   def get_environment_details(zone, environment):
#     """ Issues a request to Composer to get the environment details.
# 
#     Args:
#       zone: GCP zone of the composer environment
#       environment: name of the Composer environment
#     Returns:
#       A parsed result object.
#     Raises:
#       Exception if there is an error performing the operation.
#     """
#     default_context = google.datalab.Context.default()
#     url = (Api._ENDPOINT + (Api._ENVIRONMENTS_PATH_FORMAT % (default_context.project_id, zone,
#                                                              environment)))
# 
#     return google.datalab.utils.Http.request(url, credentials=default_context.credentials)


import unittest
import mock
import google.auth
import google.datalab.utils
from google.datalab.contrib.pipeline.composer._api import Api
class TestCases(unittest.TestCase):

  TEST_PROJECT_ID = 'test_project'

  def validate(self, mock_http_request, expected_url, expected_args=None, expected_data=None,
               expected_headers=None, expected_method=None):
    url = mock_http_request.call_args[0][0]
    kwargs = mock_http_request.call_args[1]
    self.assertEquals(expected_url, url)
    if expected_args is not None:
      self.assertEquals(expected_args, kwargs['args'])
    else:
      self.assertNotIn('args', kwargs)
    if expected_data is not None:
      self.assertEquals(expected_data, kwargs['data'])
    else:
      self.assertNotIn('data', kwargs)
    if expected_headers is not None:
      self.assertEquals(expected_headers, kwargs['headers'])
    else:
      self.assertNotIn('headers', kwargs)
    if expected_method is not None:
      self.assertEquals(expected_method, kwargs['method'])
    else:
      self.assertNotIn('method', kwargs)

  @mock.patch('google.datalab.Context.default')
  @mock.patch('google.datalab.utils.Http.request')
  def test_environment_details_get(self, mock_http_request, mock_context_default):
    mock_context_default.return_value = TestCases._create_context()

# Path: google/datalab/contrib/pipeline/composer/_api.py
# class Api(object):
#   """A helper class to issue Composer HTTP requests."""
# 
#   _ENDPOINT = 'https://composer.googleapis.com/v1alpha1'
#   _ENVIRONMENTS_PATH_FORMAT = '/projects/%s/locations/%s/environments/%s'
# 
#   @staticmethod
#   def get_environment_details(zone, environment):
#     """ Issues a request to Composer to get the environment details.
# 
#     Args:
#       zone: GCP zone of the composer environment
#       environment: name of the Composer environment
#     Returns:
#       A parsed result object.
#     Raises:
#       Exception if there is an error performing the operation.
#     """
#     default_context = google.datalab.Context.default()
#     url = (Api._ENDPOINT + (Api._ENVIRONMENTS_PATH_FORMAT % (default_context.project_id, zone,
#                                                              environment)))
# 
#     return google.datalab.utils.Http.request(url, credentials=default_context.credentials)


# Path: tests/pipeline/composer_api_tests.py
import unittest
import mock
import google.auth
import google.datalab.utils
from google.datalab.contrib.pipeline.composer._api import Api

class TestCases(unittest.TestCase):

  TEST_PROJECT_ID = 'test_project'

  def validate(self, mock_http_request, expected_url, expected_args=None, expected_data=None,
               expected_headers=None, expected_method=None):
    url = mock_http_request.call_args[0][0]
    kwargs = mock_http_request.call_args[1]
    self.assertEquals(expected_url, url)
    if expected_args is not None:
      self.assertEquals(expected_args, kwargs['args'])
    else:
      self.assertNotIn('args', kwargs)
    if expected_data is not None:
      self.assertEquals(expected_data, kwargs['data'])
    else:
      self.assertNotIn('data', kwargs)
    if expected_headers is not None:
      self.assertEquals(expected_headers, kwargs['headers'])
    else:
      self.assertNotIn('headers', kwargs)
    if expected_method is not None:
      self.assertEquals(expected_method, kwargs['method'])
    else:
      self.assertNotIn('method', kwargs)

  @mock.patch('google.datalab.Context.default')
  @mock.patch('google.datalab.utils.Http.request')
  def test_environment_details_get(self, mock_http_request, mock_context_default):
    mock_context_default.return_value = TestCases._create_context()

    Api.get_environment_details('ZONE', 'ENVIRONMENT')