##// 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
neko259
Added GET request handler, command for key generation. Changed KeyPair format for ecdsa (use to_string instead of to_pem because it's shorter)
r836 from boards.models import KeyPair, Post
neko259
Sync-import of a single post is working
r1229 from boards.models.post.sync import SyncManager
neko259
Added GET request handler, command for key generation. Changed KeyPair format for ecdsa (use to_string instead of to_pem because it's shorter)
r836 from boards.tests.mocks import MockRequest
neko259
Merged with default branch
r1227 from boards.views.sync import response_get
neko259
Added GET request handler, command for key generation. Changed KeyPair format for ecdsa (use to_string instead of to_pem because it's shorter)
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.
"""
neko259
Added signatures to the GET response. Added a view to get a full post response for one post. Don't show post key as it is present in the XML post view. Changed key display format
r837 KeyPair.objects.generate_key(primary=True)
neko259
Added GET request handler, command for key generation. Changed KeyPair format for ecdsa (use to_string instead of to_pem because it's shorter)
r836 post = Post.objects.create_post(title='test_title', text='test_text')
request = MockRequest()
neko259
Merged with default branch
r1227 request.body = (
neko259
Added GET request handler, command for key generation. Changed KeyPair format for ecdsa (use to_string instead of to_pem because it's shorter)
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)
)
neko259
Sync-import of a single post is working
r1229 response = response_get(request).content.decode()
neko259
Added GET request handler, command for key generation. Changed KeyPair format for ecdsa (use to_string instead of to_pem because it's shorter)
r836 self.assertTrue(
'<status>success</status>'
'<models>'
neko259
Moved signatures block to the model block. All the signed content is in the 'content' block now. Removed edit time, previous and next posts links from the XML sync output because they can be computed from the post itself and can be changed locally for foreign posts (which breaks the signature)
r838 '<model name="post">'
'<content>'
neko259
Added GET request handler, command for key generation. Changed KeyPair format for ecdsa (use to_string instead of to_pem because it's shorter)
r836 '<id key="%s" local-id="%d" type="%s" />'
'<title>%s</title>'
'<text>%s</text>'
neko259
Sync-import of a single post is working
r1229 '<pub-time>%s</pub-time>'
neko259
Moved signatures block to the model block. All the signed content is in the 'content' block now. Removed edit time, previous and next posts links from the XML sync output because they can be computed from the post itself and can be changed locally for foreign posts (which breaks the signature)
r838 '</content>' % (
neko259
Added GET request handler, command for key generation. Changed KeyPair format for ecdsa (use to_string instead of to_pem because it's shorter)
r836 post.global_id.key,
post.id,
post.global_id.key_type,
post.title,
neko259
Fixed connecting replies to posts
r935 post.get_raw_text(),
neko259
Sync-import of a single post is working
r1229 post.get_pub_time_str(),
neko259
Merged with default branch
r1227 ) in response_get(request).content.decode(),
neko259
Fixed connecting replies to posts
r935 'Wrong response generated for the GET request.')
neko259
Sync-import of a single post is working
r1229
post.delete()
neko259
Made SyncManager's methods static
r1236 SyncManager.parse_response_get(response)
neko259
Sync-import of a single post is working
r1229 self.assertEqual(1, Post.objects.count(),
'Post was not created from XML response.')
neko259
Don't allow to import the same post twice
r1232
neko259
Made SyncManager's methods static
r1236 SyncManager.parse_response_get(response)
neko259
Don't allow to import the same post twice
r1232 self.assertEqual(1, Post.objects.count(),
'The same post was imported twice.')