##// END OF EJS Templates
Removed call to en internal method in test.
neko259 -
r19:e1992943 default
parent child Browse files
Show More
@@ -1,99 +1,99 b''
1 from django.utils.unittest import TestCase
1 from django.utils.unittest import TestCase
2 from django.test.client import Client
2 from django.test.client import Client
3
3
4 import boards
4 import boards
5
5
6 from boards.models import Post, Admin
6 from boards.models import Post, Admin
7
7
8
8
9 class BoardTests(TestCase):
9 class BoardTests(TestCase):
10
10
11 def _create_post(self):
11 def _create_post(self):
12 return Post.objects.create_post(title = 'title',
12 return Post.objects.create_post(title = 'title',
13 text = 'text')
13 text = 'text')
14
14
15 def test_post_add(self):
15 def test_post_add(self):
16 post = self._create_post()
16 post = self._create_post()
17
17
18 self.assertIsNotNone(post)
18 self.assertIsNotNone(post)
19 self.assertEqual(boards.models.NO_PARENT, post.parent)
19 self.assertEqual(boards.models.NO_PARENT, post.parent)
20
20
21 def test_delete_post(self):
21 def test_delete_post(self):
22 post = self._create_post()
22 post = self._create_post()
23 post_id = post.id
23 post_id = post.id
24
24
25 Post.objects.delete_post(post)
25 Post.objects.delete_post(post)
26
26
27 self.assertFalse(Post.objects.exists(post_id))
27 self.assertFalse(Post.objects.exists(post_id))
28
28
29 def test_delete_posts_by_ip(self):
29 def test_delete_posts_by_ip(self):
30 post = self._create_post()
30 post = self._create_post()
31 post_id = post.id
31 post_id = post.id
32
32
33 Post.objects.delete_posts_by_ip('0.0.0.0')
33 Post.objects.delete_posts_by_ip('0.0.0.0')
34
34
35 self.assertFalse(Post.objects.exists(post_id))
35 self.assertFalse(Post.objects.exists(post_id))
36
36
37 # Authentication tests
37 # Authentication tests
38
38
39 def _create_test_user(self):
39 def _create_test_user(self):
40 admin = Admin(name = 'test_username12313584353165',
40 admin = Admin(name = 'test_username12313584353165',
41 password = 'test_userpassword135135512')
41 password = 'test_userpassword135135512')
42
42
43 admin.save()
43 admin.save()
44 return admin
44 return admin
45
45
46 def test_admin_login(self):
46 def test_admin_login(self):
47 client = Client()
47 client = Client()
48
48
49 self.assertFalse('admin' in client.session)
49 self.assertFalse('admin' in client.session)
50
50
51 admin = self._create_test_user()
51 admin = self._create_test_user()
52
52
53 response = client.post('/boards/login',
53 response = client.post('/boards/login',
54 {'name': admin.name, 'password': admin.password})
54 {'name': admin.name, 'password': admin.password})
55
55
56 # it means that login passed and user are redirected to another page
56 # it means that login passed and user are redirected to another page
57 self.assertEqual(302, response.status_code)
57 self.assertEqual(302, response.status_code)
58
58
59 self.assertTrue('admin' in client.session)
59 self.assertTrue('admin' in client.session)
60 self.assertTrue(client.session['admin'])
60 self.assertTrue(client.session['admin'])
61
61
62 admin.delete()
62 admin.delete()
63
63
64 wrong_name = 'sd2f1s3d21fs3d21f'
64 wrong_name = 'sd2f1s3d21fs3d21f'
65 wrong_password = 'sd2f1s3d21fs3d21fsdfsd'
65 wrong_password = 'sd2f1s3d21fs3d21fsdfsd'
66
66
67 client.post('/boards/login', {'name': wrong_name, 'password': wrong_password})
67 client.post('/boards/login', {'name': wrong_name, 'password': wrong_password})
68 self.assertFalse(client.session['admin'])
68 self.assertFalse(client.session['admin'])
69
69
70 def test_admin_logout(self):
70 def test_admin_logout(self):
71 client = Client()
71 client = Client()
72
72
73
73
74 self.assertFalse('admin' in client.session)
74 self.assertFalse('admin' in client.session)
75
75
76 admin = self._create_test_user()
76 admin = self._create_test_user()
77
77
78 client.post('/boards/login',
78 client.post('/boards/login',
79 {'name': admin.name, 'password': admin.password})
79 {'name': admin.name, 'password': admin.password})
80
80
81 self.assertTrue(client.session['admin'])
81 self.assertTrue(client.session['admin'])
82
82
83 client.get('/boards/logout')
83 client.get('/boards/logout')
84
84
85 self.assertFalse(client.session['admin'])
85 self.assertFalse(client.session['admin'])
86
86
87 admin.delete()
87 admin.delete()
88
88
89 def test_get_thread(self):
89 def test_get_thread(self):
90 opening_post = self._create_post()
90 opening_post = self._create_post()
91 op_id = opening_post.id
91 op_id = opening_post.id
92
92
93 for i in range(0, 2):
93 for i in range(0, 2):
94 Post.objects.create_post('title', 'text',
94 Post.objects.create_post('title', 'text',
95 parent_id = op_id)
95 parent_id = op_id)
96
96
97 thread = Post.objects.get_thread(op_id)
97 thread = Post.objects.get_thread(op_id)
98
98
99 self.assertEqual(3, thread.__len__())
99 self.assertEqual(3, len(thread))
General Comments 0
You need to be logged in to leave comments. Login now