Exemplo n.º 1
0
    def test_with_existing_path(self):
        """
        For non-custom-facet facets the new path should be stacked on
        top of the current path unless the new path and old path are
        for the same facet type.

        Note: Because the paths stack, custom facets don't follow this
              structure.

        """
        paths_and_included_facet_types = [
            ('/new-york/new-york/usa/jobs/', ['city', 'state', 'country']),

            ('new-york/new-york/usa/jobs/jpmorgan-chase/careers/',
             ['company', 'city', 'state', 'country']),

            ('/retail-store-shift-supervisor/jobs-in/', ['title']),

            ('retail-store-shift-supervisor/jobs-in/indiana/usa/jobs/',
             ['title', 'city', 'state', 'country'])
        ]

        facet_counts = {}

        slab = 'electronics-technician/ET/navy/vet-jobs::Electronics Technician'

        num_items = self.config.num_filter_items_to_show + 1

        for filter_type in filter_types:
            items = []
            for i in range(num_items):
                items.append((slab, 5))
            facet_counts['%s_slab' % filter_type] = items

        for path, included_slug_types in paths_and_included_facet_types:
            filters = helpers.build_filter_dict(path)
            request = DummyRequest(path)
            widgets = helpers.get_widgets(request, self.config, facet_counts,
                                          custom_facets=[],
                                          filters=filters)
            for widget in widgets:
                for filter_type, value in filters.iteritems():
                    # If the path isn't being overwritten, there slug
                    # from the existing path should appear the same
                    # number of times that there are elements in the widget.
                    if value and widget.widget_type not in included_slug_types:
                        matches = list(finditer(value, widget.render()))
                        self.assertEqual(len(matches), num_items)
                    elif value and widget.facet_type_to_slug() == filter_type:
                        matches = list(finditer(value, widget.render()))
                        self.assertEqual(len(matches), 0)
                    elif value:
                        matches = list(finditer(value, widget.render()))
                        self.assertEqual(len(matches), num_items)
Exemplo n.º 2
0
    def test_get_facet_count_key(self):
        """
        Tests that we're getting unique or matching cache keys based on
        filter paths

        """
        filters1 = build_filter_dict('/standard-facet/new-jobs/dubuque/jobs/')
        filters2 = build_filter_dict('/特殊字符/new-jobs/')
        filters3 = build_filter_dict('/dubuque/jobs/standard-facet/new-jobs/')

        key1 = get_facet_count_key(filters1)
        key2 = get_facet_count_key(filters2)
        key3 = get_facet_count_key(filters3)
        settings.SITE_ID = 10
        key4 = get_facet_count_key(filters1)

        self.assertNotEqual(key2, key3)
        self.assertNotEqual(key2, key1)
        self.assertNotEqual(key4, key1)
        self.assertEqual(key1, key3)
Exemplo n.º 3
0
    def test_with_custom_facet_existing_path(self):
        """
        For custom facets the new path should be stacked on
        top of the current path.

        """
        facet_counts = {}

        slab = 'taco-truck-driver/new-jobs::Taco Truck Driver'

        num_items = self.config.num_filter_items_to_show + 1

        for filter_type in filter_types:
            items = []
            for i in range(num_items):
                items.append((slab, 5))
            facet_counts['%s_slab' % filter_type] = items

        facet_counts['facet_slab'] = []
        for i in range(num_items):
            facet = factories.CustomFacetFactory(name='Test', url_slab=slab)
            facet_counts['facet_slab'].append((facet, 5))

        path = '/mechanic-jobs/new-jobs/'
        filters = helpers.build_filter_dict(path)
        request = DummyRequest(path)
        custom_facets = facet_counts['facet_slab']
        widgets = helpers.get_widgets(request,
                                      self.config,
                                      facet_counts,
                                      custom_facets=custom_facets,
                                      filters=filters)
        for widget in widgets:
            if widget.widget_type == 'facet':
                new_path = '/mechanic-jobs/taco-truck-driver/new-jobs/'
                matches = list(finditer(new_path, widget.render()))
                self.assertEqual(len(matches), num_items)
Exemplo n.º 4
0
    def test_with_custom_facet_existing_path(self):
        """
        For custom facets the new path should be stacked on
        top of the current path.

        """
        facet_counts = {}

        slab = 'taco-truck-driver/new-jobs::Taco Truck Driver'

        num_items = self.config.num_filter_items_to_show + 1

        for filter_type in filter_types:
            items = []
            for i in range(num_items):
                items.append((slab, 5))
            facet_counts['%s_slab' % filter_type] = items

        facet_counts['facet_slab'] = []
        for i in range(num_items):
            facet = factories.CustomFacetFactory(name='Test',
                                                 url_slab=slab)
            facet_counts['facet_slab'].append((facet, 5))

        path = '/mechanic-jobs/new-jobs/'
        filters = helpers.build_filter_dict(path)
        request = DummyRequest(path)
        custom_facets = facet_counts['facet_slab']
        widgets = helpers.get_widgets(request, self.config, facet_counts,
                                      custom_facets=custom_facets,
                                      filters=filters)
        for widget in widgets:
            if widget.widget_type == 'facet':
                new_path = '/mechanic-jobs/taco-truck-driver/new-jobs/'
                matches = list(finditer(new_path, widget.render()))
                self.assertEqual(len(matches), num_items)
Exemplo n.º 5
0
def get_filters(request):
    return helpers.build_filter_dict(request.path)
Exemplo n.º 6
0
    def test_custom_facet_multiple_groups(self):
        """
        Confirms that custom facet groups are hiding/showing correctly.

        """
        def get_num_of_widgets(*args, **kwargs):
            """
            Gets the number of widgets that actually have rendered content for
            a given get_widgets call.

            :param args: The args for helpers.get_widgets()
            :param kwargs: The kwargs for helpers.get_widgets()
            :return: The number of widgets with actual content able to be
                     rendered by helpers.get_widgets().

            """
            returned_widgets = helpers.get_widgets(*args, **kwargs)
            # Render only the facet widgets since they're the only
            # ones we actually care about.
            returned_widgets = [w.render() for w in returned_widgets]
            return len(filter(None, returned_widgets))

        facet_counts = {}

        slab = 'taco-truck-driver/new-jobs::Taco Truck Driver'

        num_items = self.config.num_filter_items_to_show + 1

        for filter_type in filter_types:
            items = []
            for i in range(num_items):
                items.append((slab, 5))
            facet_counts['%s_slab' % filter_type] = items

        facet_counts['facet_slab'] = []
        for i in range(1,5):
            seo_facets = factories.SeoSiteFacetFactory.create_batch(num_items, seosite=self.site,
                                                                    facet_group=i)
            for seo_facet in seo_facets:
                facet_counts['facet_slab'].append((seo_facet.customfacet, 5))

        path = '/mechanic-jobs/new-jobs/'
        filters = helpers.build_filter_dict(path)
        request = DummyRequest(path)
        custom_facets = facet_counts['facet_slab']

        # Show only the default custom facet group.
        self.config.browse_facet_show = True
        self.config.save()
        num_widgets = get_num_of_widgets(request, self.config, facet_counts,
                                         custom_facets=custom_facets,
                                         filters=filters)
        # 6 default widgets + 1 custom facet widget
        self.assertEqual(num_widgets, 7)

        # Show two of the custom facet groups.
        self.config.browse_facet_show_2 = True
        self.config.save()
        num_widgets = get_num_of_widgets(request, self.config, facet_counts,
                                         custom_facets=custom_facets,
                                         filters=filters)
        self.assertEqual(num_widgets, 8)

        # Show three custom facet groups.
        self.config.browse_facet_show_3 = True
        self.config.save()
        num_widgets = get_num_of_widgets(request, self.config, facet_counts,
                                         custom_facets=custom_facets,
                                         filters=filters)
        self.assertEqual(num_widgets, 9)

        # Show four custom facet groups
        self.config.browse_facet_show_4 = True
        self.config.save()
        num_widgets = get_num_of_widgets(request, self.config, facet_counts,
                                         custom_facets=custom_facets,
                                         filters=filters)
        self.assertEqual(num_widgets, 10)
Exemplo n.º 7
0
def get_filters(request):
    return helpers.build_filter_dict(request.path)