Beispiel #1
0
    def setUp(self):
        self.category = CategoryFactory()

        self.recipe = RecipeFactory()
        self.recipe.parent = self.category
        self.recipe.save()

        self.article = ArticleFactory()
        self.article.category = self.category
        self.article.save()

        self.create_recipe_url = api_reverse('blog:recipes:recipes-create')
        self.get_recipe_parent_list_url = api_reverse('blog:recipes:recipes-get-category-parent-list', args=(self.recipe.id,))
        self.delete_recipe_url = api_reverse('blog:recipes:recipes-delete', args=(self.recipe.id,))
        self.get_recipe_url = api_reverse('blog:recipes:recipes-read', args=(self.recipe.id,))
        self.update_recipe_url = api_reverse('blog:recipes:recipes-partial-update', args=(self.recipe.id,))

        self.valid_data = {
            'name': 'some name',
            'description': 'some description',
            'parent': self.category
        }

        self.empty_name_data = {
            'name': '',
            'description': 'some description',
            'parent': self.category
        }

        self.change_name_data = {
            'name': 'some other name'
        }
Beispiel #2
0
    def setUp(self):
        self.category = CategoryFactory()

        self.recipe = RecipeFactory()
        self.recipe.parent = self.category
        self.recipe.save()

        self.article = ArticleFactory()
        self.article.category = self.category
        self.article.save()

        self.create_category_url = api_reverse('blog:categories:category-list')
        self.get_article_list_url = api_reverse('blog:categories:category-get-article-list', args=(self.category.id,))
        self.get_category_parent_list_url = api_reverse('blog:categories:category-get-category-parent-list', args=(self.category.id,))
        self.get_recipe_list_url = api_reverse('blog:categories:category-get-recipe-list', args=(self.category.id,))
        self.delete_category_url = api_reverse('blog:categories:category-delete', args=(self.category.id,))
        self.get_category_url = api_reverse('blog:categories:category-read', args=(self.category.id,))
        self.update_category_url = api_reverse('blog:categories:category-partial-update', args=(self.category.id,))

        self.valid_data = {
            'name': 'some name',
            'parent': self.category
        }

        self.empty_name_data = {
            'name': '',
            'parent': self.category
        }

        self.change_name_data = {
            'name': 'some other name'
        }
class CategoryViewTestCase(TestCase):
    def setUp(self):
        self.category = PostCategoryFactory()
        self.category_post1 = PostFactory(
            title="Category Post1",
            show_on_index=True,
            status=Post.STATUS_CHOICES.published,
            category=self.category,
        )
        self.category_post2 = PostFactory(
            title="Category Post2",
            show_on_index=True,
            status=Post.STATUS_CHOICES.published,
            category=self.category,
        )
        self.no_category_post = PostFactory(
            title="No Category Post",
            show_on_index=False,
            status=Post.STATUS_CHOICES.published,
            category=None,
        )

    def test_good_view(self):
        url = self.category.get_absolute_url()

        response = self.client.get(url)
        assert response.status_code == 200
        self.assertTemplateUsed(response, "blog/category.html")
        self.assertIn("entry_list", response.context_data)

    def test_category_posts(self):
        url = self.category.get_absolute_url()
        response = self.client.get(url)
        assert response.status_code == 200
        self.assertContains(response, self.category_post1.title)
        self.assertContains(response, self.category_post2.title)
        self.assertNotContains(response, self.no_category_post.title)

    def test_headline(self):
        url = self.category.get_absolute_url()
        response = self.client.get(url)
        self.assertContains(response, "%s" % (self.category,))
 def setUp(self):
     self.category = PostCategoryFactory()
     self.category_post1 = PostFactory(
         title="Category Post1",
         show_on_index=True,
         status=Post.STATUS_CHOICES.published,
         category=self.category,
     )
     self.category_post2 = PostFactory(
         title="Category Post2",
         show_on_index=True,
         status=Post.STATUS_CHOICES.published,
         category=self.category,
     )
     self.no_category_post = PostFactory(
         title="No Category Post",
         show_on_index=False,
         status=Post.STATUS_CHOICES.published,
         category=None,
     )
 def test_auto_populate_title_from_name(self):
     category = CategoryFactory(title="", name="Test")
     assert category.title == category.name
def run():
    admin_user = User.objects.get(username="******")
    CategoryFactory.create_batch(10, creator=admin_user)
    print("Post categories created.")