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