# Path: moira_client/client.py
# class Client:
#     def __init__(self, api_url, auth_custom=None, auth_user=None, auth_pass=None, login=None):
#         """
# 
#         :param api_url: str Moira API URL
#         :param auth_custom: dict auth custom headers
#         :param auth_user: str auth user
#         :param auth_pass: str auth password
#         :param login: str auth login
#         """
#         if not api_url.endswith('/'):
#             self.api_url = api_url + '/'
#         else:
#             self.api_url = api_url
# 
#         if not login and auth_user:
#             login = auth_user
# 
#         self.auth = None
#         self.headers = {
#             'X-Webauth-User': login,
#             'Content-Type': 'application/json',
#             'User-Agent': 'Python Moira Client'
#             }
# 
#         if auth_user and auth_pass:
#             self.auth = HTTPBasicAuth(auth_user, auth_pass)
# 
#         if auth_custom:
#             self.headers.update(auth_custom)
# 
#     def get(self, path='', **kwargs):
#         """
# 
#         :param path: str api path
#         :param kwargs: additional parameters for request
#         :return: dict response
# 
#         :raises: HTTPError
#         :raises: InvalidJSONError
#         """
#         r = requests.get(self._path_join(path), headers=self.headers, auth=self.auth, **kwargs)
#         r.raise_for_status()
#         try:
#             return r.json()
#         except ValueError:
#             raise InvalidJSONError(r.content)
# 
#     def delete(self, path='', **kwargs):
#         """
# 
#         :param path: str api path
#         :param kwargs: additional parameters for request
#         :return: dict response
# 
#         :raises: HTTPError
#         :raises: InvalidJSONError
#         """
#         r = requests.delete(self._path_join(path), headers=self.headers, auth=self.auth, **kwargs)
#         r.raise_for_status()
#         try:
#             return r.json()
#         except ValueError:
#             raise InvalidJSONError(r.content)
# 
#     def put(self, path='', **kwargs):
#         """
# 
#         :param path: str api path
#         :param kwargs: additional parameters for request
#         :return: dict response
# 
#         :raises: HTTPError
#         :raises: InvalidJSONError
#         """
#         r = requests.put(self._path_join(path), headers=self.headers, auth=self.auth, **kwargs)
#         r.raise_for_status()
#         try:
#             return r.json()
#         except ValueError:
#             raise InvalidJSONError(r.content)
# 
#     def post(self, path='', **kwargs):
#         """
# 
#         :param path: str api path
#         :param kwargs: additional parameters for request
#         :return: dict response
# 
#         :raises: HTTPError
#         :raises: InvalidJSONError
#         """
#         r = requests.post(self._path_join(path), headers=self.headers, auth=self.auth, **kwargs)
#         r.raise_for_status()
#         try:
#             return r.json()
#         except ValueError:
#             raise InvalidJSONError(r.content)
# 
#     def _path_join(self, *args):
#         path = self.api_url
#         for part in args:
#             path += part
#         return path
# 
# Path: moira_client/models/user.py
# class UserManager:
#     def __init__(self, client):
#         self._client = client
# 
#     def get_username(self):
#         """
#         Gets the username of the authenticated user if it is available.
# 
#         :return: login
# 
#         :raises: ResponseStructureError
#         """
#         result = self._client.get(self._full_path())
#         if 'login' not in result:
#             raise ResponseStructureError("'login' field doesn't exist in response", result)
#         return result['login']
# 
#     def get_user_settings(self):
#         """
#         Get the user's contacts and subscriptions.
# 
#         :return: user settings
# 
#         :raises: ResponseStructureError
#         """
#         result = self._client.get(self._full_path('settings'))
#         required = ['login', 'contacts', 'subscriptions']
#         for field in required:
#             if field not in result:
#                 raise ResponseStructureError("'{}' field doesn't exist in response".format(field), result)
# 
#         contacts = []
#         for contact in result['contacts']:
#             contacts.append(Contact(**contact))
#         result['contacts'] = contacts
# 
#         subscriptions = []
#         for subscription in result['subscriptions']:
#             subscriptions.append(Subscription(self._client, **subscription))
#         result['subscriptions'] = subscriptions
# 
#         return UserSettings(**result)
# 
#     def _full_path(self, path=''):
#         if path:
#             return 'user/{}'.format(path)
#         return 'user'
# 
# Path: tests/models/test_model.py
# class ModelTest(unittest.TestCase):
#     TEST_API_URL = 'http://test/url'
# 
#     @property
#     def api_url(self):
#         return self.TEST_API_URL


    from unittest.mock import Mock
    from unittest.mock import patch
    from mock import Mock
    from mock import patch
from moira_client.client import Client
from moira_client.models.user import UserManager
from .test_model import ModelTest
try:
except ImportError:




class UserTest(ModelTest):

    def test_get_settings(self):
        client = Client(self.api_url)
        user_manager = UserManager(client)

        with patch.object(client, 'get', return_value={'login': 'aaa', 'contacts': [], 'subscriptions': []}
                          ) as get_mock:
            res_settings = user_manager.get_user_settings()

        self.assertEqual(res_settings.login, 'aaa')

        self.assertTrue(get_mock.called)

    def test_response_example_from_docs(self):
        client = Client(self.api_url)

# Path: moira_client/client.py
# class Client:
#     def __init__(self, api_url, auth_custom=None, auth_user=None, auth_pass=None, login=None):
#         """
# 
#         :param api_url: str Moira API URL
#         :param auth_custom: dict auth custom headers
#         :param auth_user: str auth user
#         :param auth_pass: str auth password
#         :param login: str auth login
#         """
#         if not api_url.endswith('/'):
#             self.api_url = api_url + '/'
#         else:
#             self.api_url = api_url
# 
#         if not login and auth_user:
#             login = auth_user
# 
#         self.auth = None
#         self.headers = {
#             'X-Webauth-User': login,
#             'Content-Type': 'application/json',
#             'User-Agent': 'Python Moira Client'
#             }
# 
#         if auth_user and auth_pass:
#             self.auth = HTTPBasicAuth(auth_user, auth_pass)
# 
#         if auth_custom:
#             self.headers.update(auth_custom)
# 
#     def get(self, path='', **kwargs):
#         """
# 
#         :param path: str api path
#         :param kwargs: additional parameters for request
#         :return: dict response
# 
#         :raises: HTTPError
#         :raises: InvalidJSONError
#         """
#         r = requests.get(self._path_join(path), headers=self.headers, auth=self.auth, **kwargs)
#         r.raise_for_status()
#         try:
#             return r.json()
#         except ValueError:
#             raise InvalidJSONError(r.content)
# 
#     def delete(self, path='', **kwargs):
#         """
# 
#         :param path: str api path
#         :param kwargs: additional parameters for request
#         :return: dict response
# 
#         :raises: HTTPError
#         :raises: InvalidJSONError
#         """
#         r = requests.delete(self._path_join(path), headers=self.headers, auth=self.auth, **kwargs)
#         r.raise_for_status()
#         try:
#             return r.json()
#         except ValueError:
#             raise InvalidJSONError(r.content)
# 
#     def put(self, path='', **kwargs):
#         """
# 
#         :param path: str api path
#         :param kwargs: additional parameters for request
#         :return: dict response
# 
#         :raises: HTTPError
#         :raises: InvalidJSONError
#         """
#         r = requests.put(self._path_join(path), headers=self.headers, auth=self.auth, **kwargs)
#         r.raise_for_status()
#         try:
#             return r.json()
#         except ValueError:
#             raise InvalidJSONError(r.content)
# 
#     def post(self, path='', **kwargs):
#         """
# 
#         :param path: str api path
#         :param kwargs: additional parameters for request
#         :return: dict response
# 
#         :raises: HTTPError
#         :raises: InvalidJSONError
#         """
#         r = requests.post(self._path_join(path), headers=self.headers, auth=self.auth, **kwargs)
#         r.raise_for_status()
#         try:
#             return r.json()
#         except ValueError:
#             raise InvalidJSONError(r.content)
# 
#     def _path_join(self, *args):
#         path = self.api_url
#         for part in args:
#             path += part
#         return path
# 
# Path: moira_client/models/user.py
# class UserManager:
#     def __init__(self, client):
#         self._client = client
# 
#     def get_username(self):
#         """
#         Gets the username of the authenticated user if it is available.
# 
#         :return: login
# 
#         :raises: ResponseStructureError
#         """
#         result = self._client.get(self._full_path())
#         if 'login' not in result:
#             raise ResponseStructureError("'login' field doesn't exist in response", result)
#         return result['login']
# 
#     def get_user_settings(self):
#         """
#         Get the user's contacts and subscriptions.
# 
#         :return: user settings
# 
#         :raises: ResponseStructureError
#         """
#         result = self._client.get(self._full_path('settings'))
#         required = ['login', 'contacts', 'subscriptions']
#         for field in required:
#             if field not in result:
#                 raise ResponseStructureError("'{}' field doesn't exist in response".format(field), result)
# 
#         contacts = []
#         for contact in result['contacts']:
#             contacts.append(Contact(**contact))
#         result['contacts'] = contacts
# 
#         subscriptions = []
#         for subscription in result['subscriptions']:
#             subscriptions.append(Subscription(self._client, **subscription))
#         result['subscriptions'] = subscriptions
# 
#         return UserSettings(**result)
# 
#     def _full_path(self, path=''):
#         if path:
#             return 'user/{}'.format(path)
#         return 'user'
# 
# Path: tests/models/test_model.py
# class ModelTest(unittest.TestCase):
#     TEST_API_URL = 'http://test/url'
# 
#     @property
#     def api_url(self):
#         return self.TEST_API_URL


# Path: tests/models/test_user.py
    from unittest.mock import Mock
    from unittest.mock import patch
    from mock import Mock
    from mock import patch
from moira_client.client import Client
from moira_client.models.user import UserManager
from .test_model import ModelTest

try:
except ImportError:




class UserTest(ModelTest):

    def test_get_settings(self):
        client = Client(self.api_url)
        user_manager = UserManager(client)

        with patch.object(client, 'get', return_value={'login': 'aaa', 'contacts': [], 'subscriptions': []}
                          ) as get_mock:
            res_settings = user_manager.get_user_settings()

        self.assertEqual(res_settings.login, 'aaa')

        self.assertTrue(get_mock.called)

    def test_response_example_from_docs(self):
        client = Client(self.api_url)

        user_manager = UserManager(client)