##// END OF EJS Templates
Merge tip
Merge tip

File last commit:

r1928:f3702378 default
r2144:1765cedc merge lite
Show More
test_keys.py
90 lines | 3.4 KiB | text/x-python | PythonLexer
neko259
Generate GET request and response (not full yet). Add global id to the posts...
r827 import logging
neko259
Merged with default branch (tests split)
r822 from django.test import TestCase
neko259
Save signatures when the post is parsed for the later use
r1244 from boards.models import KeyPair, GlobalId, Post, Signature
neko259
Merged with default branch
r1227 from boards.models.post.sync import SyncManager
neko259
Generate GET request and response (not full yet). Add global id to the posts...
r827
logger = logging.getLogger(__name__)
neko259
Merged with default branch (tests split)
r822
class KeyTest(TestCase):
def test_create_key(self):
key = KeyPair.objects.generate_key('ecdsa')
self.assertIsNotNone(key, 'The key was not created.')
def test_validation(self):
key = KeyPair.objects.generate_key(key_type='ecdsa')
message = 'msg'
neko259
Save signatures when the post is parsed for the later use
r1244 signature_value = key.sign(message)
signature = Signature(key_type='ecdsa', key=key.public_key,
signature=signature_value)
valid = KeyPair.objects.verify(signature, message)
neko259
Merged with default branch (tests split)
r822
self.assertTrue(valid, 'Message verification failed.')
def test_primary_constraint(self):
KeyPair.objects.generate_key(key_type='ecdsa', primary=True)
neko259
Fixed posting without a primary key defined. Use more proper way to assert an exception
r835 with self.assertRaises(Exception):
neko259
Merged with default branch (tests split)
r822 KeyPair.objects.generate_key(key_type='ecdsa', primary=True)
neko259
Generate GET request and response (not full yet). Add global id to the posts...
r827 def test_model_id_save(self):
neko259
Merged with default branch (tests split)
r822 model_id = GlobalId(key_type='test', key='test key', local_id='1')
model_id.save()
neko259
Generate GET request and response (not full yet). Add global id to the posts...
r827 def test_request_get(self):
post = self._create_post_with_key()
neko259
Added ability to filter posts in the LIST request
r1834 request = SyncManager.generate_request_get([post.global_id])
neko259
Generate GET request and response (not full yet). Add global id to the posts...
r827 logger.debug(request)
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 key = KeyPair.objects.get(primary=True)
neko259
Added more parameters to the post xml output
r828 self.assertTrue('<request type="get" version="1.0">'
'<model name="post" version="1.0">'
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 '<id key="%s" local-id="1" type="%s" />'
neko259
Added more parameters to the post xml output
r828 '</model>'
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 '</request>' % (
key.public_key,
key.key_type,
) in request,
neko259
Merged with default branch (tests split)
r822 'Wrong XML generated for the GET request.')
neko259
Generate GET request and response (not full yet). Add global id to the posts...
r827
def test_response_get(self):
post = self._create_post_with_key()
neko259
Added next id list, previous id list and thread to the post XML output
r829 reply_post = Post.objects.create_post(title='test_title',
neko259
Fixed posting without a primary key defined. Use more proper way to assert an exception
r835 text='[post]%d[/post]' % post.id,
thread=post.get_thread())
neko259
Generate GET request and response (not full yet). Add global id to the posts...
r827
neko259
Made SyncManager's methods static
r1236 response = SyncManager.generate_response_get([reply_post])
neko259
Generate GET request and response (not full yet). Add global id to the posts...
r827 logger.debug(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 key = KeyPair.objects.get(primary=True)
self.assertTrue('<status>success</status>'
neko259
Added more parameters to the post xml output
r828 '<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 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 '<id key="%s" local-id="%d" type="%s" />'
neko259
Added more parameters to the post xml output
r828 '<title>test_title</title>'
neko259
Convert local post IDs to global when generating responses
r1228 '<text>[post]%s[/post]</text>'
neko259
Use global thread ID instead of local one.
r936 '<thread><id key="%s" local-id="%d" type="%s" /></thread>'
neko259
Added more parameters to the post xml output
r828 '<pub-time>%s</pub-time>'
neko259
Added post versions to list request, changed list request to include additional attributes
r1571 '<version>%s</version>'
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 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 key.public_key,
neko259
Added next id list, previous id list and thread to the post XML output
r829 reply_post.id,
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 key.key_type,
neko259
Convert local post IDs to global when generating responses
r1228 str(post.global_id),
neko259
Use global thread ID instead of local one.
r936 key.public_key,
neko259
Added next id list, previous id list and thread to the post XML output
r829 post.id,
neko259
Use global thread ID instead of local one.
r936 key.key_type,
neko259
Sync-import of a single post is working
r1229 str(reply_post.get_pub_time_str()),
neko259
Added post versions to list request, changed list request to include additional attributes
r1571 post.version,
neko259
Added more parameters to the post xml output
r828 ) in response,
neko259
Generate GET request and response (not full yet). Add global id to the posts...
r827 'Wrong XML generated for the GET response.')
def _create_post_with_key(self):
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
Generate GET request and response (not full yet). Add global id to the posts...
r827
return Post.objects.create_post(title='test_title', text='test_text')