Show More
@@ -1,19 +1,19 b'' | |||||
1 | {% extends "boards/thread.html" %} |
|
1 | {% extends "boards/thread.html" %} | |
2 |
|
2 | |||
3 | {% load i18n %} |
|
3 | {% load i18n %} | |
4 | {% load static from staticfiles %} |
|
4 | {% load static from staticfiles %} | |
5 | {% load board %} |
|
5 | {% load board %} | |
6 | {% load tz %} |
|
6 | {% load tz %} | |
7 |
|
7 | |||
8 | {% block thread_content %} |
|
8 | {% block thread_content %} | |
9 | {% get_current_language as LANGUAGE_CODE %} |
|
9 | {% get_current_language as LANGUAGE_CODE %} | |
10 | {% get_current_timezone as TIME_ZONE %} |
|
10 | {% get_current_timezone as TIME_ZONE %} | |
11 |
|
11 | |||
12 | <div class="thread"> |
|
12 | <div class="thread"> | |
13 | {% for post in thread.get_top_level_replies %} |
|
13 | {% for post in thread.get_top_level_replies %} | |
14 |
{% post_view post moderator=moderator |
|
14 | {% post_view post moderator=moderator mode_tree=True %} | |
15 | {% endfor %} |
|
15 | {% endfor %} | |
16 | </div> |
|
16 | </div> | |
17 |
|
17 | |||
18 | <script src="{% static 'js/thread.js' %}"></script> |
|
18 | <script src="{% static 'js/thread.js' %}"></script> | |
19 | {% endblock %} |
|
19 | {% endblock %} |
@@ -1,69 +1,69 b'' | |||||
1 | import simplejson |
|
1 | import simplejson | |
2 |
|
2 | |||
3 | from django.test import TestCase |
|
3 | from django.test import TestCase | |
4 | from boards.views import api |
|
4 | from boards.views import api | |
5 |
|
5 | |||
6 | from boards.models import Tag, Post |
|
6 | from boards.models import Tag, Post | |
7 | from boards.tests.mocks import MockRequest |
|
7 | from boards.tests.mocks import MockRequest | |
8 | from boards.utils import datetime_to_epoch |
|
8 | from boards.utils import datetime_to_epoch | |
9 |
|
9 | |||
10 |
|
10 | |||
11 | class ApiTest(TestCase): |
|
11 | class ApiTest(TestCase): | |
12 | def test_thread_diff(self): |
|
12 | def test_thread_diff(self): | |
13 | tag = Tag.objects.create(name='test_tag') |
|
13 | tag = Tag.objects.create(name='test_tag') | |
14 | opening_post = Post.objects.create_post(title='title', text='text', |
|
14 | opening_post = Post.objects.create_post(title='title', text='text', | |
15 | tags=[tag]) |
|
15 | tags=[tag]) | |
16 |
|
16 | |||
17 | req = MockRequest() |
|
17 | req = MockRequest() | |
18 |
req. |
|
18 | req.POST['thread'] = opening_post.id | |
19 | req.POST['uids'] = opening_post.uid |
|
19 | req.POST['uids'] = opening_post.uid | |
20 | # Check the exact timestamp post was added |
|
20 | # Check the exact timestamp post was added | |
21 | empty_response = api.api_get_threaddiff(req) |
|
21 | empty_response = api.api_get_threaddiff(req) | |
22 | diff = simplejson.loads(empty_response.content) |
|
22 | diff = simplejson.loads(empty_response.content) | |
23 | self.assertEqual(0, len(diff['updated']), |
|
23 | self.assertEqual(0, len(diff['updated']), | |
24 | 'There must be no updated posts in the diff.') |
|
24 | 'There must be no updated posts in the diff.') | |
25 |
|
25 | |||
26 | uids = [opening_post.uid] |
|
26 | uids = [opening_post.uid] | |
27 |
|
27 | |||
28 | reply = Post.objects.create_post(title='', |
|
28 | reply = Post.objects.create_post(title='', | |
29 | text='[post]%d[/post]\ntext' % opening_post.id, |
|
29 | text='[post]%d[/post]\ntext' % opening_post.id, | |
30 | thread=opening_post.get_thread()) |
|
30 | thread=opening_post.get_thread()) | |
31 | req = MockRequest() |
|
31 | req = MockRequest() | |
32 |
req. |
|
32 | req.POST['thread'] = opening_post.id | |
33 | req.POST['uids'] = ' '.join(uids) |
|
33 | req.POST['uids'] = ' '.join(uids) | |
34 | # Check the timestamp before post was added |
|
34 | # Check the timestamp before post was added | |
35 | response = api.api_get_threaddiff(req) |
|
35 | response = api.api_get_threaddiff(req) | |
36 | diff = simplejson.loads(response.content) |
|
36 | diff = simplejson.loads(response.content) | |
37 | self.assertEqual(2, len(diff['updated']), |
|
37 | self.assertEqual(2, len(diff['updated']), | |
38 | 'There must be 2 updated posts in the diff.') |
|
38 | 'There must be 2 updated posts in the diff.') | |
39 |
|
39 | |||
40 | # Reload post to get the new UID |
|
40 | # Reload post to get the new UID | |
41 | opening_post = Post.objects.get(id=opening_post.id) |
|
41 | opening_post = Post.objects.get(id=opening_post.id) | |
42 | req = MockRequest() |
|
42 | req = MockRequest() | |
43 |
req. |
|
43 | req.POST['thread'] = opening_post.id | |
44 | req.POST['uids'] = ' '.join([opening_post.uid, reply.uid]) |
|
44 | req.POST['uids'] = ' '.join([opening_post.uid, reply.uid]) | |
45 | empty_response = api.api_get_threaddiff(req) |
|
45 | empty_response = api.api_get_threaddiff(req) | |
46 | diff = simplejson.loads(empty_response.content) |
|
46 | diff = simplejson.loads(empty_response.content) | |
47 | self.assertEqual(0, len(diff['updated']), |
|
47 | self.assertEqual(0, len(diff['updated']), | |
48 | 'There must be no updated posts in the diff.') |
|
48 | 'There must be no updated posts in the diff.') | |
49 |
|
49 | |||
50 | def test_get_threads(self): |
|
50 | def test_get_threads(self): | |
51 | # Create 10 threads |
|
51 | # Create 10 threads | |
52 | tag = Tag.objects.create(name='test_tag') |
|
52 | tag = Tag.objects.create(name='test_tag') | |
53 | for i in range(5): |
|
53 | for i in range(5): | |
54 | Post.objects.create_post(title='title', text='text', tags=[tag]) |
|
54 | Post.objects.create_post(title='title', text='text', tags=[tag]) | |
55 |
|
55 | |||
56 | # Get all threads |
|
56 | # Get all threads | |
57 | response = api.api_get_threads(MockRequest(), 5) |
|
57 | response = api.api_get_threads(MockRequest(), 5) | |
58 | diff = simplejson.loads(response.content) |
|
58 | diff = simplejson.loads(response.content) | |
59 | self.assertEqual(5, len(diff), 'Invalid thread list response.') |
|
59 | self.assertEqual(5, len(diff), 'Invalid thread list response.') | |
60 |
|
60 | |||
61 | # Get less threads then exist |
|
61 | # Get less threads then exist | |
62 | response = api.api_get_threads(MockRequest(), 3) |
|
62 | response = api.api_get_threads(MockRequest(), 3) | |
63 | diff = simplejson.loads(response.content) |
|
63 | diff = simplejson.loads(response.content) | |
64 | self.assertEqual(3, len(diff), 'Invalid thread list response.') |
|
64 | self.assertEqual(3, len(diff), 'Invalid thread list response.') | |
65 |
|
65 | |||
66 | # Get more threads then exist |
|
66 | # Get more threads then exist | |
67 | response = api.api_get_threads(MockRequest(), 10) |
|
67 | response = api.api_get_threads(MockRequest(), 10) | |
68 | diff = simplejson.loads(response.content) |
|
68 | diff = simplejson.loads(response.content) | |
69 | self.assertEqual(5, len(diff), 'Invalid thread list response.') |
|
69 | self.assertEqual(5, len(diff), 'Invalid thread list response.') |
General Comments 0
You need to be logged in to leave comments.
Login now