# Path: data_catalog/configuration.py
# class DCConfig(object):
# 
#     """
#     Contains a configuration of the Data Catalog.
#     No fields should  be written to be the user.
#     """
# 
#     def __init__(self):
#         """
#         Reads the configuration from environment variables set by Cloud Foundry (CF)
#         or by the developer when running locally.
#         Normally, CF sets the full configuration in environment variables,
#         e.g. VCAP_SERVICES (which is most important for us).
#         When working on a local machine, VCAP_SERVICES also needs to be set and contain some values.
#         Without them, the app couldn't work.
#         Most of configuration values have some defaults that will be set when they aren't configured
#         in the environment, but some of them, like the address of the authorization server can't
#         have a default. They need to be set manually by the developer to enable local work.
#         """
#         self._fail_if_no_configuration()
# 
#         self.app_base_path = '/rest/datasets'
# 
#         # if values aren't found we set defaults that are meant for local operations
#         self.app_port = int(os.getenv(VCAP_APP_PORT, '5000'))
#         self.log_level = os.getenv(LOG_LEVEL, 'DEBUG')
# 
#         services_config = json.loads(os.environ[VCAP_SERVICES])
#         self.elastic = ElasticConfig(services_config)
#         self.services_url = ServiceUrlsConfig(services_config)
# 
#     @staticmethod
#     def _fail_if_no_configuration():
#         """
#         Checks the environment variables to decide if the app can run.
#         :rtype: None
#         :raises NoConfigEnvError: When VCAP_SERVICES is not present and the app can't run.
#         """
#         if not VCAP_SERVICES in os.environ:
#             raise NoConfigEnvError(
#                 'VCAP_SERVICES environment variable needs to be set to run Data Catalog.')
# 
# Path: tests/conftest.py
# def setup_fake_env():
#     """
#     Sets up a fake environment needed for the app to properly load configuration during tests.
#     This fake environment looks like a major part of normal environment in Cloud Foundry.
#     :rtype: None
#     """
#     os.environ[VCAP_SERVICES] = '''{
#         "downloader": [
#             {
#                 "credentials": {
#                     "url": "http://downloader-broker.apps.example.com"
#                 },
#                 "label": "downloader",
#                 "name": "downloader",
#                 "plan": "shared",
#                 "syslog_drain_url": "",
#                 "tags": [
#                     "simple",
#                     "shared"
#                 ]
#             }
#         ],
#         "elasticsearch13": [
#             {
#                 "credentials": {
#                     "hostname": "10.10.2.7",
#                     "ports": {
#                         "9200/tcp": "49237",
#                         "9300/tcp": "49238"
#                     }
#                 },
#                 "label": "elasticsearch13",
#                 "name": "data-catalog-mock-index",
#                 "plan": "free",
#                 "tags": [
#                     "elasticsearch13",
#                     "elasticsearch",
#                     "search"
#                 ]
#             }
#         ],
#         "user-provided": [
#             {
#                 "credentials": {
#                     "host": "http://hive.apps.example.com"
#                 },
#                 "label": "user-provided",
#                 "name": "datacatalogexport",
#                 "syslog_drain_url": "",
#                 "tags": []
#             },
#             {
#                 "credentials": {
#                      "tokenKey": "http://uaa.run.example.com/token_key"
#                 },
#                 "label": "user-provided",
#                 "name": "sso",
#                 "syslog_drain_url": "",
#                 "tags": []
#             },
#             {
#                 "credentials": {
#                     "url": "http://downloader-broker.apps.example.com"
#                 },
#                 "label": "user-provided",
#                 "name": "downloader",
#                 "syslog_drain_url": "",
#                 "tags": []
#             },
#             {
#                 "credentials": {
#                     "host": "http://user-management.apps.example.com"
#                 },
#                 "label": "user-provided",
#                 "name": "user-management",
#                 "syslog_drain_url": "",
#                 "tags": []
#             }
#         ]
#     }'''
#     os.environ[VCAP_APP_PORT] = '5555'
#     os.environ[LOG_LEVEL] = 'INFO'
#     os.environ[VCAP_APPLICATION] = "this is set just so the config doesn't try to set local values"
# 
# def clean_fake_env():
#     os.environ.pop(VCAP_SERVICES, None)
#     os.environ.pop(VCAP_APP_PORT, None)
#     os.environ.pop(LOG_LEVEL, None)
#     os.environ.pop(VCAP_APPLICATION, None)
# 
# def disable_authentication(app_client):
#     mock = MagicMock()
#     mock.mocked_function.side_effect = lambda: None
#     app_client.application.before_request_funcs = {None: [mock.mocked_function]}
#     return mock.mocked_function


import unittest
import data_catalog.app
from data_catalog.configuration import DCConfig
from .conftest import setup_fake_env, clean_fake_env, disable_authentication
#
# Copyright (c) 2015 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#





class DataCatalogTestCase(unittest.TestCase):
    def setUp(self):
        setup_fake_env()
        self._config = DCConfig()

        self.app = data_catalog.app._create_app(self._config)
        self.app.config['TESTING'] = True

# Path: data_catalog/configuration.py
# class DCConfig(object):
# 
#     """
#     Contains a configuration of the Data Catalog.
#     No fields should  be written to be the user.
#     """
# 
#     def __init__(self):
#         """
#         Reads the configuration from environment variables set by Cloud Foundry (CF)
#         or by the developer when running locally.
#         Normally, CF sets the full configuration in environment variables,
#         e.g. VCAP_SERVICES (which is most important for us).
#         When working on a local machine, VCAP_SERVICES also needs to be set and contain some values.
#         Without them, the app couldn't work.
#         Most of configuration values have some defaults that will be set when they aren't configured
#         in the environment, but some of them, like the address of the authorization server can't
#         have a default. They need to be set manually by the developer to enable local work.
#         """
#         self._fail_if_no_configuration()
# 
#         self.app_base_path = '/rest/datasets'
# 
#         # if values aren't found we set defaults that are meant for local operations
#         self.app_port = int(os.getenv(VCAP_APP_PORT, '5000'))
#         self.log_level = os.getenv(LOG_LEVEL, 'DEBUG')
# 
#         services_config = json.loads(os.environ[VCAP_SERVICES])
#         self.elastic = ElasticConfig(services_config)
#         self.services_url = ServiceUrlsConfig(services_config)
# 
#     @staticmethod
#     def _fail_if_no_configuration():
#         """
#         Checks the environment variables to decide if the app can run.
#         :rtype: None
#         :raises NoConfigEnvError: When VCAP_SERVICES is not present and the app can't run.
#         """
#         if not VCAP_SERVICES in os.environ:
#             raise NoConfigEnvError(
#                 'VCAP_SERVICES environment variable needs to be set to run Data Catalog.')
# 
# Path: tests/conftest.py
# def setup_fake_env():
#     """
#     Sets up a fake environment needed for the app to properly load configuration during tests.
#     This fake environment looks like a major part of normal environment in Cloud Foundry.
#     :rtype: None
#     """
#     os.environ[VCAP_SERVICES] = '''{
#         "downloader": [
#             {
#                 "credentials": {
#                     "url": "http://downloader-broker.apps.example.com"
#                 },
#                 "label": "downloader",
#                 "name": "downloader",
#                 "plan": "shared",
#                 "syslog_drain_url": "",
#                 "tags": [
#                     "simple",
#                     "shared"
#                 ]
#             }
#         ],
#         "elasticsearch13": [
#             {
#                 "credentials": {
#                     "hostname": "10.10.2.7",
#                     "ports": {
#                         "9200/tcp": "49237",
#                         "9300/tcp": "49238"
#                     }
#                 },
#                 "label": "elasticsearch13",
#                 "name": "data-catalog-mock-index",
#                 "plan": "free",
#                 "tags": [
#                     "elasticsearch13",
#                     "elasticsearch",
#                     "search"
#                 ]
#             }
#         ],
#         "user-provided": [
#             {
#                 "credentials": {
#                     "host": "http://hive.apps.example.com"
#                 },
#                 "label": "user-provided",
#                 "name": "datacatalogexport",
#                 "syslog_drain_url": "",
#                 "tags": []
#             },
#             {
#                 "credentials": {
#                      "tokenKey": "http://uaa.run.example.com/token_key"
#                 },
#                 "label": "user-provided",
#                 "name": "sso",
#                 "syslog_drain_url": "",
#                 "tags": []
#             },
#             {
#                 "credentials": {
#                     "url": "http://downloader-broker.apps.example.com"
#                 },
#                 "label": "user-provided",
#                 "name": "downloader",
#                 "syslog_drain_url": "",
#                 "tags": []
#             },
#             {
#                 "credentials": {
#                     "host": "http://user-management.apps.example.com"
#                 },
#                 "label": "user-provided",
#                 "name": "user-management",
#                 "syslog_drain_url": "",
#                 "tags": []
#             }
#         ]
#     }'''
#     os.environ[VCAP_APP_PORT] = '5555'
#     os.environ[LOG_LEVEL] = 'INFO'
#     os.environ[VCAP_APPLICATION] = "this is set just so the config doesn't try to set local values"
# 
# def clean_fake_env():
#     os.environ.pop(VCAP_SERVICES, None)
#     os.environ.pop(VCAP_APP_PORT, None)
#     os.environ.pop(LOG_LEVEL, None)
#     os.environ.pop(VCAP_APPLICATION, None)
# 
# def disable_authentication(app_client):
#     mock = MagicMock()
#     mock.mocked_function.side_effect = lambda: None
#     app_client.application.before_request_funcs = {None: [mock.mocked_function]}
#     return mock.mocked_function


# Path: tests/base_test.py
import unittest
import data_catalog.app
from data_catalog.configuration import DCConfig
from .conftest import setup_fake_env, clean_fake_env, disable_authentication

#
# Copyright (c) 2015 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#





class DataCatalogTestCase(unittest.TestCase):
    def setUp(self):
        setup_fake_env()
        self._config = DCConfig()

        self.app = data_catalog.app._create_app(self._config)
        self.app.config['TESTING'] = True

        self.client = self.app.test_client()