# Path: goodreads_api_client/resources/book.py
# class Book(Resource):
#     resource_name = 'book'
# 
#     def id_to_work_id(self, ids: Iterable[str]):
#         id_csv = ','.join(ids)
#         endpoint = 'book/id_to_work_id/{}'.format(id_csv)
#         res = self._transport.req(endpoint=endpoint)
#         return res['work-ids']
# 
#     def isbn_to_id(self, isbns: Iterable[str]):
#         raise NotImplementedError('API always 404s on this endpoint')
# 
#     def review_counts(self, isbns: Iterable[str]):
#         # This endpoint 406s on non-json content type
#         endpoint = 'book/review_counts.json'
#         params = {
#             'isbns': ','.join(set(isbns)),
#         }
#         res = self._transport.req(endpoint=endpoint, params=params,
#                                   transform='json')
#         return res['books']
# 
#     def show(self, id_: str):
#         return self._show_single_resource(id_)
# 
#     def show_by_isbn(self, isbn: str):
#         endpoint = 'book/isbn/{}'.format(isbn)
#         res = self._transport.req(endpoint=endpoint)
#         return res['book']
# 
#     def title(self, title: str, author: str=None, rating: int=None):
#         endpoint = 'book/title'
#         params = {
#             'author': author,
#             'rating': rating,
#             'title': title,
#         }
#         res = self._transport.req(endpoint=endpoint, params=params)
#         return res['book']
# 
# Path: goodreads_api_client/tests/resources/conftest.py
# class ResourceTestCase(unittest.TestCase):
#     @classmethod
#     def setUpClass(cls):
#         """Run both child class setup, as well as this class setup.
# 
#         Taken from https://gist.github.com/twolfson/13f5f5784f67fd49b245.
#         """
#         if cls is not ResourceTestCase and \
#                 cls.setUp is not ResourceTestCase.setUp:
#             child_setup = cls.setUp
# 
#             def merged_setup(self, *args, **kwargs):
#                 ResourceTestCase.setUp(self)
#                 return child_setup(self, *args, **kwargs)
# 
#             cls.setUp = merged_setup
# 
#     def setUp(self):
#         self._transport = Transport(developer_key=developer_key,
#                                     developer_secret=developer_secret)
# 
#         patch_transport = patch.object(Transport, 'session', requests)
#         patch_transport.start()
# 
#         self.addCleanup(patch_transport.stop)
# 
#         if self._transport.is_using_session():
#             self.addCleanup(self._transport.session.close)
# 
# Path: goodreads_api_client/tests/conftest.py
# def make_vcr():


from goodreads_api_client.resources import Book
from goodreads_api_client.tests.resources.conftest import ResourceTestCase
from goodreads_api_client.tests.conftest import vcr


class TestBook(ResourceTestCase):
    def setUp(self):
        self._book = Book(transport=self._transport)

    @vcr.use_cassette('book/id_to_work_id.yaml')
    def test_id_to_work_id(self):
        result = self._book.id_to_work_id(['1842', '1867'])

        self.assertEqual(result['item'], ['2138852', '5985'])

    @vcr.use_cassette('book/review_counts.yaml')
    def test_review_counts(self):
        result = self._book.review_counts(['0441172717'])

        self.assertEqual(len(result), 1)
        self.assertEqual(result[0]['id'], 53732)
        self.assertEqual(result[0]['isbn'], '0441172717')
        self.assertEqual(result[0]['isbn13'], '9780441172719')


# Path: goodreads_api_client/resources/book.py
# class Book(Resource):
#     resource_name = 'book'
# 
#     def id_to_work_id(self, ids: Iterable[str]):
#         id_csv = ','.join(ids)
#         endpoint = 'book/id_to_work_id/{}'.format(id_csv)
#         res = self._transport.req(endpoint=endpoint)
#         return res['work-ids']
# 
#     def isbn_to_id(self, isbns: Iterable[str]):
#         raise NotImplementedError('API always 404s on this endpoint')
# 
#     def review_counts(self, isbns: Iterable[str]):
#         # This endpoint 406s on non-json content type
#         endpoint = 'book/review_counts.json'
#         params = {
#             'isbns': ','.join(set(isbns)),
#         }
#         res = self._transport.req(endpoint=endpoint, params=params,
#                                   transform='json')
#         return res['books']
# 
#     def show(self, id_: str):
#         return self._show_single_resource(id_)
# 
#     def show_by_isbn(self, isbn: str):
#         endpoint = 'book/isbn/{}'.format(isbn)
#         res = self._transport.req(endpoint=endpoint)
#         return res['book']
# 
#     def title(self, title: str, author: str=None, rating: int=None):
#         endpoint = 'book/title'
#         params = {
#             'author': author,
#             'rating': rating,
#             'title': title,
#         }
#         res = self._transport.req(endpoint=endpoint, params=params)
#         return res['book']
# 
# Path: goodreads_api_client/tests/resources/conftest.py
# class ResourceTestCase(unittest.TestCase):
#     @classmethod
#     def setUpClass(cls):
#         """Run both child class setup, as well as this class setup.
# 
#         Taken from https://gist.github.com/twolfson/13f5f5784f67fd49b245.
#         """
#         if cls is not ResourceTestCase and \
#                 cls.setUp is not ResourceTestCase.setUp:
#             child_setup = cls.setUp
# 
#             def merged_setup(self, *args, **kwargs):
#                 ResourceTestCase.setUp(self)
#                 return child_setup(self, *args, **kwargs)
# 
#             cls.setUp = merged_setup
# 
#     def setUp(self):
#         self._transport = Transport(developer_key=developer_key,
#                                     developer_secret=developer_secret)
# 
#         patch_transport = patch.object(Transport, 'session', requests)
#         patch_transport.start()
# 
#         self.addCleanup(patch_transport.stop)
# 
#         if self._transport.is_using_session():
#             self.addCleanup(self._transport.session.close)
# 
# Path: goodreads_api_client/tests/conftest.py
# def make_vcr():


# Path: goodreads_api_client/tests/resources/test_book.py
from goodreads_api_client.resources import Book
from goodreads_api_client.tests.resources.conftest import ResourceTestCase
from goodreads_api_client.tests.conftest import vcr



class TestBook(ResourceTestCase):
    def setUp(self):
        self._book = Book(transport=self._transport)

    @vcr.use_cassette('book/id_to_work_id.yaml')
    def test_id_to_work_id(self):
        result = self._book.id_to_work_id(['1842', '1867'])

        self.assertEqual(result['item'], ['2138852', '5985'])

    @vcr.use_cassette('book/review_counts.yaml')
    def test_review_counts(self):
        result = self._book.review_counts(['0441172717'])

        self.assertEqual(len(result), 1)
        self.assertEqual(result[0]['id'], 53732)
        self.assertEqual(result[0]['isbn'], '0441172717')
        self.assertEqual(result[0]['isbn13'], '9780441172719')


    @vcr.use_cassette('book/show.yaml')