# Path: scar/providers/oscar/client.py
# class OSCARClient():
#     _SERVICES_PATH = '/system/services'
# 
#     def __init__(self, credentials_info: Dict, cluster_id: str):
#         self.cluster_id = cluster_id
#         self.endpoint = credentials_info['endpoint']
#         self.auth_user = credentials_info['auth_user']
#         self.auth_password = credentials_info['auth_password']
#         self.ssl_verify = credentials_info['ssl_verify']
# 
#     def create_service(self, **kwargs: Dict) -> Dict:
#         """Creates a new OSCAR service."""
#         logger.debug('Creating OSCAR service.')
#         res = requests.post(
#             f'{self.endpoint}{self._SERVICES_PATH}',
#             auth=(self.auth_user, self.auth_password),
#             verify=self.ssl_verify,
#             json=kwargs
#         )
#         # Raise a ServiceCreationError if the return code is not 201
#         if res.status_code != 201:
#             raise excp.ServiceCreationError(service_name=kwargs['name'], error_msg=_get_error_msg(res))
# 
#     def delete_service(self, service_name: str) -> None:
#         """Deletes an OSCAR service."""
#         logger.debug('Deleting OSCAR service.')
#         res = requests.delete(
#             f'{self.endpoint}{self._SERVICES_PATH}/{service_name}',
#             auth=(self.auth_user, self.auth_password),
#             verify=self.ssl_verify
#         )
#         # Raise a ServiceDeletionError if the return code is not 204
#         if res.status_code != 204:
#             raise excp.ServiceDeletionError(service_name=service_name, error_msg=_get_error_msg(res))
# 
#     def get_service(self, service_name: str) -> Dict:
#         """Get the properties of the specified service."""
#         res = requests.get(
#             f'{self.endpoint}{self._SERVICES_PATH}/{service_name}',
#             auth=(self.auth_user, self.auth_password),
#             verify=self.ssl_verify
#         )
#         # Raise a ServiceNotFoundError if the return code is not 200
#         if res.status_code != 200:
#             raise excp.ServiceNotFoundError(service_name=service_name, error_msg=_get_error_msg(res))
#         return res.json()
# 
#     def list_services(self) -> List:
#         """Get all the services registered in the cluster."""
#         res = requests.get(
#             f'{self.endpoint}{self._SERVICES_PATH}',
#             auth=(self.auth_user, self.auth_password),
#             verify=self.ssl_verify
#         )
#         # Raise a ListServicesError if the return code is not 200
#         if res.status_code != 200:
#             raise excp.ListServicesError(cluster_id=self.cluster_id, error_msg=_get_error_msg(res))
#         return res.json()
# 
# Path: scar/exceptions.py
# class ServiceCreationError(ScarError):
#     """
#     There was an error creating the OSCAR service
# 
#     :ivar service_name: Name of the function
#     :ivar error_msg: General error message
#     """
#     fmt = "Unable to create the service '{service_name}': {error_msg}"
# 
# class ServiceDeletionError(ScarError):
#     """
#     There was an error deleting the OSCAR service
# 
#     :ivar service_name: Name of the function
#     :ivar error_msg: General error message
#     """
#     fmt = "Unable to delete the service '{service_name}': {error_msg}"
# 
# class ServiceNotFoundError(ScarError):
#     """
#     There was an error getting the OSCAR service
# 
#     :ivar service_name: Name of the function
#     :ivar error_msg: General error message
#     """
#     fmt = "The service '{service_name}' does not exist: {error_msg}"
# 
# class ListServicesError(ScarError):
#     """
#     There was an error getting the OSCAR service
# 
#     :ivar service_name: Name of the function
#     :ivar error_msg: General error message
#     """
#     fmt = "Unable to list services from OSCAR cluster '{cluster_id}': {error_msg}"


import unittest
import sys
from mock import MagicMock
from mock import patch
from scar.providers.oscar.client import OSCARClient
from scar.exceptions import ServiceCreationError, ServiceDeletionError, ServiceNotFoundError, ListServicesError
            "Unable to delete the service 'sname': Some error",
            str(ex.exception)
        )

    @patch('requests.get')
    def test_get_service(self, get):
        response = MagicMock(["status_code", "json"])
        response.status_code = 200
        response.json.return_value = {"key": "value"}
        get.return_value = response
        oscar = OSCARClient({"endpoint": "url", "auth_user": "user", "auth_password": "pass", "ssl_verify": False}, "cid")
        self.assertEqual(oscar.get_service("sname"), {"key": "value"})
        self.assertEqual(get.call_args_list[0][0][0], "url/system/services/sname")
        self.assertEqual(get.call_args_list[0][1], {'auth': ('user', 'pass'), 'verify': False})

        response.status_code = 401
        response.text = "Some error"
        with self.assertRaises(ServiceNotFoundError) as ex:
            oscar.get_service("sname"), {"key": "value"}
        self.assertEqual(
            "The service 'sname' does not exist: Some error",
            str(ex.exception)
        )

    @patch('requests.get')
    def test_list_services(self, get):
        response = MagicMock(["status_code", "json"])
        response.status_code = 200
        response.json.return_value = {"key": "value"}
        get.return_value = response

# Path: scar/providers/oscar/client.py
# class OSCARClient():
#     _SERVICES_PATH = '/system/services'
# 
#     def __init__(self, credentials_info: Dict, cluster_id: str):
#         self.cluster_id = cluster_id
#         self.endpoint = credentials_info['endpoint']
#         self.auth_user = credentials_info['auth_user']
#         self.auth_password = credentials_info['auth_password']
#         self.ssl_verify = credentials_info['ssl_verify']
# 
#     def create_service(self, **kwargs: Dict) -> Dict:
#         """Creates a new OSCAR service."""
#         logger.debug('Creating OSCAR service.')
#         res = requests.post(
#             f'{self.endpoint}{self._SERVICES_PATH}',
#             auth=(self.auth_user, self.auth_password),
#             verify=self.ssl_verify,
#             json=kwargs
#         )
#         # Raise a ServiceCreationError if the return code is not 201
#         if res.status_code != 201:
#             raise excp.ServiceCreationError(service_name=kwargs['name'], error_msg=_get_error_msg(res))
# 
#     def delete_service(self, service_name: str) -> None:
#         """Deletes an OSCAR service."""
#         logger.debug('Deleting OSCAR service.')
#         res = requests.delete(
#             f'{self.endpoint}{self._SERVICES_PATH}/{service_name}',
#             auth=(self.auth_user, self.auth_password),
#             verify=self.ssl_verify
#         )
#         # Raise a ServiceDeletionError if the return code is not 204
#         if res.status_code != 204:
#             raise excp.ServiceDeletionError(service_name=service_name, error_msg=_get_error_msg(res))
# 
#     def get_service(self, service_name: str) -> Dict:
#         """Get the properties of the specified service."""
#         res = requests.get(
#             f'{self.endpoint}{self._SERVICES_PATH}/{service_name}',
#             auth=(self.auth_user, self.auth_password),
#             verify=self.ssl_verify
#         )
#         # Raise a ServiceNotFoundError if the return code is not 200
#         if res.status_code != 200:
#             raise excp.ServiceNotFoundError(service_name=service_name, error_msg=_get_error_msg(res))
#         return res.json()
# 
#     def list_services(self) -> List:
#         """Get all the services registered in the cluster."""
#         res = requests.get(
#             f'{self.endpoint}{self._SERVICES_PATH}',
#             auth=(self.auth_user, self.auth_password),
#             verify=self.ssl_verify
#         )
#         # Raise a ListServicesError if the return code is not 200
#         if res.status_code != 200:
#             raise excp.ListServicesError(cluster_id=self.cluster_id, error_msg=_get_error_msg(res))
#         return res.json()
# 
# Path: scar/exceptions.py
# class ServiceCreationError(ScarError):
#     """
#     There was an error creating the OSCAR service
# 
#     :ivar service_name: Name of the function
#     :ivar error_msg: General error message
#     """
#     fmt = "Unable to create the service '{service_name}': {error_msg}"
# 
# class ServiceDeletionError(ScarError):
#     """
#     There was an error deleting the OSCAR service
# 
#     :ivar service_name: Name of the function
#     :ivar error_msg: General error message
#     """
#     fmt = "Unable to delete the service '{service_name}': {error_msg}"
# 
# class ServiceNotFoundError(ScarError):
#     """
#     There was an error getting the OSCAR service
# 
#     :ivar service_name: Name of the function
#     :ivar error_msg: General error message
#     """
#     fmt = "The service '{service_name}' does not exist: {error_msg}"
# 
# class ListServicesError(ScarError):
#     """
#     There was an error getting the OSCAR service
# 
#     :ivar service_name: Name of the function
#     :ivar error_msg: General error message
#     """
#     fmt = "Unable to list services from OSCAR cluster '{cluster_id}': {error_msg}"


# Path: test/unit/oscar/test_client.py
import unittest
import sys
from mock import MagicMock
from mock import patch
from scar.providers.oscar.client import OSCARClient
from scar.exceptions import ServiceCreationError, ServiceDeletionError, ServiceNotFoundError, ListServicesError

            "Unable to delete the service 'sname': Some error",
            str(ex.exception)
        )

    @patch('requests.get')
    def test_get_service(self, get):
        response = MagicMock(["status_code", "json"])
        response.status_code = 200
        response.json.return_value = {"key": "value"}
        get.return_value = response
        oscar = OSCARClient({"endpoint": "url", "auth_user": "user", "auth_password": "pass", "ssl_verify": False}, "cid")
        self.assertEqual(oscar.get_service("sname"), {"key": "value"})
        self.assertEqual(get.call_args_list[0][0][0], "url/system/services/sname")
        self.assertEqual(get.call_args_list[0][1], {'auth': ('user', 'pass'), 'verify': False})

        response.status_code = 401
        response.text = "Some error"
        with self.assertRaises(ServiceNotFoundError) as ex:
            oscar.get_service("sname"), {"key": "value"}
        self.assertEqual(
            "The service 'sname' does not exist: Some error",
            str(ex.exception)
        )

    @patch('requests.get')
    def test_list_services(self, get):
        response = MagicMock(["status_code", "json"])
        response.status_code = 200
        response.json.return_value = {"key": "value"}
        get.return_value = response

        oscar = OSCARClient({"endpoint": "url", "auth_user": "user", "auth_password": "pass", "ssl_verify": False}, "cid")