1
- from django .test import Client , RequestFactory , TestCase
2
- from blog .models import Article , Category , Tag
3
- from django .contrib .auth import get_user_model
4
- from django .contrib .sites .models import Site
5
- import datetime
1
+ from django .test import TestCase
6
2
7
-
8
- # Create your tests here.
9
-
10
- class ArticleTest (TestCase ):
11
- def setUp (self ):
12
- self .client = Client ()
13
- self .factory = RequestFactory ()
14
-
15
- def test_validate_article (self ):
16
- from accounts .models import BlogUser
17
- site = Site .objects .get_current ().domain
18
- user = BlogUser ()
19
- user .email = "liangliangyy@gmail.com"
20
- user .username = "liangliangyy"
21
- user .password = "liangliangyy"
22
- user .save ()
23
- response = self .client .get (user .get_absolute_url ())
24
- self .assertEqual (response .status_code , 200 )
25
-
26
- category = Category ()
27
- category .name = "category"
28
- category .created_time = datetime .datetime .now ()
29
- category .last_mod_time = datetime .datetime .now ()
30
- category .save ()
31
-
32
- response = self .client .get (category .get_absolute_url ())
33
- self .assertEqual (response .status_code , 200 )
34
-
35
- article = Article ()
36
- article .title = "nicetitle"
37
- article .body = "nicecontent"
38
- article .author = user
39
- article .category = category
40
- article .type = 'a'
41
- article .status = 'p'
42
- article .save ()
43
- response = self .client .get (article .get_absolute_url ())
44
- self .assertEqual (response .status_code , 200 )
3
+ # Create your tests here.
0 commit comments