Skip to content

Instantly share code, notes, and snippets.

@olegkovalov
Last active September 8, 2019 20:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save olegkovalov/aa0c029c00ae29f39269517b36eab55d to your computer and use it in GitHub Desktop.
Save olegkovalov/aa0c029c00ae29f39269517b36eab55d to your computer and use it in GitHub Desktop.
test_models
from django.test import TestCase
from django_blog.apps.blog.models import Post, Tag
class PostTestCase(TestCase):
def test_post(self):
self.assertEquals(
Post.objects.count(),
0
)
Post.objects.create(
title='active', text='text', is_active=True
)
Post.objects.create(
title='inactive', text='text', is_active=False
)
self.assertEquals(
Post.objects.count(),
2
)
active_posts = Post.objects.active()
self.assertEquals(
active_posts.count(),
1
)
inactive_posts = Post.objects.inactive()
self.assertEquals(
inactive_posts.count(),
1
)
class TagTestCase(TestCase):
def test_tag(self):
self.assertEquals(
Tag.objects.count(),
0
)
Tag.objects.create(name='name')
self.assertEquals(
Tag.objects.count(),
1
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment