from boards.models import KeyPair, Post, Tag
from boards.models.post.sync import SyncManager
from boards.tests.mocks import MockRequest
from boards.views.sync import response_get
__author__ = 'neko259'
from django.test import TestCase
class SyncTest(TestCase):
def test_get(self):
"""
Forms a GET request of a post and checks the response.
"""
KeyPair.objects.generate_key(primary=True)
tag = Tag.objects.create(name='tag1')
post = Post.objects.create_post(title='test_title', text='test_text',
tags=[tag])
request = MockRequest()
request.body = (
''
''
''
''
'' % (post.global_id.key,
post.id,
post.global_id.key_type)
)
response = response_get(request).content.decode()
self.assertTrue(
'success'
''
''
''
''
'%s'
'%s'
'%s'
'%s'
'' % (
post.global_id.key,
post.id,
post.global_id.key_type,
post.title,
post.get_raw_text(),
post.get_thread().get_tags().first().name,
post.get_pub_time_str(),
) in response_get(request).content.decode(),
'Wrong response generated for the GET request.')
post.delete()
SyncManager.parse_response_get(response)
self.assertEqual(1, Post.objects.count(),
'Post was not created from XML response.')
parsed_post = Post.objects.first()
self.assertEqual('tag1',
parsed_post.get_thread().get_tags().first().name,
'Invalid tag was parsed.')
SyncManager.parse_response_get(response)
self.assertEqual(1, Post.objects.count(),
'The same post was imported twice.')