##// END OF EJS Templates
Fixed tests to use the new settings
neko259 -
r1154:d3095827 default
parent child Browse files
Show More
@@ -1,135 +1,135 b''
1 from django.core.paginator import Paginator
1 from django.core.paginator import Paginator
2 from django.test import TestCase
2 from django.test import TestCase
3 from boards import settings
3 from boards import settings
4 from boards.models import Tag, Post, Thread
4 from boards.models import Tag, Post, Thread
5
5
6
6
7 class PostTests(TestCase):
7 class PostTests(TestCase):
8
8
9 def _create_post(self):
9 def _create_post(self):
10 tag, created = Tag.objects.get_or_create(name='test_tag')
10 tag, created = Tag.objects.get_or_create(name='test_tag')
11 return Post.objects.create_post(title='title', text='text',
11 return Post.objects.create_post(title='title', text='text',
12 tags=[tag])
12 tags=[tag])
13
13
14 def test_post_add(self):
14 def test_post_add(self):
15 """Test adding post"""
15 """Test adding post"""
16
16
17 post = self._create_post()
17 post = self._create_post()
18
18
19 self.assertIsNotNone(post, 'No post was created.')
19 self.assertIsNotNone(post, 'No post was created.')
20 self.assertEqual('test_tag', post.get_thread().tags.all()[0].name,
20 self.assertEqual('test_tag', post.get_thread().tags.all()[0].name,
21 'No tags were added to the post.')
21 'No tags were added to the post.')
22
22
23 def test_delete_post(self):
23 def test_delete_post(self):
24 """Test post deletion"""
24 """Test post deletion"""
25
25
26 post = self._create_post()
26 post = self._create_post()
27 post_id = post.id
27 post_id = post.id
28
28
29 post.delete()
29 post.delete()
30
30
31 self.assertFalse(Post.objects.filter(id=post_id).exists())
31 self.assertFalse(Post.objects.filter(id=post_id).exists())
32
32
33 def test_delete_thread(self):
33 def test_delete_thread(self):
34 """Test thread deletion"""
34 """Test thread deletion"""
35
35
36 opening_post = self._create_post()
36 opening_post = self._create_post()
37 thread = opening_post.get_thread()
37 thread = opening_post.get_thread()
38 reply = Post.objects.create_post("", "", thread=thread)
38 reply = Post.objects.create_post("", "", thread=thread)
39
39
40 thread.delete()
40 thread.delete()
41
41
42 self.assertFalse(Post.objects.filter(id=reply.id).exists(),
42 self.assertFalse(Post.objects.filter(id=reply.id).exists(),
43 'Reply was not deleted with the thread.')
43 'Reply was not deleted with the thread.')
44 self.assertFalse(Post.objects.filter(id=opening_post.id).exists(),
44 self.assertFalse(Post.objects.filter(id=opening_post.id).exists(),
45 'Opening post was not deleted with the thread.')
45 'Opening post was not deleted with the thread.')
46
46
47 def test_post_to_thread(self):
47 def test_post_to_thread(self):
48 """Test adding post to a thread"""
48 """Test adding post to a thread"""
49
49
50 op = self._create_post()
50 op = self._create_post()
51 post = Post.objects.create_post("", "", thread=op.get_thread())
51 post = Post.objects.create_post("", "", thread=op.get_thread())
52
52
53 self.assertIsNotNone(post, 'Reply to thread wasn\'t created')
53 self.assertIsNotNone(post, 'Reply to thread wasn\'t created')
54 self.assertEqual(op.get_thread().last_edit_time, post.pub_time,
54 self.assertEqual(op.get_thread().last_edit_time, post.pub_time,
55 'Post\'s create time doesn\'t match thread last edit'
55 'Post\'s create time doesn\'t match thread last edit'
56 ' time')
56 ' time')
57
57
58 def test_delete_posts_by_ip(self):
58 def test_delete_posts_by_ip(self):
59 """Test deleting posts with the given ip"""
59 """Test deleting posts with the given ip"""
60
60
61 post = self._create_post()
61 post = self._create_post()
62 post_id = post.id
62 post_id = post.id
63
63
64 Post.objects.delete_posts_by_ip('0.0.0.0')
64 Post.objects.delete_posts_by_ip('0.0.0.0')
65
65
66 self.assertFalse(Post.objects.filter(id=post_id).exists())
66 self.assertFalse(Post.objects.filter(id=post_id).exists())
67
67
68 def test_get_thread(self):
68 def test_get_thread(self):
69 """Test getting all posts of a thread"""
69 """Test getting all posts of a thread"""
70
70
71 opening_post = self._create_post()
71 opening_post = self._create_post()
72
72
73 for i in range(2):
73 for i in range(2):
74 Post.objects.create_post('title', 'text',
74 Post.objects.create_post('title', 'text',
75 thread=opening_post.get_thread())
75 thread=opening_post.get_thread())
76
76
77 thread = opening_post.get_thread()
77 thread = opening_post.get_thread()
78
78
79 self.assertEqual(3, thread.get_replies().count())
79 self.assertEqual(3, thread.get_replies().count())
80
80
81 def test_create_post_with_tag(self):
81 def test_create_post_with_tag(self):
82 """Test adding tag to post"""
82 """Test adding tag to post"""
83
83
84 tag = Tag.objects.create(name='test_tag')
84 tag = Tag.objects.create(name='test_tag')
85 post = Post.objects.create_post(title='title', text='text', tags=[tag])
85 post = Post.objects.create_post(title='title', text='text', tags=[tag])
86
86
87 thread = post.get_thread()
87 thread = post.get_thread()
88 self.assertIsNotNone(post, 'Post not created')
88 self.assertIsNotNone(post, 'Post not created')
89 self.assertTrue(tag in thread.tags.all(), 'Tag not added to thread')
89 self.assertTrue(tag in thread.tags.all(), 'Tag not added to thread')
90
90
91 def test_thread_max_count(self):
91 def test_thread_max_count(self):
92 """Test deletion of old posts when the max thread count is reached"""
92 """Test deletion of old posts when the max thread count is reached"""
93
93
94 for i in range(settings.MAX_THREAD_COUNT + 1):
94 for i in range(settings.get_int('Messages', 'MaxThreadCount') + 1):
95 self._create_post()
95 self._create_post()
96
96
97 self.assertEqual(settings.MAX_THREAD_COUNT,
97 self.assertEqual(settings.get_int('Messages', 'MaxThreadCount'),
98 len(Thread.objects.filter(archived=False)))
98 len(Thread.objects.filter(archived=False)))
99
99
100 def test_pages(self):
100 def test_pages(self):
101 """Test that the thread list is properly split into pages"""
101 """Test that the thread list is properly split into pages"""
102
102
103 for i in range(settings.MAX_THREAD_COUNT):
103 for i in range(settings.get_int('Messages', 'MaxThreadCount')):
104 self._create_post()
104 self._create_post()
105
105
106 all_threads = Thread.objects.filter(archived=False)
106 all_threads = Thread.objects.filter(archived=False)
107
107
108 paginator = Paginator(Thread.objects.filter(archived=False),
108 paginator = Paginator(Thread.objects.filter(archived=False),
109 settings.THREADS_PER_PAGE)
109 settings.get_int('View', 'ThreadsPerPage'))
110 posts_in_second_page = paginator.page(2).object_list
110 posts_in_second_page = paginator.page(2).object_list
111 first_post = posts_in_second_page[0]
111 first_post = posts_in_second_page[0]
112
112
113 self.assertEqual(all_threads[settings.THREADS_PER_PAGE].id,
113 self.assertEqual(all_threads[settings.get_int('View', 'ThreadsPerPage')].id,
114 first_post.id)
114 first_post.id)
115
115
116 def test_thread_replies(self):
116 def test_thread_replies(self):
117 """
117 """
118 Tests that the replies can be queried from a thread in all possible
118 Tests that the replies can be queried from a thread in all possible
119 ways.
119 ways.
120 """
120 """
121
121
122 tag = Tag.objects.create(name='test_tag')
122 tag = Tag.objects.create(name='test_tag')
123 opening_post = Post.objects.create_post(title='title', text='text',
123 opening_post = Post.objects.create_post(title='title', text='text',
124 tags=[tag])
124 tags=[tag])
125 thread = opening_post.get_thread()
125 thread = opening_post.get_thread()
126
126
127 reply1 = Post.objects.create_post(title='title', text='text', thread=thread)
127 reply1 = Post.objects.create_post(title='title', text='text', thread=thread)
128 reply2 = Post.objects.create_post(title='title', text='text', thread=thread)
128 reply2 = Post.objects.create_post(title='title', text='text', thread=thread)
129
129
130 replies = thread.get_replies()
130 replies = thread.get_replies()
131 self.assertTrue(len(replies) > 0, 'No replies found for thread.')
131 self.assertTrue(len(replies) > 0, 'No replies found for thread.')
132
132
133 replies = thread.get_replies(view_fields_only=True)
133 replies = thread.get_replies(view_fields_only=True)
134 self.assertTrue(len(replies) > 0,
134 self.assertTrue(len(replies) > 0,
135 'No replies found for thread with view fields only.')
135 'No replies found for thread with view fields only.')
General Comments 0
You need to be logged in to leave comments. Login now