Ejemplo n.º 1
0
    def test_book_info_to_circulation_advantage(self):
        # Overdrive Advantage accounts derive different information
        # from the same API responses as regular Overdrive accounts.
        raw, info = self.sample_json("overdrive_availability_advantage.json")

        extractor = OverdriveRepresentationExtractor(self.api)
        consortial_data = extractor.book_info_to_circulation(info)
        assert 2 == consortial_data.licenses_owned
        assert 2 == consortial_data.licenses_available

        class MockAPI(object):
            # Pretend to be an API for an Overdrive Advantage collection with
            # library ID 61.
            advantage_library_id = 61

        extractor = OverdriveRepresentationExtractor(MockAPI())
        advantage_data = extractor.book_info_to_circulation(info)
        assert 1 == advantage_data.licenses_owned
        assert 1 == advantage_data.licenses_available

        # Both collections have the same information about active
        # holds, because that information is not split out by
        # collection.
        assert 0 == advantage_data.patrons_in_hold_queue
        assert 0 == consortial_data.patrons_in_hold_queue

        # If for whatever reason Overdrive doesn't mention the
        # relevant collection at all, no collection-specific
        # information is gleaned.
        #
        # TODO: It would probably be better not to return a
        # CirculationData object at all, but this shouldn't happen in
        # a real scenario.
        class MockAPI(object):
            # Pretend to be an API for an Overdrive Advantage collection with
            # library ID 62.
            advantage_library_id = 62

        extractor = OverdriveRepresentationExtractor(MockAPI())
        advantage_data = extractor.book_info_to_circulation(info)
        assert None == advantage_data.licenses_owned
        assert None == advantage_data.licenses_available
        assert 0 == consortial_data.patrons_in_hold_queue
Ejemplo n.º 2
0
    def test_not_found_error_to_circulationdata(self):
        raw, info = self.sample_json("overdrive_availability_not_found.json")

        # By default, a "NotFound" error can't be converted to a
        # CirculationData object, because we don't know _which_ book it
        # was that wasn't found.
        extractor = OverdriveRepresentationExtractor(self.api)
        m = extractor.book_info_to_circulation
        assert None == m(info)

        # However, if an ID was added to `info` ahead of time (as the
        # circulation code does), we do know, and we can create a
        # CirculationData.
        identifier = self._identifier(identifier_type=Identifier.OVERDRIVE_ID)
        info["id"] = identifier.identifier
        data = m(info)
        assert identifier == data.primary_identifier(self._db)
        assert 0 == data.licenses_owned
        assert 0 == data.licenses_available
        assert 0 == data.patrons_in_hold_queue
Ejemplo n.º 3
0
    def test_book_info_to_circulation(self):
        # Tests that can convert an overdrive json block into a CirculationData object.

        raw, info = self.sample_json("overdrive_availability_information.json")
        extractor = OverdriveRepresentationExtractor(self.api)
        circulationdata = extractor.book_info_to_circulation(info)

        # NOTE: It's not realistic for licenses_available and
        # patrons_in_hold_queue to both be nonzero; this is just to
        # verify that the test picks up whatever data is in the
        # document.
        assert 3 == circulationdata.licenses_owned
        assert 1 == circulationdata.licenses_available
        assert 10 == circulationdata.patrons_in_hold_queue

        # Related IDs.
        identifier = circulationdata.primary_identifier(self._db)
        assert (Identifier.OVERDRIVE_ID,
                "2a005d55-a417-4053-b90d-7a38ca6d2065") == (
                    identifier.type,
                    identifier.identifier,
                )