Пример #1
0
    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 range(20, 15, -1):
            self.assertIn("Page " + str(i), response.content.decode('ascii'))
Пример #2
0
    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.decode('ascii'))
                self.assertIn(page.url, response.content.decode('ascii'))
Пример #3
0
    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.assertCountEqual(response.context['pages'], pages)
            self.assertEquals(response.context['category'], category)
Пример #4
0
    def test_index_context(self):
        # Access index with empty database
        response = self.client.get(reverse('index'))

        # Context dictionary is then empty
        self.assertCountEqual(response.context['categories'], [])
        self.assertCountEqual(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.assertCountEqual(response.context['categories'], categories)
        self.assertCountEqual(response.context['pages'], pages)