Beispiel #1
0
    def test_initialization(self):
        # An error is raised if SeriesLane is created with an empty string.
        pytest.raises(ValueError, SeriesLane, self._default_library, "")
        pytest.raises(ValueError, SeriesLane, self._default_library, None)

        work = self._work(language="spa", audience=[Classifier.AUDIENCE_CHILDREN])
        work_based_lane = WorkBasedLane(self._default_library, work)
        child = SeriesLane(
            self._default_library,
            "Alrighty Then",
            parent=work_based_lane,
            languages=["eng"],
            audiences=["another audience"],
        )

        # The series provided in the constructor is stored as .series.
        assert "Alrighty Then" == child.series

        # The SeriesLane is added as a child of its parent
        # WorkBasedLane -- something that doesn't happen by default.
        assert [child] == work_based_lane.children

        # As a side effect of that, this lane's audiences and
        # languages were changed to values consistent with its parent.
        assert [work_based_lane.source_audience] == child.audiences
        assert work_based_lane.languages == child.languages

        # If for some reason there's no audience for the work used as
        # a basis for the parent lane, the parent lane's audience
        # filter is used as a basis for the child lane's audience filter.
        work_based_lane.source_audience = None
        child = SeriesLane(self._default_library, "No Audience", parent=work_based_lane)
        assert work_based_lane.audiences == child.audiences
Beispiel #2
0
    def test_childrens_series_with_same_name_as_adult_series(self):
        [children, ya, adult, adults_only] = self.sample_works_for_each_audience()

        # Give them all the same series name.
        series_name = "Monkey Business"
        for work in [children, adult, adults_only]:
            work.presentation_edition.series = series_name
        self._db.commit()
        SessionManager.refresh_materialized_views(self._db)

        # SeriesLane only returns works that match a given audience.
        children_lane = SeriesLane(
            self._default_library, series_name, audiences=[Classifier.AUDIENCE_CHILDREN]
        )
        self.assert_works_queries(children_lane, [children])

        # It's strict about this, in an attempt to increase series accuracy.
        # A request for adult material, only returns Adult material, not
        # Adults Only material.
        adult_lane = SeriesLane(
            self._default_library, series_name, audiences=[Classifier.AUDIENCE_ADULT]
        )
        self.assert_works_queries(adult_lane, [adult])

        adult_lane = SeriesLane(
            self._default_library, series_name, audiences=[Classifier.AUDIENCE_ADULTS_ONLY]
        )
        self.assert_works_queries(adult_lane, [adults_only])
Beispiel #3
0
    def test_overview_facets(self):
        # A FeaturedFacets object is adapted to a SeriesFacets object.
        # This guarantees that a SeriesLane's contributions to a
        # grouped feed will be ordered correctly.
        featured = FeaturedFacets(0.44, entrypoint=AudiobooksEntryPoint)
        lane = SeriesLane(self._default_library, "Alrighty Then")
        overview = lane.overview_facets(self._db, featured)
        assert isinstance(overview, SeriesFacets)
        assert Facets.COLLECTION_FULL == overview.collection
        assert Facets.AVAILABLE_ALL == overview.availability
        assert Facets.ORDER_SERIES_POSITION == overview.order

        # Entry point was preserved.
        assert AudiobooksEntryPoint == overview.entrypoint
Beispiel #4
0
    def test_initialization(self):
        # An error is raised if SeriesLane is created with an empty string.
        assert_raises(ValueError, SeriesLane, self._db, self._default_library,
                      '')

        lane = SeriesLane(self._db, self._default_library, 'Alrighty Then')
        eq_('Alrighty Then', lane.series)
Beispiel #5
0
    def test_initialization(self):
        # An error is raised if SeriesLane is created with an empty string.
        assert_raises(
            ValueError, SeriesLane, self._default_library, ''
        )
        assert_raises(
            ValueError, SeriesLane, self._default_library, None
        )

        work = self._work(
            language='spa', audience=[Classifier.AUDIENCE_CHILDREN]
        )
        work_based_lane = WorkBasedLane(self._default_library, work)
        child = SeriesLane(self._default_library, "Alrighty Then",
                           parent=work_based_lane, languages=['eng'],
                           audiences=['another audience'])

        # The series provided in the constructor is stored as .series.
        eq_("Alrighty Then", child.series)

        # The SeriesLane is added as a child of its parent
        # WorkBasedLane -- something that doesn't happen by default.
        eq_([child], work_based_lane.children)

        # As a side effect of that, this lane's audiences and
        # languages were changed to values consistent with its parent.
        eq_([work_based_lane.source_audience], child.audiences)
        eq_(work_based_lane.languages, child.languages)
Beispiel #6
0
    def test_works_query(self):
        # If there are no works with the series name, no works are returned.
        series_name = "Like As If Whatever Mysteries"
        lane = SeriesLane(self._default_library, series_name)
        self.assert_works_queries(lane, [])

        # Works in the series are returned as expected.
        w1 = self._work(with_license_pool=True)
        w1.presentation_edition.series = series_name
        self._db.commit()
        SessionManager.refresh_materialized_views(self._db)
        self.assert_works_queries(lane, [w1])

        # When there are two works without series_position, they're
        # returned in alphabetical order by title.
        w1.presentation_edition.title = "Zoology"
        w2 = self._work(with_license_pool=True)
        w2.presentation_edition.title = "Anthropology"
        w2.presentation_edition.series = series_name
        self._db.commit()
        SessionManager.refresh_materialized_views(self._db)
        self.assert_works_queries(lane, [w2, w1])

        # If a series_position is added, they're ordered in numerical order.
        w1.presentation_edition.series_position = 6
        w2.presentation_edition.series_position = 13
        self._db.commit()
        SessionManager.refresh_materialized_views(self._db)
        self.assert_works_queries(lane, [w1, w2])

        # If the lane is created with languages, works in other languages
        # aren't included.
        fre = self._work(with_license_pool=True, language='fre')
        spa = self._work(with_license_pool=True, language='spa')
        for work in [fre, spa]:
            work.presentation_edition.series = series_name
        self._db.commit()
        SessionManager.refresh_materialized_views(self._db)

        lane.languages = ['fre', 'spa']
        self.assert_works_queries(lane, [fre, spa])
    def test_works_query(self):
        # If there are no works with the series name, no works are returned.
        series_name = "Like As If Whatever Mysteries"
        lane = SeriesLane(self._default_library, series_name)
        self.assert_works_queries(lane, [])

        # Works in the series are returned as expected.
        w1 = self._work(with_license_pool=True)
        w1.presentation_edition.series = series_name
        self._db.commit()
        SessionManager.refresh_materialized_views(self._db)
        self.assert_works_queries(lane, [w1])

        # When there are two works without series_position, they're
        # returned in alphabetical order by title.
        w1.presentation_edition.title = "Zoology"
        w2 = self._work(with_license_pool=True)
        w2.presentation_edition.title = "Anthropology"
        w2.presentation_edition.series = series_name
        self._db.commit()
        SessionManager.refresh_materialized_views(self._db)
        self.assert_works_queries(lane, [w2, w1])

        # If a series_position is added, they're ordered in numerical order.
        w1.presentation_edition.series_position = 6
        w2.presentation_edition.series_position = 13
        self._db.commit()
        SessionManager.refresh_materialized_views(self._db)
        self.assert_works_queries(lane, [w1, w2])

        # If the lane is created with languages, works in other languages
        # aren't included.
        fre = self._work(with_license_pool=True, language='fre')
        spa = self._work(with_license_pool=True, language='spa')
        for work in [fre, spa]:
            work.presentation_edition.series = series_name
        self._db.commit()
        SessionManager.refresh_materialized_views(self._db)

        lane.languages = ['fre', 'spa']
        self.assert_works_queries(lane, [fre, spa])
Beispiel #8
0
    def test_facets_entry_point_propagated(self):
        """The facets passed in to SeriesLane.featured_works are converted
        to a FeaturedSeriesFacets object with the same entry point.
        """
        lane = SeriesLane(self._default_library, "A series")
        def mock_works(_db, facets, pagination):
            self.called_with = facets
            # It doesn't matter what the query we return matches; just
            # return some kind of query.
            return _db.query(MaterializedWorkWithGenre)
        lane.works = mock_works
        entrypoint = object()
        facets = FacetsWithEntryPoint(entrypoint=entrypoint)
        lane.featured_works(self._db, facets=facets)

        new_facets = self.called_with
        assert isinstance(new_facets, FeaturedSeriesFacets)
        eq_(entrypoint, new_facets.entrypoint)

        # Availability facets have been hard-coded rather than propagated.
        eq_(FeaturedSeriesFacets.COLLECTION_FULL, new_facets.collection)
        eq_(FeaturedSeriesFacets.AVAILABLE_ALL, new_facets.availability)
    def test_facets_entry_point_propagated(self):
        """The facets passed in to SeriesLane.featured_works are converted
        to a FeaturedSeriesFacets object with the same entry point.
        """
        lane = SeriesLane(self._default_library, "A series")
        def mock_works(_db, facets, pagination):
            self.called_with = facets
            # It doesn't matter what the query we return matches; just
            # return some kind of query.
            return _db.query(MaterializedWorkWithGenre)
        lane.works = mock_works
        entrypoint = object()
        facets = FacetsWithEntryPoint(entrypoint=entrypoint)
        lane.featured_works(self._db, facets=facets)

        new_facets = self.called_with
        assert isinstance(new_facets, FeaturedSeriesFacets)
        eq_(entrypoint, new_facets.entrypoint)

        # Availability facets have been hard-coded rather than propagated.
        eq_(FeaturedSeriesFacets.COLLECTION_FULL, new_facets.collection)
        eq_(FeaturedSeriesFacets.AVAILABLE_ALL, new_facets.availability)
Beispiel #10
0
 def test_modify_search_filter_hook(self):
     lane = SeriesLane(self._default_library, "So That Happened")
     filter = Filter()
     lane.modify_search_filter_hook(filter)
     assert "So That Happened" == filter.series