Example #1
0
    def test_contributor_lane_generation(self):

        original = self.edition.contributions[0].contributor
        luthor, i = self._contributor("Luthor, Lex")
        self.edition.add_contributor(luthor, Contributor.EDITOR_ROLE)

        # Lex Luthor doesn't show up because he's only an editor,
        # and an author is listed.
        result = RelatedBooksLane(self._default_library, self.work, "")
        assert 1 == len(result.children)
        [sublane] = result.children
        assert original == sublane.contributor

        # A book with multiple contributors results in multiple
        # ContributorLane sublanes.
        lane, i = self._contributor("Lane, Lois")
        self.edition.add_contributor(lane, Contributor.PRIMARY_AUTHOR_ROLE)
        result = RelatedBooksLane(self._default_library, self.work, "")
        assert 2 == len(result.children)
        sublane_contributors = list()
        [sublane_contributors.append(c.contributor) for c in result.children]
        assert set([lane, original]) == set(sublane_contributors)

        # When there are no AUTHOR_ROLES present, contributors in
        # displayable secondary roles appear.
        for contribution in self.edition.contributions:
            if contribution.role in Contributor.AUTHOR_ROLES:
                self._db.delete(contribution)
        self._db.commit()

        result = RelatedBooksLane(self._default_library, self.work, "")
        assert 1 == len(result.children)
        [sublane] = result.children
        assert luthor == sublane.contributor
    def test_works_query(self):
        """RelatedBooksLane is an invisible, groups lane without works."""

        self.work.presentation_edition.series = "All By Myself"
        lane = RelatedBooksLane(self._db, self.lp, "")
        eq_(None, lane.works())
        eq_(None, lane.materialized_works())
Example #3
0
    def test_initialization(self):
        """Asserts that a RelatedBooksLane won't be initialized for a work
        without related books
        """

        # A book without a series or a contributor on a circ manager without
        # NoveList recommendations raises an error.
        self._db.delete(self.edition.contributions[0])
        self._db.commit()

        assert_raises(
            ValueError, RelatedBooksLane, self._default_library, self.work, ""
        )

        # A book with a contributor initializes a RelatedBooksLane.
        luthor, i = self._contributor('Luthor, Lex')
        self.edition.add_contributor(luthor, [Contributor.EDITOR_ROLE])

        result = RelatedBooksLane(self._default_library, self.work, '')
        eq_(self.work, result.work)
        [sublane] = result.children
        eq_(True, isinstance(sublane, ContributorLane))
        eq_(sublane.contributors, [luthor])

        # As does a book in a series.
        self.edition.series = "All By Myself"
        result = RelatedBooksLane(self._default_library, self.work, "")
        eq_(2, len(result.children))
        [contributor, series] = result.children
        eq_(True, isinstance(series, SeriesLane))

        # When NoveList is configured and recommendations are available,
        # a RecommendationLane will be included.
        self._external_integration(
            ExternalIntegration.NOVELIST,
            goal=ExternalIntegration.METADATA_GOAL, username=u'library',
            password=u'sure', libraries=[self._default_library]
        )
        mock_api = MockNoveListAPI(self._db)
        response = Metadata(
            self.edition.data_source, recommendations=[self._identifier()]
        )
        mock_api.setup(response)
        result = RelatedBooksLane(self._default_library, self.work, "", novelist_api=mock_api)
        eq_(3, len(result.children))

        # The book's language and audience list is passed down to all sublanes.
        eq_(['eng'], result.languages)
        for sublane in result.children:
            eq_(result.languages, sublane.languages)
            if isinstance(sublane, SeriesLane):
                eq_([result.source_audience], sublane.audiences)
            else:
                eq_(sorted(list(result.audiences)), sorted(list(sublane.audiences)))

        contributor, recommendations, series = result.children
        eq_(True, isinstance(recommendations, RecommendationLane))
        eq_(True, isinstance(series, SeriesLane))
        eq_(True, isinstance(contributor, ContributorLane))
Example #4
0
    def test_contributor_lane_generation(self):

        original = self.edition.contributions[0].contributor
        luthor, i = self._contributor('Luthor, Lex')
        self.edition.add_contributor(luthor, Contributor.EDITOR_ROLE)

        # Lex Luthor doesn't show up because he's only an editor,
        # and an author is listed.
        result = RelatedBooksLane(self._db, self._default_library, self.work,
                                  '')
        eq_(1, len(result.sublanes))
        [sublane] = result.sublanes
        eq_([original], sublane.contributors)

        # A book with multiple contributors results in multiple
        # ContributorLane sublanes.
        lane, i = self._contributor('Lane, Lois')
        self.edition.add_contributor(lane, Contributor.PRIMARY_AUTHOR_ROLE)
        result = RelatedBooksLane(self._db, self._default_library, self.work,
                                  '')
        eq_(2, len(result.sublanes))
        sublane_contributors = list()
        [sublane_contributors.extend(c.contributors) for c in result.sublanes]
        eq_(set([lane, original]), set(sublane_contributors))

        # When there are no AUTHOR_ROLES present, contributors in
        # displayable secondary roles appear.
        for contribution in self.edition.contributions:
            if contribution.role in Contributor.AUTHOR_ROLES:
                self._db.delete(contribution)
        self._db.commit()

        result = RelatedBooksLane(self._db, self._default_library, self.work,
                                  '')
        eq_(1, len(result.sublanes))
        [sublane] = result.sublanes
        eq_([luthor], sublane.contributors)
    def test_contributor_lane_generation(self):

        with temp_config() as config:
            config['integrations'][Configuration.NOVELIST_INTEGRATION] = {}

            original = self.edition.contributions[0].contributor
            luthor, i = self._contributor('Luthor, Lex')
            self.edition.add_contributor(luthor, Contributor.EDITOR_ROLE)

            # Lex Luthor doesn't show up because he's only an editor,
            # and an author is listed.
            result = RelatedBooksLane(self._db, self.lp, '')
            eq_(1, len(result.sublanes))
            [sublane] = result.sublanes
            eq_(original, sublane.contributor)

        # A book with multiple contributors results in multiple
        # ContributorLane sublanes.
        lane, i = self._contributor('Lane, Lois')
        self.edition.add_contributor(lane, Contributor.PRIMARY_AUTHOR_ROLE)
        result = RelatedBooksLane(self._db, self.lp, '')
        eq_(2, len(result.sublanes))
        sublane_contributors = [c.contributor for c in result.sublanes]
        eq_(set([lane, original]), set(sublane_contributors))

        # When there are no AUTHOR_ROLES present, contributors in
        # displayable secondary roles appear.
        for contribution in self.edition.contributions:
            if contribution.role in Contributor.AUTHOR_ROLES:
                self._db.delete(contribution)
        self._db.commit()

        result = RelatedBooksLane(self._db, self.lp, '')
        eq_(1, len(result.sublanes))
        [sublane] = result.sublanes
        eq_(luthor, sublane.contributor)
Example #6
0
    def test_works_query(self):
        """RelatedBooksLane is an invisible, groups lane without works."""

        self.edition.series = "All By Myself"
        lane = RelatedBooksLane(self._default_library, self.work, "")
        assert [] == lane.works(self._db)
Example #7
0
    def test_initialization(self):
        # Asserts that a RelatedBooksLane won't be initialized for a work
        # without related books

        # A book without a series or a contributor on a circ manager without
        # NoveList recommendations raises an error.
        self._db.delete(self.edition.contributions[0])
        self._db.commit()

        pytest.raises(
            ValueError, RelatedBooksLane, self._default_library, self.work, ""
        )

        # A book with a contributor initializes a RelatedBooksLane.
        luthor, i = self._contributor("Luthor, Lex")
        self.edition.add_contributor(luthor, [Contributor.EDITOR_ROLE])

        result = RelatedBooksLane(self._default_library, self.work, "")
        assert self.work == result.work
        [sublane] = result.children
        assert True == isinstance(sublane, ContributorLane)
        assert sublane.contributor == luthor

        # As does a book in a series.
        self.edition.series = "All By Myself"
        result = RelatedBooksLane(self._default_library, self.work, "")
        assert 2 == len(result.children)
        [contributor, series] = result.children
        assert True == isinstance(series, SeriesLane)

        # When NoveList is configured and recommendations are available,
        # a RecommendationLane will be included.
        self._external_integration(
            ExternalIntegration.NOVELIST,
            goal=ExternalIntegration.METADATA_GOAL,
            username="******",
            password="******",
            libraries=[self._default_library],
        )
        mock_api = MockNoveListAPI(self._db)
        response = Metadata(
            self.edition.data_source, recommendations=[self._identifier()]
        )
        mock_api.setup_method(response)
        result = RelatedBooksLane(
            self._default_library, self.work, "", novelist_api=mock_api
        )
        assert 3 == len(result.children)

        [novelist_recommendations] = [
            x for x in result.children if isinstance(x, RecommendationLane)
        ]
        assert (
            "Similar titles recommended by NoveList"
            == novelist_recommendations.display_name
        )

        # The book's language and audience list is passed down to all sublanes.
        assert ["eng"] == result.languages
        for sublane in result.children:
            assert result.languages == sublane.languages
            if isinstance(sublane, SeriesLane):
                assert [result.source_audience] == sublane.audiences
            else:
                assert sorted(list(result.audiences)) == sorted(list(sublane.audiences))

        contributor, recommendations, series = result.children
        assert True == isinstance(recommendations, RecommendationLane)
        assert True == isinstance(series, SeriesLane)
        assert True == isinstance(contributor, ContributorLane)
    def test_initialization(self):
        """Asserts that a RelatedBooksLane won't be initialized for a work
        without related books
        """

        with temp_config() as config:
            # A book without a series or a contributor on a circ manager without
            # NoveList recommendations raises an error.
            config['integrations'][Configuration.NOVELIST_INTEGRATION] = {}
            self._db.delete(self.edition.contributions[0])
            self._db.commit()

            assert_raises(ValueError, RelatedBooksLane, self._db, self.lp, "")

            # A book with a contributor initializes a RelatedBooksLane.
            luthor, i = self._contributor('Luthor, Lex')
            self.edition.add_contributor(luthor, [Contributor.EDITOR_ROLE])

            result = RelatedBooksLane(self._db, self.lp, '')
            eq_(self.lp, result.license_pool)
            [sublane] = result.sublanes
            eq_(True, isinstance(sublane, ContributorLane))
            eq_(sublane.contributor, luthor)

            # As does a book in a series.
            self.edition.series = "All By Myself"
            result = RelatedBooksLane(self._db, self.lp, "")
            eq_(2, len(result.sublanes))
            [contributor, series] = result.sublanes
            eq_(True, isinstance(series, SeriesLane))

        with temp_config() as config:
            config['integrations'][Configuration.NOVELIST_INTEGRATION] = {
                Configuration.NOVELIST_PROFILE: 'library',
                Configuration.NOVELIST_PASSWORD: '******'
            }
            # When NoveList is configured and recommendations are available,
            # a RecommendationLane will be included.
            mock_api = MockNoveListAPI()
            response = Metadata(self.lp.data_source,
                                recommendations=[self._identifier()])
            mock_api.setup(response)
            result = RelatedBooksLane(self._db,
                                      self.lp,
                                      "",
                                      novelist_api=mock_api)
            eq_(3, len(result.sublanes))

            # The book's language and audience list is passed down to all sublanes.
            eq_(['eng'], result.languages)
            for sublane in result.sublanes:
                eq_(result.languages, sublane.languages)
                if isinstance(sublane, SeriesLane):
                    eq_(set([result.source_audience]), sublane.audiences)
                else:
                    eq_(sorted(list(result.audiences)),
                        sorted(list(sublane.audiences)))

            contributor, recommendations, series = result.sublanes
            eq_(True, isinstance(recommendations, RecommendationLane))
            eq_(True, isinstance(series, SeriesLane))
            eq_(True, isinstance(contributor, ContributorLane))
    def test_works_query(self):
        """RelatedBooksLane is an invisible, groups lane without works."""

        self.edition.series = "All By Myself"
        lane = RelatedBooksLane(self._default_library, self.work, "")
        eq_([], lane.works(self._db).all())