# Path: groupy/api/memberships.py
# class Memberships(base.Manager):
# class Member(base.ManagedResource):
# class MembershipRequest(base.ManagedResource):
#     def __init__(self, session, group_id):
#     def add(self, nickname, email=None, phone_number=None, user_id=None):
#     def add_multiple(self, *users):
#     def check(self, results_id):
#     def update(self, nickname=None, **kwargs):
#     def remove(self, membership_id):
#     def __init__(self, manager, group_id, **data):
#     def __repr__(self):
#     def __eq__(self, other):
#     def post(self, text=None, attachments=None, source_guid=None):
#     def is_blocked(self):
#     def block(self):
#     def unblock(self):
#     def remove(self):
#     def add_to_group(self, group_id, nickname=None):
#     def __init__(self, manager, *requests, **data):
#     def check_if_ready(self):
#     def get_failed_requests(self, results):
#     def get_new_members(self, results):
#     def is_ready(self, check=True):
#     def poll(self, timeout=30, interval=2):
#     def get(self):
# 
# Path: groupy/exceptions.py
# class ResultsNotReady(ResultsError):
#     """Exception raised when results are not yet ready.
# 
#     :param response: the response
#     :type response: :class:`~requests.Response`
#     :param str message: a description of the exception
#     """
# 
#     def __init__(self, response, message='The results are not ready yet'):
#         super().__init__(response, message)
# 
# Path: groupy/exceptions.py
# class ResultsExpired(ResultsError):
#     """Exception raised when the results have expired.
# 
#     :param response: the response
#     :type response: :class:`~requests.Response`
#     :param str message: a description of the exception
#     """
# 
#     def __init__(self, response, message='The results have expired'):
#         super().__init__(response, message)
# 
# Path: tests/api/base.py
# def get_fake_response(code=200, data=None):
#     response = mock.Mock()
#     response.status_code = code
#     response.data = data
#     return response
# 
# def get_fake_member_data(**kwargs):
#     data = {
#         'id': 'foo',
#         'user_id': 'baz',
#         'nickname': 'nick',
#     }
#     data.update(kwargs)
#     return data
# 
# Path: tests/api/base.py
# class TestCase(unittest.TestCase):
#     def assert_kwargs(self, mock, **kwargs):
#         __, m_kwargs = mock.call_args
#         for k, v in kwargs.items():
#             with self.subTest(key=k, value=v):
#                 self.assertEqual(m_kwargs.get(k), v)


from unittest import mock
from groupy.api import memberships
from groupy.exceptions import ResultsNotReady
from groupy.exceptions import ResultsExpired
from .base import get_fake_response, get_fake_member_data
from .base import TestCase



class MembershipsTests(TestCase):
    def setUp(self):
        self.m_session = mock.Mock()
        self.memberships = memberships.Memberships(self.m_session,
                                                   group_id='foo')


class AddMembershipTests(MembershipsTests):
    def setUp(self):
        super().setUp()
        self.members = [{'bar': 'baz'}, {'baz': 'qux'}]
        self.m_session.post.return_value = get_fake_response(data={'qux': 'quux'})
        self.result = self.memberships.add(*self.members)

    def test_result_is_MembershipRequest(self):
        self.assertIsInstance(self.result, memberships.MembershipRequest)

    def test_payload_contained_guids(self):
        __, kwargs = self.m_session.post.call_args
        for member in kwargs['json']['members']:
            with self.subTest(member=member):
                self.assertIn('guid', member)


class CheckMembershipTests(MembershipsTests):
    def test_results_not_ready_yet(self):
        self.m_session.get.return_value = get_fake_response(code=503)

# Path: groupy/api/memberships.py
# class Memberships(base.Manager):
# class Member(base.ManagedResource):
# class MembershipRequest(base.ManagedResource):
#     def __init__(self, session, group_id):
#     def add(self, nickname, email=None, phone_number=None, user_id=None):
#     def add_multiple(self, *users):
#     def check(self, results_id):
#     def update(self, nickname=None, **kwargs):
#     def remove(self, membership_id):
#     def __init__(self, manager, group_id, **data):
#     def __repr__(self):
#     def __eq__(self, other):
#     def post(self, text=None, attachments=None, source_guid=None):
#     def is_blocked(self):
#     def block(self):
#     def unblock(self):
#     def remove(self):
#     def add_to_group(self, group_id, nickname=None):
#     def __init__(self, manager, *requests, **data):
#     def check_if_ready(self):
#     def get_failed_requests(self, results):
#     def get_new_members(self, results):
#     def is_ready(self, check=True):
#     def poll(self, timeout=30, interval=2):
#     def get(self):
# 
# Path: groupy/exceptions.py
# class ResultsNotReady(ResultsError):
#     """Exception raised when results are not yet ready.
# 
#     :param response: the response
#     :type response: :class:`~requests.Response`
#     :param str message: a description of the exception
#     """
# 
#     def __init__(self, response, message='The results are not ready yet'):
#         super().__init__(response, message)
# 
# Path: groupy/exceptions.py
# class ResultsExpired(ResultsError):
#     """Exception raised when the results have expired.
# 
#     :param response: the response
#     :type response: :class:`~requests.Response`
#     :param str message: a description of the exception
#     """
# 
#     def __init__(self, response, message='The results have expired'):
#         super().__init__(response, message)
# 
# Path: tests/api/base.py
# def get_fake_response(code=200, data=None):
#     response = mock.Mock()
#     response.status_code = code
#     response.data = data
#     return response
# 
# def get_fake_member_data(**kwargs):
#     data = {
#         'id': 'foo',
#         'user_id': 'baz',
#         'nickname': 'nick',
#     }
#     data.update(kwargs)
#     return data
# 
# Path: tests/api/base.py
# class TestCase(unittest.TestCase):
#     def assert_kwargs(self, mock, **kwargs):
#         __, m_kwargs = mock.call_args
#         for k, v in kwargs.items():
#             with self.subTest(key=k, value=v):
#                 self.assertEqual(m_kwargs.get(k), v)


# Path: tests/api/test_memberships.py
from unittest import mock
from groupy.api import memberships
from groupy.exceptions import ResultsNotReady
from groupy.exceptions import ResultsExpired
from .base import get_fake_response, get_fake_member_data
from .base import TestCase




class MembershipsTests(TestCase):
    def setUp(self):
        self.m_session = mock.Mock()
        self.memberships = memberships.Memberships(self.m_session,
                                                   group_id='foo')


class AddMembershipTests(MembershipsTests):
    def setUp(self):
        super().setUp()
        self.members = [{'bar': 'baz'}, {'baz': 'qux'}]
        self.m_session.post.return_value = get_fake_response(data={'qux': 'quux'})
        self.result = self.memberships.add(*self.members)

    def test_result_is_MembershipRequest(self):
        self.assertIsInstance(self.result, memberships.MembershipRequest)

    def test_payload_contained_guids(self):
        __, kwargs = self.m_session.post.call_args
        for member in kwargs['json']['members']:
            with self.subTest(member=member):
                self.assertIn('guid', member)


class CheckMembershipTests(MembershipsTests):
    def test_results_not_ready_yet(self):
        self.m_session.get.return_value = get_fake_response(code=503)

        with self.assertRaises(ResultsNotReady):