示例#1
0
    def test_item_filter_more(self):
        """
        Test the result when a few filters are applied to the results.
        """
        query_tuple = [('limit', 0), ('item:extended_info:i_brand', 'Apple'),
                       ('item:subcategory', 'Laptop Computer'),
                       ('extended_info:app_type', 'tech')]
        request = RequestFactory().get(
            '/?limit=0&item:extended_info:i_brand=Apple&'
            'item:subcategory=Laptop+Computer&'
            'extended_info:app_type=tech')

        spots = get_spots_by_filter(query_tuple)
        filtered_spots = get_filtered_items(spots, request)
        self.assertNotEqual(
            get_item_count(spots), get_item_count(filtered_spots),
            "Filters weren't applied. All items were returned!")
        self.assertEqual(get_item_count(filtered_spots), 8,
                         "Invalid number of filtered items returned")
        for spot in filtered_spots:
            for item in spot.items:
                self.assertEqual(
                    item.brand, "Apple",
                    "Invalid brand for spot %s item %s made through the "
                    "filters." % (spot.name, item.name))
                self.assertEqual(
                    item.subcategory, "Laptop Computer",
                    "Invalid category for spot %s item %s made through the "
                    "filters." % (spot.name, item.name))
示例#2
0
    def test_item_filter(self):
        """
        Test the result when a few filters are applied to the results.
        """
        query_tuple = [
            ('limit', 0),
            ('item:extended_info:i_brand', 'Apple'),
            ('extended_info:app_type', 'tech')
        ]
        request = RequestFactory().get(
            '/?limit=0&item:extended_info:i_brand=Apple&'
            'extended_info:app_type=tech'
        )

        spots = get_spots_by_filter(query_tuple)
        filtered_spots = get_filtered_items(spots, request)
        self.assertNotEqual(
            get_item_count(spots),
            get_item_count(filtered_spots),
            "Filters weren't applied. All items were returned!"
        )
        self.assertEqual(
            get_item_count(filtered_spots),
            15,
            "Invalid number of filtered items returned"
        )
        for spot in filtered_spots:
            for item in spot.items:
                self.assertEqual(
                    item.brand,
                    "Apple",
                    "Invalid brand for spot %s item %s made through the "
                    "filters." % (spot.name, item.name)
                )
示例#3
0
    def test_item_nofilter(self):
        """
        Test the result when no filters are applied to the results.
        """
        query_tuple = [('limit', 0), ('extended_info:app_type', 'tech')]
        request = RequestFactory().get('/?limit=0&extended_info:app_type=tech')

        spots = get_spots_by_filter(query_tuple)
        filtered_spots = get_filtered_items(spots, request)
        self.assertEqual(
            spots, filtered_spots,
            "Filters weren't applied. All items weren't returned!")
        self.assertEqual(get_item_count(filtered_spots), 115,
                         "Invalid number of filtered items returned")
示例#4
0
def tech_list_view(request, campus):
    # spots = get_spots_by_filter([('has_items', 'true')])
    spots = get_filtered_spots(request, campus, "tech")
    spots = get_filtered_items(spots, request)
    count = get_item_count(spots)
    if count <= 0:
        spots = []

    context = {"spots": spots,
               "campus": campus,
               "count": count,
               "app_type": 'tech'}
    return render_to_response('scout/tech/list.html', context,
                              context_instance=RequestContext(request))
示例#5
0
文件: views.py 项目: uw-it-aca/scout
    def get_context_data(self, **kwargs):
        self.template_name = kwargs['template_name']
        # spots = get_spots_by_filter([('has_items', 'true')])
        self.request.GET = self.request.GET.copy()
        self.request.GET['item_is_active'] = 'true'
        spots = get_filtered_spots(self.request, kwargs['campus'], "tech")
        spots = get_filtered_items(spots, self.request)
        count = get_item_count(spots)
        if count <= 0:
            spots = []

        context = {
            "spots": spots,
            "campus": kwargs['campus'],
            "count": count,
            "app_type": 'tech',
            "campus_locations": CAMPUS_LOCATIONS
        }
        return context
示例#6
0
    def test_item_invalid_filter(self):
        """
        Test the result when invalid filters are applied to the results.
        """
        query_tuple = [
            ('limit', 0),
            ('extended_info:app_type', 'invalid')
        ]
        request = RequestFactory().get(
            '/?limit=0&extended_info:app_type=invalid'
        )

        spots = get_spots_by_filter(query_tuple)
        filtered_spots = get_filtered_items(spots, request)
        self.assertEqual(
            spots,
            filtered_spots,
            "Filters weren't applied. All items weren't returned!"
        )
        self.assertEqual(
            get_item_count(filtered_spots),
            0,
            "Invalid number of filtered items returned"
        )