# Path: shared/gcp_jupyterlab_shared/version.py
# VERSION = '1.1.3'


import asyncio
import base64
import json
import unittest
import tornado.testing
from unittest.mock import patch, MagicMock
from google.auth.exceptions import RefreshError
from tornado.web import Application
from tornado.httpclient import HTTPClientError
from gcp_jupyterlab_shared import handlers, test_data
from .version import VERSION

  def _configure_mock_client(self, mock_client):
    mock_response = MagicMock()
    mock_response.body = self.RESPONSE_BODY
    mock_fetch = MagicMock(return_value=async_return(mock_response))
    mock_client.return_value.fetch = mock_fetch
    return mock_fetch

  def _make_url(self, path):
    gcp_path = base64.b64encode((self.GCP_URL + path).encode()).decode()
    return '{}/{}'.format(self.URL, gcp_path)

  def get_app(self):
    return Application([
        (self.URL + '/(.+)', handlers.ProxyHandler),
    ])

  def test_get(self, mock_auth_provider, mock_client):
    gcp_path = '/services?consumerId=project:TEST'
    self._configure_mock_auth_provider(mock_auth_provider)
    mock_fetch = self._configure_mock_client(mock_client)
    response = self.fetch(self._make_url(gcp_path))
    request = mock_fetch.call_args[0][0]
    self.assertEqual(200, response.code)
    self.assertEqual(self.RESPONSE_BODY, response.body)
    self.assertEqual(
        '{}{}'.format(self.GCP_URL, '/services?consumerId=project:TEST'),
        request.url)
    self.assertEqual('GET', request.method)
    self.assertEqual(None, request.body)

# Path: shared/gcp_jupyterlab_shared/version.py
# VERSION = '1.1.3'


# Path: shared/gcp_jupyterlab_shared/handlers_test.py
import asyncio
import base64
import json
import unittest
import tornado.testing
from unittest.mock import patch, MagicMock
from google.auth.exceptions import RefreshError
from tornado.web import Application
from tornado.httpclient import HTTPClientError
from gcp_jupyterlab_shared import handlers, test_data
from .version import VERSION


  def _configure_mock_client(self, mock_client):
    mock_response = MagicMock()
    mock_response.body = self.RESPONSE_BODY
    mock_fetch = MagicMock(return_value=async_return(mock_response))
    mock_client.return_value.fetch = mock_fetch
    return mock_fetch

  def _make_url(self, path):
    gcp_path = base64.b64encode((self.GCP_URL + path).encode()).decode()
    return '{}/{}'.format(self.URL, gcp_path)

  def get_app(self):
    return Application([
        (self.URL + '/(.+)', handlers.ProxyHandler),
    ])

  def test_get(self, mock_auth_provider, mock_client):
    gcp_path = '/services?consumerId=project:TEST'
    self._configure_mock_auth_provider(mock_auth_provider)
    mock_fetch = self._configure_mock_client(mock_client)
    response = self.fetch(self._make_url(gcp_path))
    request = mock_fetch.call_args[0][0]
    self.assertEqual(200, response.code)
    self.assertEqual(self.RESPONSE_BODY, response.body)
    self.assertEqual(
        '{}{}'.format(self.GCP_URL, '/services?consumerId=project:TEST'),
        request.url)
    self.assertEqual('GET', request.method)
    self.assertEqual(None, request.body)

    self.assertEqual('jupyterlab_gcpextension/{}'.format(VERSION),