Skip to content
Permalink
Browse files
setUpTestData
  • Loading branch information
dizballanze committed May 23, 2018
1 parent 45d89a2 commit 5594cac
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 14 deletions.
@@ -7,15 +7,18 @@ class BaseBlogTestCase(TestCase):
def setUp(self):
super().setUp()

def _create_tags(self):
@classmethod
def _create_tags(cls):
return [Tag.objects.create(name='Foo'), Tag.objects.create(name='Bar'), Tag.objects.create(name='Spam')]

def _create_author(self, username, email, bio, password):
@classmethod
def _create_author(cls, username, email, bio, password):
author = Author.objects.create(bio=bio, email=email, username=username)
author.set_password(password)
return author

def _create_article(self, title, content, author, comments_on, tags):
@classmethod
def _create_article(cls, title, content, author, comments_on, tags):
article = Article.objects.create(title=title, content=content, author=author, comments_on=comments_on)
if tags:
article.tags.add(*tags)
@@ -14,16 +14,16 @@ def test_url_resolving(self):

class ArticlesListPaginationTestCase(BaseBlogTestCase):

def setUp(self):
super().setUp()
self.tags = self._create_tags()
@classmethod
def setUpTestData(cls):
cls.tags = cls._create_tags()
for author_num in range(5):
author = self._create_author(
author = cls._create_author(
'author-{}'.format(author_num), 'author-{}@e.co'.format(author_num), 'Bio #{}'.format(author_num),
'v3rys3cr31')
for article_num in range(10):
self._create_article(
'Article #{}'.format(author_num*10+article_num), 'foo bar', author, True, self.tags)
cls._create_article(
'Article #{}'.format(author_num*10+article_num), 'foo bar', author, True, cls.tags)

def test_first_20_articles_are_on_the_page(self):
resp = self.client.get(reverse('articles_list'))
@@ -5,11 +5,11 @@

class ArticlesTagsTestCase(BaseBlogTestCase):

def setUp(self):
super().setUp()
tags = self._create_tags()
author = self._create_author('foobar', 'foobar@e.co', 'spam', 'v3rys3cr31')
self._create_article('Spam', 'foo bar', author, True, tags)
@classmethod
def setUpTestData(cls):
tags = cls._create_tags()
author = cls._create_author('foobar', 'foobar@e.co', 'spam', 'v3rys3cr31')
cls._create_article('Spam', 'foo bar', author, True, tags)

def test_foo_bar(self):
self.assertEqual(3, 2+1)

0 comments on commit 5594cac

Please sign in to comment.