@@ -6,16 +6,17 @@ class BaseBlogTestCase(TestCase):
6
6
7
7
def setUp (self ):
8
8
super ().setUp ()
9
- tags = [Tag .objects .create (name = 'Foo' ), Tag .objects .create (name = 'Bar' ), Tag .objects .create (name = 'Spam' )]
10
- self .authors = []
11
- for author_num in range (5 ):
12
- author = Author .objects .create (
13
- bio = 'Bio #{}' .format (author_num ), email = 'author{}@e.co' .format (author_num ),
14
- username = 'author-{}' .format (author_num ))
15
- author .set_password ('v3rys3cr31' )
16
- for article_num in range (10 ):
17
- article = Article .objects .create (
18
- title = 'Article #{}' .format (author_num * 10 + article_num ), content = 'foo bar' , author = author ,
19
- comments_on = (article_num % 2 == 0 ))
20
- article .tags .add (* tags )
21
- self .authors .append (author )
9
+
10
+ def _create_tags (self ):
11
+ return [Tag .objects .create (name = 'Foo' ), Tag .objects .create (name = 'Bar' ), Tag .objects .create (name = 'Spam' )]
12
+
13
+ def _create_author (self , username , email , bio , password ):
14
+ author = Author .objects .create (bio = bio , email = email , username = username )
15
+ author .set_password (password )
16
+ return author
17
+
18
+ def _create_article (self , title , content , author , comments_on , tags ):
19
+ article = Article .objects .create (title = title , content = content , author = author , comments_on = comments_on )
20
+ if tags :
21
+ article .tags .add (* tags )
22
+ return article
0 commit comments