##// END OF EJS Templates
Split tests module into separate modules
Split tests module into separate modules

File last commit:

r821:572aaa88 default
r821:572aaa88 default
Show More
test_api.py
49 lines | 2.3 KiB | text/x-python | PythonLexer
import simplejson
from django.test import TestCase
from boards.models import Tag, Post
from boards.tests.mocks import MockRequest
from boards.utils import datetime_to_epoch
from boards.views.api import api_get_threaddiff
class ApiTest(TestCase):
def test_thread_diff(self):
tag = Tag.objects.create(name='test_tag')
opening_post = Post.objects.create_post(title='title', text='text',
tags=[tag])
last_edit_time = datetime_to_epoch(opening_post.last_edit_time)
# Check the exact timestamp post was added
empty_response = api_get_threaddiff(MockRequest(),
str(opening_post.thread_new.id),
str(last_edit_time))
diff = simplejson.loads(empty_response.content)
self.assertEqual(0, len(diff['added']),
'There must be no added posts in the diff.')
self.assertEqual(0, len(diff['updated']),
'There must be no updated posts in the diff.')
reply = Post.objects.create_post(title='',
text='[post]%d[/post]\ntext' % opening_post.id,
thread=opening_post.thread_new)
# Check the timestamp before post was added
response = api_get_threaddiff(MockRequest(),
str(opening_post.thread_new.id),
str(last_edit_time))
diff = simplejson.loads(response.content)
self.assertEqual(1, len(diff['added']),
'There must be 1 added posts in the diff.')
self.assertEqual(1, len(diff['updated']),
'There must be 1 updated posts in the diff.')
empty_response = api_get_threaddiff(MockRequest(),
str(opening_post.thread_new.id),
str(datetime_to_epoch(reply.last_edit_time)))
diff = simplejson.loads(empty_response.content)
self.assertEqual(0, len(diff['added']),
'There must be no added posts in the diff.')
self.assertEqual(0, len(diff['updated']),
'There must be no updated posts in the diff.')