# Path: networking_odl/common/client.py
# class OpenDaylightRestClient(object):
#     @staticmethod
#     def _check_opt(url):
#         if not url:
#             raise cfg.RequiredOptError('url', cfg.OptGroup('ml2_odl'))
#         required_opts = ('url', 'username', 'password')
#         for opt in required_opts:
#             if not getattr(cfg.CONF.ml2_odl, opt):
#                 raise cfg.RequiredOptError(opt, cfg.OptGroup('ml2_odl'))
# 
#     @classmethod
#     def create_client(cls, url=None):
#         if cfg.CONF.ml2_odl.enable_lightweight_testing:
#             LOG.debug("ODL lightweight testing is enabled, "
#                       "returning a OpenDaylightLwtClient instance")
# 
#             # Have to import at here, otherwise we create a dependency loop
#             # pylint: disable=import-outside-toplevel
#             from networking_odl.common import lightweight_testing as lwt
#             cls = lwt.OpenDaylightLwtClient
# 
#         url = url or cfg.CONF.ml2_odl.url
#         cls._check_opt(url)
#         return cls(
#             url,
#             cfg.CONF.ml2_odl.username,
#             cfg.CONF.ml2_odl.password,
#             cfg.CONF.ml2_odl.timeout)
# 
#     def __init__(self, url, username, password, timeout):
#         super(OpenDaylightRestClient, self).__init__()
#         self.url = url
#         self.timeout = timeout
#         self.session = sessions.Session()
#         self.session.auth = (username, password)
# 
#     def get_resource(self, resource_type, resource_id):
#         response = self.get(utils.make_url_object(resource_type) + '/' +
#                             resource_id)
#         if response.status_code == requests.codes.not_found:
#             return None
# 
#         return self._check_response(response).json()
# 
#     def get(self, urlpath='', data=None):
#         return self.request('get', urlpath, data)
# 
#     def request(self, method, urlpath='', data=None):
#         headers = {'Content-Type': 'application/json'}
#         url = '/'.join([self.url, urlpath])
#         LOG.debug(
#             "Sending METHOD (%(method)s) URL (%(url)s) JSON (%(data)s)",
#             {'method': method, 'url': url, 'data': data})
#         return self.session.request(
#             method, url=url, headers=headers, data=data, timeout=self.timeout)
# 
#     def sendjson(self, method, urlpath, obj):
#         """Send json to the OpenDaylight controller."""
#         data = jsonutils.dumps(obj, indent=2) if obj else None
#         try:
#             return self._check_response(
#                 self.request(method, urlpath, data))
#         except Exception:
#             with excutils.save_and_reraise_exception():
#                 LOG.error("REST request ( %(method)s ) to "
#                           "url ( %(urlpath)s ) is failed. "
#                           "Request body : [%(body)s] service",
#                           {'method': method,
#                            'urlpath': urlpath,
#                            'body': obj})
# 
#     def _check_response(self, response):
#         try:
#             response.raise_for_status()
#         except requests.HTTPError as error:
#             with excutils.save_and_reraise_exception():
#                 LOG.debug("Exception from ODL: %(e)s %(text)s",
#                           {'e': error, 'text': response.text}, exc_info=1)
#         else:
#             LOG.debug("Got response:\n"
#                       "(%(response)s)", {'response': response.text})
#             return response
# 
# Path: networking_odl/common/odl_features.py
# LOG = log.getLogger(__name__)
# OPERATIONAL_PORT_STATUS = 'operational-port-status'
# EMPTY_FEATURES = {}
# def init():
# def has(feature):
# def get_config(feature):
# def deinit():
# def _load_features(json):
# def _fetch_features():
# 
# Path: networking_odl/tests/base.py
# class DietTestCase(base.DietTestCase):
# class OpenDaylightRestClientFixture(fixtures.Fixture):
# class OpenDaylightRestClientGlobalFixture(fixtures.Fixture):
# class OpenDaylightFeaturesFixture(fixtures.Fixture):
# class OpenDaylightJournalThreadFixture(fixtures.Fixture):
# class JournalWorkerPidFileFixture(fixtures.Fixture):
# class OpenDaylightPeriodicTaskFixture(fixtures.Fixture):
# class OpenDaylightPseudoAgentPrePopulateFixture(
#         nl_fixture.CallbackRegistryFixture):
# class OpenDaylightFullSyncFixture(fixtures.Fixture):
#     def patch(self, target, name, *args, **kwargs):
#     def _setUp(self):
#     def __init__(self, global_client):
#     def _setUp(self):
#     def _setUp(self):
#     def _setUp(self):
#     def remock_atexit(self):
#     def _setUp(self):
#     def _setUp(self):
#     def _setUp(self):
#     def _restore(self):
#     def _setUp(self):


from unittest import mock
from oslo_config import fixture as config_fixture
from oslo_serialization import jsonutils
from requests import exceptions
from networking_odl.common.client import OpenDaylightRestClient
from networking_odl.common import odl_features
from networking_odl.tests import base
#
#    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 TestOdlFeatures(base.DietTestCase):
    """Basic tests for odl_features"""

    feature_json = """{"features": {"feature":
                            [{"service-provider-feature":
                            "neutron-extensions:operational-port-status"},
                            {"service-provider-feature":
                            "neutron-extensions:feature-with-config",
                            "configuration": "steal-your-face"}]}}"""

    feature_list = 'thing1, thing2'

    def setUp(self):

# Path: networking_odl/common/client.py
# class OpenDaylightRestClient(object):
#     @staticmethod
#     def _check_opt(url):
#         if not url:
#             raise cfg.RequiredOptError('url', cfg.OptGroup('ml2_odl'))
#         required_opts = ('url', 'username', 'password')
#         for opt in required_opts:
#             if not getattr(cfg.CONF.ml2_odl, opt):
#                 raise cfg.RequiredOptError(opt, cfg.OptGroup('ml2_odl'))
# 
#     @classmethod
#     def create_client(cls, url=None):
#         if cfg.CONF.ml2_odl.enable_lightweight_testing:
#             LOG.debug("ODL lightweight testing is enabled, "
#                       "returning a OpenDaylightLwtClient instance")
# 
#             # Have to import at here, otherwise we create a dependency loop
#             # pylint: disable=import-outside-toplevel
#             from networking_odl.common import lightweight_testing as lwt
#             cls = lwt.OpenDaylightLwtClient
# 
#         url = url or cfg.CONF.ml2_odl.url
#         cls._check_opt(url)
#         return cls(
#             url,
#             cfg.CONF.ml2_odl.username,
#             cfg.CONF.ml2_odl.password,
#             cfg.CONF.ml2_odl.timeout)
# 
#     def __init__(self, url, username, password, timeout):
#         super(OpenDaylightRestClient, self).__init__()
#         self.url = url
#         self.timeout = timeout
#         self.session = sessions.Session()
#         self.session.auth = (username, password)
# 
#     def get_resource(self, resource_type, resource_id):
#         response = self.get(utils.make_url_object(resource_type) + '/' +
#                             resource_id)
#         if response.status_code == requests.codes.not_found:
#             return None
# 
#         return self._check_response(response).json()
# 
#     def get(self, urlpath='', data=None):
#         return self.request('get', urlpath, data)
# 
#     def request(self, method, urlpath='', data=None):
#         headers = {'Content-Type': 'application/json'}
#         url = '/'.join([self.url, urlpath])
#         LOG.debug(
#             "Sending METHOD (%(method)s) URL (%(url)s) JSON (%(data)s)",
#             {'method': method, 'url': url, 'data': data})
#         return self.session.request(
#             method, url=url, headers=headers, data=data, timeout=self.timeout)
# 
#     def sendjson(self, method, urlpath, obj):
#         """Send json to the OpenDaylight controller."""
#         data = jsonutils.dumps(obj, indent=2) if obj else None
#         try:
#             return self._check_response(
#                 self.request(method, urlpath, data))
#         except Exception:
#             with excutils.save_and_reraise_exception():
#                 LOG.error("REST request ( %(method)s ) to "
#                           "url ( %(urlpath)s ) is failed. "
#                           "Request body : [%(body)s] service",
#                           {'method': method,
#                            'urlpath': urlpath,
#                            'body': obj})
# 
#     def _check_response(self, response):
#         try:
#             response.raise_for_status()
#         except requests.HTTPError as error:
#             with excutils.save_and_reraise_exception():
#                 LOG.debug("Exception from ODL: %(e)s %(text)s",
#                           {'e': error, 'text': response.text}, exc_info=1)
#         else:
#             LOG.debug("Got response:\n"
#                       "(%(response)s)", {'response': response.text})
#             return response
# 
# Path: networking_odl/common/odl_features.py
# LOG = log.getLogger(__name__)
# OPERATIONAL_PORT_STATUS = 'operational-port-status'
# EMPTY_FEATURES = {}
# def init():
# def has(feature):
# def get_config(feature):
# def deinit():
# def _load_features(json):
# def _fetch_features():
# 
# Path: networking_odl/tests/base.py
# class DietTestCase(base.DietTestCase):
# class OpenDaylightRestClientFixture(fixtures.Fixture):
# class OpenDaylightRestClientGlobalFixture(fixtures.Fixture):
# class OpenDaylightFeaturesFixture(fixtures.Fixture):
# class OpenDaylightJournalThreadFixture(fixtures.Fixture):
# class JournalWorkerPidFileFixture(fixtures.Fixture):
# class OpenDaylightPeriodicTaskFixture(fixtures.Fixture):
# class OpenDaylightPseudoAgentPrePopulateFixture(
#         nl_fixture.CallbackRegistryFixture):
# class OpenDaylightFullSyncFixture(fixtures.Fixture):
#     def patch(self, target, name, *args, **kwargs):
#     def _setUp(self):
#     def __init__(self, global_client):
#     def _setUp(self):
#     def _setUp(self):
#     def _setUp(self):
#     def remock_atexit(self):
#     def _setUp(self):
#     def _setUp(self):
#     def _setUp(self):
#     def _restore(self):
#     def _setUp(self):


# Path: networking_odl/tests/unit/common/test_odl_features.py
from unittest import mock
from oslo_config import fixture as config_fixture
from oslo_serialization import jsonutils
from requests import exceptions
from networking_odl.common.client import OpenDaylightRestClient
from networking_odl.common import odl_features
from networking_odl.tests import base

#
#    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 TestOdlFeatures(base.DietTestCase):
    """Basic tests for odl_features"""

    feature_json = """{"features": {"feature":
                            [{"service-provider-feature":
                            "neutron-extensions:operational-port-status"},
                            {"service-provider-feature":
                            "neutron-extensions:feature-with-config",
                            "configuration": "steal-your-face"}]}}"""

    feature_list = 'thing1, thing2'

    def setUp(self):

        self.features_fixture = base.OpenDaylightFeaturesFixture()