Beispiel #1
0
class TestListContentType(ViewHelpersTestCase):
    def setUp(self):
        super(TestListContentType, self).setUp()
        create_and_place_more_publishables(self)
        list_all_publishables_in_category_by_hour(self, category=self.category)
        self.list_content_type = ListContentType()

    def test_only_category_and_year_returns_all_listings(self):
        c = self.list_content_type.get_context(self.request, '', '2008')
        tools.assert_equals(self.listings, list(c['listings']))

    def test_only_nested_category_and_year_returns_all_listings(self):
        Listing.objects.all().update(category=self.category_nested_second)
        c = self.list_content_type.get_context(
            self.request, 'nested-category/second-nested-category', '2008')
        tools.assert_equals(self.listings, list(c['listings']))

    def test_return_first_2_listings_if_paginate_by_2(self):
        self.category.app_data = {'ella': {'paginate_by': 2}}
        self.category.save()
        c = self.list_content_type.get_context(self.request, '', '2008')
        tools.assert_equals(self.listings[:2], list(c['listings']))
        tools.assert_true(c['is_paginated'])

    def test_return_second_2_listings_if_paginate_by_2_and_page_2(self):
        self.category.app_data = {'ella': {'paginate_by': 2}}
        self.category.save()
        self.request.GET['p'] = '2'
        c = self.list_content_type.get_context(self.request, '', '2008')
        tools.assert_equals(self.listings[2:4], list(c['listings']))
        tools.assert_true(c['is_paginated'])

    def test_returns_empty_list_if_no_listing_found(self):
        c = self.list_content_type.get_context(self.request, '', '2007')
        tools.assert_equals([], list(c['listings']))

    def test_raises404_for_incorrect_page(self):
        self.request.GET['p'] = '200'
        tools.assert_raises(Http404, self.list_content_type.get_context,
                            self.request, '', '2008')

    def test_raises404_for_incorrect_category(self):
        tools.assert_raises(Http404, self.list_content_type.get_context,
                            self.request, 'XXX', '2008')

    def test_raises404_for_incorrect_month(self):
        tools.assert_raises(Http404, self.list_content_type.get_context,
                            self.request, '', '2008', '13')

    def test_raises404_for_incorrect_day(self):
        tools.assert_raises(Http404, self.list_content_type.get_context,
                            self.request, '', '2008', '1', '42')

    def test_raises404_for_incorrect_date(self):
        tools.assert_raises(Http404, self.list_content_type.get_context,
                            self.request, '', '2008', '2', '30')
Beispiel #2
0
class TestListContentType(ViewHelpersTestCase):
    def setUp(self):
        super(TestListContentType, self).setUp()
        create_and_place_more_publishables(self)
        list_all_publishables_in_category_by_hour(self, category=self.category)
        self.list_content_type = ListContentType()

    def test_only_category_and_year_returns_all_listings(self):
        c = self.list_content_type.get_context(self.request, "", "2008")
        tools.assert_equals(self.listings, list(c["listings"]))

    def test_only_nested_category_and_year_returns_all_listings(self):
        Listing.objects.all().update(category=self.category_nested_second)
        c = self.list_content_type.get_context(self.request, "nested-category/second-nested-category", "2008")
        tools.assert_equals(self.listings, list(c["listings"]))

    def test_return_first_2_listings_if_paginate_by_2(self):
        self.category.app_data = {"ella": {"paginate_by": 2}}
        self.category.save()
        c = self.list_content_type.get_context(self.request, "", "2008")
        tools.assert_equals(self.listings[:2], list(c["listings"]))
        tools.assert_true(c["is_paginated"])

    def test_return_second_2_listings_if_paginate_by_2_and_page_2(self):
        self.category.app_data = {"ella": {"paginate_by": 2}}
        self.category.save()
        self.request.GET["p"] = "2"
        c = self.list_content_type.get_context(self.request, "", "2008")
        tools.assert_equals(self.listings[2:4], list(c["listings"]))
        tools.assert_true(c["is_paginated"])

    def test_returns_empty_list_if_no_listing_found(self):
        c = self.list_content_type.get_context(self.request, "", "2007")
        tools.assert_equals([], list(c["listings"]))

    def test_raises404_for_incorrect_page(self):
        self.request.GET["p"] = "200"
        tools.assert_raises(Http404, self.list_content_type.get_context, self.request, "", "2008")

    def test_raises404_for_incorrect_category(self):
        tools.assert_raises(Http404, self.list_content_type.get_context, self.request, "XXX", "2008")

    def test_raises404_for_incorrect_month(self):
        tools.assert_raises(Http404, self.list_content_type.get_context, self.request, "", "2008", "13")

    def test_raises404_for_incorrect_day(self):
        tools.assert_raises(Http404, self.list_content_type.get_context, self.request, "", "2008", "1", "42")

    def test_raises404_for_incorrect_date(self):
        tools.assert_raises(Http404, self.list_content_type.get_context, self.request, "", "2008", "2", "30")

    def test_raises404_for_incorrect_content_type(self):
        tools.assert_raises(
            Http404, self.list_content_type.get_context, self.request, "", "2008", "2", "3", "not-a-content-type"
        )
Beispiel #3
0
class TestListContentType(ViewHelpersTestCase):
    def setUp(self):
        super(TestListContentType, self).setUp()
        create_and_place_more_publishables(self)
        list_all_publishables_in_category_by_hour(self, category=self.category)
        self.list_content_type = ListContentType()

    def test_only_category_and_year_returns_all_listings(self):
        c = self.list_content_type.get_context(self.request, '', '2008')
        tools.assert_equals(self.listings, list(c['listings']))

    def test_only_nested_category_and_year_returns_all_listings(self):
        Listing.objects.all().update(category=self.category_nested_second)
        c = self.list_content_type.get_context(self.request, 'nested-category/second-nested-category', '2008')
        tools.assert_equals(self.listings, list(c['listings']))

    def test_return_first_2_listings_if_paginate_by_2(self):
        self.category.app_data = {'ella': {'paginate_by': 2}}
        self.category.save()
        c = self.list_content_type.get_context(self.request, '', '2008')
        tools.assert_equals(self.listings[:2], list(c['listings']))
        tools.assert_true(c['is_paginated'])

    def test_return_second_2_listings_if_paginate_by_2_and_page_2(self):
        self.category.app_data = {'ella': {'paginate_by': 2}}
        self.category.save()
        self.request.GET['p'] = '2'
        c = self.list_content_type.get_context(self.request, '', '2008')
        tools.assert_equals(self.listings[2:4], list(c['listings']))
        tools.assert_true(c['is_paginated'])

    def test_returns_empty_list_if_no_listing_found(self):
        c = self.list_content_type.get_context(self.request, '', '2007')
        tools.assert_equals([], list(c['listings']))

    def test_raises404_for_incorrect_page(self):
        self.request.GET['p'] = '200'
        tools.assert_raises(Http404, self.list_content_type.get_context, self.request, '', '2008')

    def test_raises404_for_incorrect_category(self):
        tools.assert_raises(Http404, self.list_content_type.get_context, self.request, 'XXX', '2008')

    def test_raises404_for_incorrect_month(self):
        tools.assert_raises(Http404, self.list_content_type.get_context, self.request, '', '2008', '13')

    def test_raises404_for_incorrect_day(self):
        tools.assert_raises(Http404, self.list_content_type.get_context, self.request, '', '2008', '1', '42')

    def test_raises404_for_incorrect_date(self):
        tools.assert_raises(Http404, self.list_content_type.get_context, self.request, '', '2008', '2', '30')

    def test_raises404_for_incorrect_content_type(self):
        tools.assert_raises(Http404, self.list_content_type.get_context, self.request, '', '2008', '2', '3', 'not-a-content-type')
Beispiel #4
0
    def test_redis_listing_handler_used_from_view_when_requested(self):
        ct_id = self.publishables[0].content_type_id
        t1, t2 = time.time()-90, time.time()-100
        self.redis.zadd('listing:d:2', '%d:1' % ct_id, repr(t1))
        self.redis.zadd('listing:d:2', '%d:3' % ct_id, repr(t2))
        dt1, dt2 = from_timestamp(t1), from_timestamp(t2)

        rf = RequestFactory()
        request = rf.get(self.category_nested.get_absolute_url(), {'using': 'redis'})
        lct = ListContentType()

        context = lct.get_context(request, self.category_nested.tree_path)
        tools.assert_equals(2, len(context['listings']))
        l1, l2 = context['listings']

        tools.assert_equals(l1.publishable, self.publishables[0])
        tools.assert_equals(l2.publishable, self.publishables[2])
        tools.assert_equals(l1.publish_from, dt1)
        tools.assert_equals(l2.publish_from, dt2)
Beispiel #5
0
class TestCategoryDetail(ViewHelpersTestCase):
    def setUp(self):
        super(TestCategoryDetail, self).setUp()
        self.category_detail = ListContentType()

    def test_returns_category_by_tree_path(self):
        c = self.category_detail.get_context(self.request, 'nested-category')
        tools.assert_equals(self.category_nested, c['category'])
        tools.assert_false(c['is_homepage'])
        
    def test_returns_home_page_with_no_args(self):
        c = self.category_detail.get_context(self.request)
        tools.assert_equals(self.category, c['category'])
        tools.assert_true(c['is_homepage'])
        
    def test_returns_nested_category_by_tree_path(self):
        c = self.category_detail.get_context(self.request, 'nested-category/second-nested-category')
        tools.assert_equals(self.category_nested_second, c['category'])
        tools.assert_false(c['is_homepage'])
Beispiel #6
0
class TestCategoryDetail(ViewHelpersTestCase):
    def setUp(self):
        super(TestCategoryDetail, self).setUp()
        self.category_detail = ListContentType()

    def test_returns_category_by_tree_path(self):
        c = self.category_detail.get_context(self.request, 'nested-category')
        self.assert_equals(self.category_nested, c['category'])
        self.assert_false(c['is_homepage'])

    def test_returns_home_page_with_no_args(self):
        c = self.category_detail.get_context(self.request)
        self.assert_equals(self.category, c['category'])
        self.assert_true(c['is_homepage'])

    def test_returns_nested_category_by_tree_path(self):
        c = self.category_detail.get_context(
            self.request, 'nested-category/second-nested-category')
        self.assert_equals(self.category_nested_second, c['category'])
        self.assert_false(c['is_homepage'])
Beispiel #7
0
    def test_redis_listing_handler_used_from_view_when_requested(self):
        ct_id = self.publishables[0].content_type_id
        t1, t2 = time.time() - 90, time.time() - 100
        redis.client.zadd('listing:d:2', '%d:1' % ct_id, repr(t1))
        redis.client.zadd('listing:d:2', '%d:3' % ct_id, repr(t2))
        dt1, dt2 = from_timestamp(t1), from_timestamp(t2)

        rf = RequestFactory()
        request = rf.get(self.category_nested.get_absolute_url(),
                         {'using': 'redis'})
        lct = ListContentType()

        context = lct.get_context(request, self.category_nested)
        tools.assert_equals(2, len(context['listings']))
        l1, l2 = context['listings']

        tools.assert_equals(l1.publishable, self.publishables[0])
        tools.assert_equals(l2.publishable, self.publishables[2])
        tools.assert_equals(l1.publish_from, dt1)
        tools.assert_equals(l2.publish_from, dt2)
Beispiel #8
0
class TestListContentType(ViewHelpersTestCase):
    def setUp(self):
        super(TestListContentType, self).setUp()
        create_and_place_more_publishables(self)
        list_all_placements_in_category_by_hour(self, category=self.category)
        self.list_content_type = ListContentType()

    def test_only_category_and_year_returns_all_listings(self):
        c = self.list_content_type.get_context(self.request, '', '2008')
        self.assert_equals(self.listings, c['listings'])
        
    def test_only_nested_category_and_year_returns_all_listings(self):
        Listing.objects.all().update(category=self.category_nested_second)
        c = self.list_content_type.get_context(self.request, 'nested-category/second-nested-category', '2008')
        self.assert_equals(self.listings, c['listings'])

    def test_return_first_2_listings_if_paginate_by_2(self):
        c = self.list_content_type.get_context(self.request, '', '2008', paginate_by=2)
        self.assert_equals(self.listings[:2], c['listings'])
        self.assert_true(c['is_paginated'])
        
    def test_return_second_2_listings_if_paginate_by_2_and_page_2(self):
        self.request.GET['p'] = '2'
        c = self.list_content_type.get_context(self.request, '', '2008', paginate_by=2)
        self.assert_equals(self.listings[2:4], c['listings'])
        self.assert_true(c['is_paginated'])

    def test_reflect_priorities(self):
        l = self.listings[-1]
        l.priority_value = 10
        l.priority_from = datetime.now() - timedelta(days=1)
        l.priority_to = datetime.now() + timedelta(days=1)
        l.save()

        c = self.list_content_type.get_context(self.request, '', '2008')
        expected = [l] + self.listings[:-1]
        self.assert_equals(expected, c['listings'])

    def test_returns_empty_list_if_no_listing_found(self):
        c = self.list_content_type.get_context(self.request, '', '2007')
        self.assert_equals([], c['listings'])

    def test_raises404_for_incorrect_page(self):
        self.request.GET['p'] = '200'
        self.assert_raises(Http404, self.list_content_type.get_context, self.request, '', '2008', paginate_by=2)
        
    def test_raises404_for_incorrect_category(self):
        self.assert_raises(Http404, self.list_content_type.get_context, self.request, 'XXX', '2008')

    def test_raises404_for_incorrect_month(self):
        self.assert_raises(Http404, self.list_content_type.get_context, self.request, '', '2008', '13')

    def test_raises404_for_incorrect_day(self):
        self.assert_raises(Http404, self.list_content_type.get_context, self.request, '', '2008', '1', '42')

    def test_raises404_for_incorrect_date(self):
        self.assert_raises(Http404, self.list_content_type.get_context, self.request, '', '2008', '2', '30')

    def test_raises404_for_incorrect_content_type(self):
        self.assert_raises(Http404, self.list_content_type.get_context, self.request, '', '2008', '2', '3', 'not-a-content-type')
Beispiel #9
0
 def setUp(self):
     super(TestCategoryDetail, self).setUp()
     self.category_detail = ListContentType()
Beispiel #10
0
 def setUp(self):
     super(TestListContentType, self).setUp()
     create_and_place_more_publishables(self)
     list_all_placements_in_category_by_hour(self, category=self.category)
     self.list_content_type = ListContentType()
Beispiel #11
0
class TestListContentType(ViewHelpersTestCase):
    def setUp(self):
        super(TestListContentType, self).setUp()
        create_and_place_more_publishables(self)
        list_all_placements_in_category_by_hour(self, category=self.category)
        self.list_content_type = ListContentType()

    def test_only_category_and_year_returns_all_listings(self):
        c = self.list_content_type.get_context(self.request, '', '2008')
        self.assert_equals(self.listings, c['listings'])

    def test_only_nested_category_and_year_returns_all_listings(self):
        Listing.objects.all().update(category=self.category_nested_second)
        c = self.list_content_type.get_context(
            self.request, 'nested-category/second-nested-category', '2008')
        self.assert_equals(self.listings, c['listings'])

    def test_return_first_2_listings_if_paginate_by_2(self):
        c = self.list_content_type.get_context(self.request,
                                               '',
                                               '2008',
                                               paginate_by=2)
        self.assert_equals(self.listings[:2], c['listings'])
        self.assert_true(c['is_paginated'])

    def test_return_second_2_listings_if_paginate_by_2_and_page_2(self):
        self.request.GET['p'] = '2'
        c = self.list_content_type.get_context(self.request,
                                               '',
                                               '2008',
                                               paginate_by=2)
        self.assert_equals(self.listings[2:4], c['listings'])
        self.assert_true(c['is_paginated'])

    def test_reflect_priorities(self):
        l = self.listings[-1]
        l.priority_value = 10
        l.priority_from = datetime.now() - timedelta(days=1)
        l.priority_to = datetime.now() + timedelta(days=1)
        l.save()

        c = self.list_content_type.get_context(self.request, '', '2008')
        expected = [l] + self.listings[:-1]
        self.assert_equals(expected, c['listings'])

    def test_returns_empty_list_if_no_listing_found(self):
        c = self.list_content_type.get_context(self.request, '', '2007')
        self.assert_equals([], c['listings'])

    def test_raises404_for_incorrect_page(self):
        self.request.GET['p'] = '200'
        self.assert_raises(Http404,
                           self.list_content_type.get_context,
                           self.request,
                           '',
                           '2008',
                           paginate_by=2)

    def test_raises404_for_incorrect_category(self):
        self.assert_raises(Http404, self.list_content_type.get_context,
                           self.request, 'XXX', '2008')

    def test_raises404_for_incorrect_month(self):
        self.assert_raises(Http404, self.list_content_type.get_context,
                           self.request, '', '2008', '13')

    def test_raises404_for_incorrect_day(self):
        self.assert_raises(Http404, self.list_content_type.get_context,
                           self.request, '', '2008', '1', '42')

    def test_raises404_for_incorrect_date(self):
        self.assert_raises(Http404, self.list_content_type.get_context,
                           self.request, '', '2008', '2', '30')

    def test_raises404_for_incorrect_content_type(self):
        self.assert_raises(Http404, self.list_content_type.get_context,
                           self.request, '', '2008', '2', '3',
                           'not-a-content-type')
Beispiel #12
0
 def setUp(self):
     super(TestCategoryDetail, self).setUp()
     self.category_detail = ListContentType()
Beispiel #13
0
 def setUp(self):
     super(TestListContentType, self).setUp()
     create_and_place_more_publishables(self)
     list_all_publishables_in_category_by_hour(self, category=self.category)
     self.list_content_type = ListContentType()