Show More
@@ -178,8 +178,6 b' class PagesTest(TestCase):' | |||
|
178 | 178 | |
|
179 | 179 | class FormTest(TestCase): |
|
180 | 180 | def test_post_validation(self): |
|
181 | """Test the validation of the post form""" | |
|
182 | ||
|
183 | 181 | # Disable captcha for the test |
|
184 | 182 | captcha_enabled = settings.ENABLE_CAPTCHA |
|
185 | 183 | settings.ENABLE_CAPTCHA = False |
@@ -222,3 +220,14 b' class FormTest(TestCase):' | |||
|
222 | 220 | |
|
223 | 221 | # Restore captcha setting |
|
224 | 222 | settings.ENABLE_CAPTCHA = captcha_enabled |
|
223 | ||
|
224 | ||
|
225 | class ViewTest(TestCase): | |
|
226 | def test_index(self): | |
|
227 | client = Client() | |
|
228 | ||
|
229 | response = client.get('/') | |
|
230 | self.assertEqual(HTTP_CODE_OK, response.status_code, 'Index page not ' | |
|
231 | 'opened') | |
|
232 | self.assertEqual('boards/posting_general.html', response.templates[0] | |
|
233 | .name, 'Index page should open posting_general template') No newline at end of file |
@@ -55,16 +55,7 b' def index(request, page=0):' | |||
|
55 | 55 | |
|
56 | 56 | threads = [] |
|
57 | 57 | for thread_to_show in Post.objects.get_threads(page=int(page)): |
|
58 | last_replies = thread_to_show.get_last_replies() | |
|
59 | skipped_replies_count = thread_to_show.get_replies().count() \ | |
|
60 | - len(last_replies) - 1 | |
|
61 | threads.append({ | |
|
62 | 'thread': thread_to_show, | |
|
63 | 'op': thread_to_show.get_replies()[0], | |
|
64 | 'bumpable': thread_to_show.can_bump(), | |
|
65 | 'last_replies': last_replies, | |
|
66 | 'skipped_replies': skipped_replies_count, | |
|
67 | }) | |
|
58 | threads.append(_get_template_thread(thread_to_show)) | |
|
68 | 59 | |
|
69 | 60 | # TODO Make this generic for tag and threads list pages |
|
70 | 61 | context['threads'] = None if len(threads) == 0 else threads |
@@ -142,16 +133,7 b' def tag(request, tag_name, page=0):' | |||
|
142 | 133 | tag = get_object_or_404(Tag, name=tag_name) |
|
143 | 134 | threads = [] |
|
144 | 135 | for thread_to_show in Post.objects.get_threads(page=int(page), tag=tag): |
|
145 | last_replies = thread_to_show.get_last_replies() | |
|
146 | skipped_replies_count = thread_to_show.get_replies().count() \ | |
|
147 | - len(last_replies) - 1 | |
|
148 | threads.append({ | |
|
149 | 'thread': thread_to_show, | |
|
150 | 'op': thread_to_show.get_replies()[0], | |
|
151 | 'bumpable': thread_to_show.can_bump(), | |
|
152 | 'last_replies': last_replies, | |
|
153 | 'skipped_replies': skipped_replies_count, | |
|
154 | }) | |
|
136 | threads.append(_get_template_thread(thread_to_show)) | |
|
155 | 137 | |
|
156 | 138 | if request.method == 'POST': |
|
157 | 139 | form = ThreadForm(request.POST, request.FILES, |
@@ -572,3 +554,18 b' def _datetime_to_epoch(datetime):' | |||
|
572 | 554 | return int(time.mktime(timezone.localtime( |
|
573 | 555 | datetime,timezone.get_current_timezone()).timetuple()) |
|
574 | 556 | * 1000000 + datetime.microsecond) |
|
557 | ||
|
558 | ||
|
559 | def _get_template_thread(thread_to_show): | |
|
560 | """Get template values for thread""" | |
|
561 | ||
|
562 | last_replies = thread_to_show.get_last_replies() | |
|
563 | skipped_replies_count = thread_to_show.get_replies().count() \ | |
|
564 | - len(last_replies) - 1 | |
|
565 | return { | |
|
566 | 'thread': thread_to_show, | |
|
567 | 'op': thread_to_show.get_replies()[0], | |
|
568 | 'bumpable': thread_to_show.can_bump(), | |
|
569 | 'last_replies': last_replies, | |
|
570 | 'skipped_replies': skipped_replies_count, | |
|
571 | } |
General Comments 0
You need to be logged in to leave comments.
Login now