def create_category(name='life', description=""): category, is_created = Category.objects.get_or_create( name=name, description=description ) return category
class TestModel(TestCase): def setUp(self): self.client = Client() self.author_000 = User.objects.create( username='smith', password='nopassword') def test_category(self): category = create_category() def test_post(self): category = create_category( ) post_000 = create_post( title="The first post", content="Hello World. We are the world.", author=self.author_000, category=category ) self.assertEqual(category.post_set.count(), 1)
|