Beispiel #1
0
    def test_list_item_in_index_are_presented_using_list_group(self):
        #Create categories and pages
        categories = test_utils.create_categories()
        test_utils.create_pages(categories)

        #Access index page
        response = self.client.get(reverse('index'))

        #Check for usage of list-group
        self.assertIn('<ul class="list-group">', response.content)
        self.assertIn('<li class="list-group-item">', response.content)
    def test_index_displays_five_most_viewed_pages(self):
        #Create categories
        categories = test_utils.create_categories()

        #Create pages for categories
        test_utils.create_pages(categories)

        # Access index
        response = self.client.get(reverse('index'))

        # Check if the 5 pages with most views are displayed
        for i in xrange(20, 15, -1):
            self.assertIn("Page " + str(i), response.content)
    def test_category_page_displays_pages(self):
        #Create categories in database
        categories = test_utils.create_categories()

        # Create pages for categories
        test_utils.create_pages(categories)

        # For each category, access its page and check for the pages associated with it
        for category in categories:
            # Access category page
            response = self.client.get(
                reverse('show_category', args=[category.slug]))

            # Retrieve pages for that category
            pages = Page.objects.filter(category=category)

            # Check pages are displayed and they have a link
            for page in pages:
                self.assertIn(page.title, response.content)
                self.assertIn(page.url, response.content)
    def test_index_context(self):
        # Access index with empty database
        response = self.client.get(reverse('index'))

        # Context dictionary is then empty
        self.assertItemsEqual(response.context['categories'], [])
        self.assertItemsEqual(response.context['pages'], [])

        categories = test_utils.create_categories()
        test_utils.create_pages(categories)

        #Access index with database filled
        response = self.client.get(reverse('index'))

        #Retrieve categories and pages from database
        categories = Category.objects.order_by('-likes')[:5]
        pages = Page.objects.order_by('-views')[:5]

        # Check context dictionary filled
        self.assertItemsEqual(response.context['categories'], categories)
        self.assertItemsEqual(response.context['pages'], pages)
    def test_category_context(self):
        #Create categories and pages for categories
        categories = test_utils.create_categories()
        pages = test_utils.create_pages(categories)

        # For each category check the context dictionary passed via render() function
        for category in categories:
            response = self.client.get(
                reverse('show_category', args=[category.slug]))
            pages = Page.objects.filter(category=category)
            self.assertItemsEqual(response.context['pages'], pages)
            self.assertEquals(response.context['category'], category)