test_sync.py
60 lines
| 1.9 KiB
| text/x-python
|
PythonLexer
|
r836 | from boards.models import KeyPair, Post | ||
|
r1229 | from boards.models.post.sync import SyncManager | ||
|
r836 | from boards.tests.mocks import MockRequest | ||
|
r1227 | from boards.views.sync import response_get | ||
|
r836 | |||
__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. | ||||
""" | ||||
|
r837 | KeyPair.objects.generate_key(primary=True) | ||
|
r836 | post = Post.objects.create_post(title='test_title', text='test_text') | ||
request = MockRequest() | ||||
|
r1227 | request.body = ( | ||
|
r836 | '<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) | ||||
) | ||||
|
r1229 | response = response_get(request).content.decode() | ||
|
r836 | self.assertTrue( | ||
'<status>success</status>' | ||||
'<models>' | ||||
|
r838 | '<model name="post">' | ||
'<content>' | ||||
|
r836 | '<id key="%s" local-id="%d" type="%s" />' | ||
'<title>%s</title>' | ||||
'<text>%s</text>' | ||||
|
r1229 | '<pub-time>%s</pub-time>' | ||
|
r838 | '</content>' % ( | ||
|
r836 | post.global_id.key, | ||
post.id, | ||||
post.global_id.key_type, | ||||
post.title, | ||||
|
r935 | post.get_raw_text(), | ||
|
r1229 | post.get_pub_time_str(), | ||
|
r1227 | ) in response_get(request).content.decode(), | ||
|
r935 | 'Wrong response generated for the GET request.') | ||
|
r1229 | |||
post.delete() | ||||
SyncManager().parse_response_get(response) | ||||
self.assertEqual(1, Post.objects.count(), | ||||
'Post was not created from XML response.') | ||||
|
r1232 | |||
SyncManager().parse_response_get(response) | ||||
self.assertEqual(1, Post.objects.count(), | ||||
'The same post was imported twice.') | ||||