##// END OF EJS Templates
Removed multi replies from tests
neko259 -
r1711:d48d9cb4 default
parent child Browse files
Show More
@@ -1,191 +1,176 b''
1 1 from django.core.paginator import Paginator
2 2 from django.test import TestCase
3 3
4 4 from boards import settings
5 5 from boards.models import Tag, Post, Thread, KeyPair
6 6 from boards.models.thread import STATUS_ARCHIVE
7 7
8 8
9 9 class PostTests(TestCase):
10 10
11 11 def _create_post(self):
12 12 tag, created = Tag.objects.get_or_create(name='test_tag')
13 13 return Post.objects.create_post(title='title', text='text',
14 14 tags=[tag])
15 15
16 16 def test_post_add(self):
17 17 """Test adding post"""
18 18
19 19 post = self._create_post()
20 20
21 21 self.assertIsNotNone(post, 'No post was created.')
22 22 self.assertEqual('test_tag', post.get_thread().tags.all()[0].name,
23 23 'No tags were added to the post.')
24 24
25 25 def test_delete_post(self):
26 26 """Test post deletion"""
27 27
28 28 post = self._create_post()
29 29 post_id = post.id
30 30
31 31 post.delete()
32 32
33 33 self.assertFalse(Post.objects.filter(id=post_id).exists())
34 34
35 35 def test_delete_thread(self):
36 36 """Test thread deletion"""
37 37
38 38 opening_post = self._create_post()
39 39 thread = opening_post.get_thread()
40 40 reply = Post.objects.create_post("", "", thread=thread)
41 41
42 42 thread.delete()
43 43
44 44 self.assertFalse(Post.objects.filter(id=reply.id).exists(),
45 45 'Reply was not deleted with the thread.')
46 46 self.assertFalse(Post.objects.filter(id=opening_post.id).exists(),
47 47 'Opening post was not deleted with the thread.')
48 48
49 49 def test_post_to_thread(self):
50 50 """Test adding post to a thread"""
51 51
52 52 op = self._create_post()
53 53 post = Post.objects.create_post("", "", thread=op.get_thread())
54 54
55 55 self.assertIsNotNone(post, 'Reply to thread wasn\'t created')
56 56 self.assertEqual(op.get_thread().last_edit_time, post.pub_time,
57 57 'Post\'s create time doesn\'t match thread last edit'
58 58 ' time')
59 59
60 60 def test_delete_posts_by_ip(self):
61 61 """Test deleting posts with the given ip"""
62 62
63 63 post = self._create_post()
64 64 post_id = post.id
65 65
66 66 Post.objects.delete_posts_by_ip('0.0.0.0')
67 67
68 68 self.assertFalse(Post.objects.filter(id=post_id).exists())
69 69
70 70 def test_get_thread(self):
71 71 """Test getting all posts of a thread"""
72 72
73 73 opening_post = self._create_post()
74 74
75 75 for i in range(2):
76 76 Post.objects.create_post('title', 'text',
77 77 thread=opening_post.get_thread())
78 78
79 79 thread = opening_post.get_thread()
80 80
81 81 self.assertEqual(3, thread.get_replies().count())
82 82
83 83 def test_create_post_with_tag(self):
84 84 """Test adding tag to post"""
85 85
86 86 tag = Tag.objects.create(name='test_tag')
87 87 post = Post.objects.create_post(title='title', text='text', tags=[tag])
88 88
89 89 thread = post.get_thread()
90 90 self.assertIsNotNone(post, 'Post not created')
91 91 self.assertTrue(tag in thread.tags.all(), 'Tag not added to thread')
92 92
93 93 def test_pages(self):
94 94 """Test that the thread list is properly split into pages"""
95 95
96 96 for i in range(settings.get_int('View', 'ThreadsPerPage') * 2):
97 97 self._create_post()
98 98
99 99 all_threads = Thread.objects.exclude(status=STATUS_ARCHIVE)
100 100
101 101 paginator = Paginator(Thread.objects.exclude(status=STATUS_ARCHIVE),
102 102 settings.get_int('View', 'ThreadsPerPage'))
103 103 posts_in_second_page = paginator.page(2).object_list
104 104 first_post = posts_in_second_page[0]
105 105
106 106 self.assertEqual(all_threads[settings.get_int('View', 'ThreadsPerPage')].id,
107 107 first_post.id)
108 108
109 109 def test_reflinks(self):
110 110 """
111 111 Tests that reflinks are parsed within post and connecting replies
112 112 to the replied posts.
113 113
114 114 Local reflink example: [post]123[/post]
115 115 Global reflink example: [post]key_type::key::123[/post]
116 116 """
117 117
118 118 key = KeyPair.objects.generate_key(primary=True)
119 119
120 120 tag = Tag.objects.create(name='test_tag')
121 121
122 122 post = Post.objects.create_post(title='', text='', tags=[tag])
123 123 post_local_reflink = Post.objects.create_post(title='',
124 124 text='[post]%d[/post]' % post.id, thread=post.get_thread())
125 125
126 126 self.assertTrue(post_local_reflink in post.referenced_posts.all(),
127 127 'Local reflink not connecting posts.')
128 128
129 129
130 130 def test_thread_replies(self):
131 131 """
132 132 Tests that the replies can be queried from a thread in all possible
133 133 ways.
134 134 """
135 135
136 136 tag = Tag.objects.create(name='test_tag')
137 137 opening_post = Post.objects.create_post(title='title', text='text',
138 138 tags=[tag])
139 139 thread = opening_post.get_thread()
140 140
141 141 Post.objects.create_post(title='title', text='text', thread=thread)
142 142 Post.objects.create_post(title='title', text='text', thread=thread)
143 143
144 144 replies = thread.get_replies()
145 145 self.assertTrue(len(replies) > 0, 'No replies found for thread.')
146 146
147 147 replies = thread.get_replies(view_fields_only=True)
148 148 self.assertTrue(len(replies) > 0,
149 149 'No replies found for thread with view fields only.')
150 150
151 151 def test_bumplimit(self):
152 152 """
153 153 Tests that the thread bumpable status is changed and post uids and
154 154 last update times are updated across all post threads.
155 155 """
156 156
157 157 op1 = Post.objects.create_post(title='title', text='text')
158 op2 = Post.objects.create_post(title='title', text='text')
159 158
160 159 thread1 = op1.get_thread()
161 160 thread1.max_posts = 5
162 161 thread1.save()
163 162
164 163 uid_1 = op1.uid
165 uid_2 = op2.uid
166 164
167 165 # Create multi reply
168 166 Post.objects.create_post(
169 title='title', text='text', thread=thread1,
170 opening_posts=[op1, op2])
171 thread_update_time_2 = op2.get_thread().last_edit_time
167 title='title', text='text', thread=thread1)
172 168 for i in range(6):
173 169 Post.objects.create_post(title='title', text='text',
174 170 thread=thread1)
175 171
176 172 self.assertFalse(op1.get_thread().can_bump(),
177 173 'Thread is bumpable when it should not be.')
178 self.assertTrue(op2.get_thread().can_bump(),
179 'Thread is not bumpable when it should be.')
180 174 self.assertNotEqual(
181 175 uid_1, Post.objects.get(id=op1.id).uid,
182 176 'UID of the first OP should be changed but it is not.')
183 self.assertEqual(
184 uid_2, Post.objects.get(id=op2.id).uid,
185 'UID of the first OP should not be changed but it is.')
186
187 self.assertNotEqual(
188 thread_update_time_2,
189 Thread.objects.get(id=op2.get_thread().id).last_edit_time,
190 'Thread last update time should change when the other thread '
191 'changes status.')
General Comments 0
You need to be logged in to leave comments. Login now