##// 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 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, created = Tag.objects.get_or_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 40 thread.delete()
41 41
42 42 self.assertFalse(Post.objects.filter(id=reply.id).exists(),
43 43 'Reply was not deleted with the thread.')
44 44 self.assertFalse(Post.objects.filter(id=opening_post.id).exists(),
45 45 'Opening post was not deleted with the thread.')
46 46
47 47 def test_post_to_thread(self):
48 48 """Test adding post to a thread"""
49 49
50 50 op = self._create_post()
51 51 post = Post.objects.create_post("", "", thread=op.get_thread())
52 52
53 53 self.assertIsNotNone(post, 'Reply to thread wasn\'t created')
54 54 self.assertEqual(op.get_thread().last_edit_time, post.pub_time,
55 55 'Post\'s create time doesn\'t match thread last edit'
56 56 ' time')
57 57
58 58 def test_delete_posts_by_ip(self):
59 59 """Test deleting posts with the given ip"""
60 60
61 61 post = self._create_post()
62 62 post_id = post.id
63 63
64 64 Post.objects.delete_posts_by_ip('0.0.0.0')
65 65
66 66 self.assertFalse(Post.objects.filter(id=post_id).exists())
67 67
68 68 def test_get_thread(self):
69 69 """Test getting all posts of a thread"""
70 70
71 71 opening_post = self._create_post()
72 72
73 73 for i in range(2):
74 74 Post.objects.create_post('title', 'text',
75 75 thread=opening_post.get_thread())
76 76
77 77 thread = opening_post.get_thread()
78 78
79 79 self.assertEqual(3, thread.get_replies().count())
80 80
81 81 def test_create_post_with_tag(self):
82 82 """Test adding tag to post"""
83 83
84 84 tag = Tag.objects.create(name='test_tag')
85 85 post = Post.objects.create_post(title='title', text='text', tags=[tag])
86 86
87 87 thread = post.get_thread()
88 88 self.assertIsNotNone(post, 'Post not created')
89 89 self.assertTrue(tag in thread.tags.all(), 'Tag not added to thread')
90 90
91 91 def test_thread_max_count(self):
92 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 95 self._create_post()
96 96
97 self.assertEqual(settings.MAX_THREAD_COUNT,
97 self.assertEqual(settings.get_int('Messages', 'MaxThreadCount'),
98 98 len(Thread.objects.filter(archived=False)))
99 99
100 100 def test_pages(self):
101 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 104 self._create_post()
105 105
106 106 all_threads = Thread.objects.filter(archived=False)
107 107
108 108 paginator = Paginator(Thread.objects.filter(archived=False),
109 settings.THREADS_PER_PAGE)
109 settings.get_int('View', 'ThreadsPerPage'))
110 110 posts_in_second_page = paginator.page(2).object_list
111 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 114 first_post.id)
115 115
116 116 def test_thread_replies(self):
117 117 """
118 118 Tests that the replies can be queried from a thread in all possible
119 119 ways.
120 120 """
121 121
122 122 tag = Tag.objects.create(name='test_tag')
123 123 opening_post = Post.objects.create_post(title='title', text='text',
124 124 tags=[tag])
125 125 thread = opening_post.get_thread()
126 126
127 127 reply1 = Post.objects.create_post(title='title', text='text', thread=thread)
128 128 reply2 = Post.objects.create_post(title='title', text='text', thread=thread)
129 129
130 130 replies = thread.get_replies()
131 131 self.assertTrue(len(replies) > 0, 'No replies found for thread.')
132 132
133 133 replies = thread.get_replies(view_fields_only=True)
134 134 self.assertTrue(len(replies) > 0,
135 135 'No replies found for thread with view fields only.')
General Comments 0
You need to be logged in to leave comments. Login now