##// END OF EJS Templates
Fixed posting without a primary key defined. Use more proper way to assert an exception
Fixed posting without a primary key defined. Use more proper way to assert an exception

File last commit:

r835:0f3bc07f decentral
r835:0f3bc07f decentral
Show More
test_keys.py
95 lines | 3.8 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
Generate GET request and response (not full yet). Add global id to the posts...
r827 from boards.models import KeyPair, GlobalId, Post
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'
signature = key.sign(message)
valid = KeyPair.objects.verify(key.public_key, message, signature,
key_type='ecdsa')
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()
request = Post.objects.generate_request_get([post])
logger.debug(request)
neko259
Added more parameters to the post xml output
r828 self.assertTrue('<request type="get" version="1.0">'
'<model name="post" version="1.0">'
'<id key="pubkey" local-id="1" type="test_key_type" />'
'</model>'
'</request>' 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
Added next id list, previous id list and thread to the post XML output
r829 reply_reply_post = Post.objects.create_post(title='',
neko259
Fixed posting without a primary key defined. Use more proper way to assert an exception
r835 text='[post]%d[/post]'
% reply_post.id,
thread=post.get_thread())
neko259
Generate GET request and response (not full yet). Add global id to the posts...
r827
neko259
Added next id list, previous id list and thread to the post XML output
r829 response = Post.objects.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 more parameters to the post xml output
r828 self.assertTrue('<response>'
'<status>success</status>'
'<models>'
'<model name="post" ref-id="1">'
neko259
Added next id list, previous id list and thread to the post XML output
r829 '<id key="pubkey" local-id="%d" type="test_key_type" />'
neko259
Added more parameters to the post xml output
r828 '<title>test_title</title>'
neko259
Added next id list, previous id list and thread to the post XML output
r829 '<text>[post]%d[/post]</text>'
'<thread>%d</thread>'
neko259
Added more parameters to the post xml output
r828 '<pub-time>%s</pub-time>'
'<edit-time>%s</edit-time>'
neko259
Added next id list, previous id list and thread to the post XML output
r829 '<previous>'
'<id key="pubkey" local-id="%d" type="test_key_type" />'
'</previous>'
'<next>'
'<id key="pubkey" local-id="%d" type="test_key_type" />'
'</next>'
neko259
Added more parameters to the post xml output
r828 '</model>'
'</models>'
'</response>' % (
neko259
Added next id list, previous id list and thread to the post XML output
r829 reply_post.id,
post.id,
post.id,
str(reply_post.get_edit_time_epoch()),
str(reply_post.get_pub_time_epoch()),
post.id,
reply_reply_post.id,
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):
key = KeyPair(public_key='pubkey', private_key='privkey',
key_type='test_key_type', primary=True)
key.save()
return Post.objects.create_post(title='test_title', text='test_text')