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