##// END OF EJS Templates
Made SyncManager's methods static
Made SyncManager's methods static

File last commit:

r1236:124750d7 decentral
r1236:124750d7 decentral
Show More
test_sync.py
60 lines | 1.9 KiB | text/x-python | PythonLexer
from boards.models import KeyPair, Post
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)
post = Post.objects.create_post(title='test_title', text='test_text')
request = MockRequest()
request.body = (
'<request type="get" version="1.0">'
'<model name="post" version="1.0">'
'<id key="%s" local-id="%d" type="%s" />'
'</model>'
'</request>' % (post.global_id.key,
post.id,
post.global_id.key_type)
)
response = response_get(request).content.decode()
self.assertTrue(
'<status>success</status>'
'<models>'
'<model name="post">'
'<content>'
'<id key="%s" local-id="%d" type="%s" />'
'<title>%s</title>'
'<text>%s</text>'
'<pub-time>%s</pub-time>'
'</content>' % (
post.global_id.key,
post.id,
post.global_id.key_type,
post.title,
post.get_raw_text(),
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.')
SyncManager.parse_response_get(response)
self.assertEqual(1, Post.objects.count(),
'The same post was imported twice.')