##// END OF EJS Templates
Fixed indent in key manager
Fixed indent in key manager

File last commit:

r806:3a0369a9 decentral
r809:5b80316a decentral
Show More
tests.py
338 lines | 12.1 KiB | text/x-python | PythonLexer
neko259
Fixed unicode tags validation. Moved constants from classes to modules. Added error 404 when trying to get the non-existent thread. This fixes #19
r71 # coding=utf-8
neko259
Added test for all views get requests. Fixed banned view failing this test
r545 import time
import logging
neko259
Added a test for thread diff api
r801 import simplejson
neko259
Updated paginator for long page lists. Removed old get_threads method in the post manager
r596 from django.core.paginator import Paginator
neko259
Added test for all views get requests. Fixed banned view failing this test
r545
neko259
Use django's test case that works with database correctry without the need to flush transactions manually. Removed some workarounds that were used before
r345 from django.test import TestCase
Ilyas
Completed login and logout functionality and covered by tests.
r13 from django.test.client import Client
neko259
Added test for all views get requests. Fixed banned view failing this test
r545 from django.core.urlresolvers import reverse, NoReverseMatch
neko259
Divided settings manager into base settings manager class and session-based settings manager. This allowes to add other backends to the settings manager
r730 from boards.abstracts.settingsmanager import get_settings_manager
Ilyas
Completed login and logout functionality and covered by tests.
r13
neko259
Added KeyPair model for signing and verifying data, that will be user for...
r793 from boards.models import Post, Tag, Thread, KeyPair
neko259
Added test for all views get requests. Fixed banned view failing this test
r545 from boards import urls
neko259
Moved imageboard settings to the boards settings module. Added setting to disable archive
r716 from boards import settings
neko259
Added a test for thread diff api
r801 from boards.views.api import api_get_threaddiff
from boards.utils import datetime_to_epoch
neko259
Moved imageboard settings to the boards settings module. Added setting to disable archive
r716 import neboard
neko259
Initial commit. One test doesn't work, missing posting form.
r0
neko259
Removed linked tags. Added changelog for 2.0. Fixed reply connection.
r740 TEST_TAG = 'test_tag'
neko259
Cleaned up code in some modules. Added a new style for the contributor roles.
r203 PAGE_404 = 'boards/404.html'
neko259
Fixed unicode tags validation. Moved constants from classes to modules. Added error 404 when trying to get the non-existent thread. This fixes #19
r71 TEST_TEXT = 'test text'
NEW_THREAD_PAGE = '/'
neko259
Added error 404 for opening not existing thread or tag. This fixes #8
r79 THREAD_PAGE_ONE = '/thread/1/'
THREAD_PAGE = '/thread/'
TAG_PAGE = '/tag/'
neko259
Fixed unicode tags validation. Moved constants from classes to modules. Added error 404 when trying to get the non-existent thread. This fixes #19
r71 HTTP_CODE_REDIRECT = 302
neko259
Added error 404 for opening not existing thread or tag. This fixes #8
r79 HTTP_CODE_OK = 200
HTTP_CODE_NOT_FOUND = 404
neko259
Fixed unicode tags validation. Moved constants from classes to modules. Added error 404 when trying to get the non-existent thread. This fixes #19
r71
neko259
Added test for all views get requests. Fixed banned view failing this test
r545 logger = logging.getLogger(__name__)
neko259
Fixed the tests. Added exists() method for the post.
r8
neko259
Moved adding linked posts from view to post manager. Cleaned up tests, added some more tests
r381 class PostTests(TestCase):
neko259
Cleaned up code in some modules. Added a new style for the contributor roles.
r203
neko259
Added a text area to the posting form. Added a basic CSS style. Changed threads list a bit.
r16 def _create_post(self):
neko259
Removed linked tags. Added changelog for 2.0. Fixed reply connection.
r740 tag = Tag.objects.create(name=TEST_TAG)
return Post.objects.create_post(title='title', text='text',
tags=[tag])
neko259
Initial commit. One test doesn't work, missing posting form.
r0
def test_post_add(self):
neko259
Moved adding linked posts from view to post manager. Cleaned up tests, added some more tests
r381 """Test adding post"""
neko259
Added a text area to the posting form. Added a basic CSS style. Changed threads list a bit.
r16 post = self._create_post()
neko259
Added images upload. Changed the design a bit. Reformatted some code by PEP 8. Changed the urls: not the main site is located at /, not /boards/.
r22
neko259
Removed linked tags. Added changelog for 2.0. Fixed reply connection.
r740 self.assertIsNotNone(post, 'No post was created.')
self.assertEqual(TEST_TAG, post.get_thread().tags.all()[0].name,
'No tags were added to the post.')
neko259
Initial commit. One test doesn't work, missing posting form.
r0
def test_delete_post(self):
neko259
Moved adding linked posts from view to post manager. Cleaned up tests, added some more tests
r381 """Test post deletion"""
neko259
Added a text area to the posting form. Added a basic CSS style. Changed threads list a bit.
r16 post = self._create_post()
neko259
Fixed the tests. Added exists() method for the post.
r8 post_id = post.id
neko259
Added images upload. Changed the design a bit. Reformatted some code by PEP 8. Changed the urls: not the main site is located at /, not /boards/.
r22
neko259
Fixed indents for pycharm. Moved images upload path to settings. Some cosmetic changes.
r1 Post.objects.delete_post(post)
neko259
Initial commit. One test doesn't work, missing posting form.
r0
neko259
Removed strange 'exists' method in post manager, fixed tests in which it was...
r396 self.assertFalse(Post.objects.filter(id=post_id).exists())
neko259
Initial commit. One test doesn't work, missing posting form.
r0
neko259
Moved adding linked posts from view to post manager. Cleaned up tests, added some more tests
r381 def test_delete_thread(self):
"""Test thread deletion"""
neko259
Split up post model into post and thread to normalise models. Still need some refactoring
r398 opening_post = self._create_post()
neko259
Updated tests to use get_thread() method of post
r628 thread = opening_post.get_thread()
neko259
Moved adding linked posts from view to post manager. Cleaned up tests, added some more tests
r381 reply = Post.objects.create_post("", "", thread=thread)
neko259
Use own search form and view
r718 thread.delete()
neko259
Moved adding linked posts from view to post manager. Cleaned up tests, added some more tests
r381
neko259
Removed strange 'exists' method in post manager, fixed tests in which it was...
r396 self.assertFalse(Post.objects.filter(id=reply.id).exists())
neko259
Moved adding linked posts from view to post manager. Cleaned up tests, added some more tests
r381
neko259
Minor fixes. Added test for posting to thread
r380 def test_post_to_thread(self):
neko259
Moved adding linked posts from view to post manager. Cleaned up tests, added some more tests
r381 """Test adding post to a thread"""
neko259
Minor fixes. Added test for posting to thread
r380 op = self._create_post()
neko259
Updated tests to use get_thread() method of post
r628 post = Post.objects.create_post("", "", thread=op.get_thread())
neko259
Minor fixes. Added test for posting to thread
r380
self.assertIsNotNone(post, 'Reply to thread wasn\'t created')
neko259
Updated tests to use get_thread() method of post
r628 self.assertEqual(op.get_thread().last_edit_time, post.pub_time,
neko259
Minor fixes. Added test for posting to thread
r380 'Post\'s create time doesn\'t match thread last edit'
' time')
neko259
Initial commit. One test doesn't work, missing posting form.
r0 def test_delete_posts_by_ip(self):
neko259
Moved adding linked posts from view to post manager. Cleaned up tests, added some more tests
r381 """Test deleting posts with the given ip"""
neko259
Added a text area to the posting form. Added a basic CSS style. Changed threads list a bit.
r16 post = self._create_post()
neko259
Fixed the tests. Added exists() method for the post.
r8 post_id = post.id
neko259
Initial commit. One test doesn't work, missing posting form.
r0
neko259
Fixed indents for pycharm. Moved images upload path to settings. Some cosmetic changes.
r1 Post.objects.delete_posts_by_ip('0.0.0.0')
neko259
Initial commit. One test doesn't work, missing posting form.
r0
neko259
Removed strange 'exists' method in post manager, fixed tests in which it was...
r396 self.assertFalse(Post.objects.filter(id=post_id).exists())
Ilyas
Completed login and logout functionality and covered by tests.
r13
neko259
Fixed getting posts for a thread. Implemented thread getting test.
r17 def test_get_thread(self):
neko259
Moved adding linked posts from view to post manager. Cleaned up tests, added some more tests
r381 """Test getting all posts of a thread"""
neko259
Fixed getting posts for a thread. Implemented thread getting test.
r17 opening_post = self._create_post()
for i in range(0, 2):
neko259
Split up post model into post and thread to normalise models. Still need some refactoring
r398 Post.objects.create_post('title', 'text',
neko259
Updated tests to use get_thread() method of post
r628 thread=opening_post.get_thread())
neko259
Fixed getting posts for a thread. Implemented thread getting test.
r17
neko259
Updated tests to use get_thread() method of post
r628 thread = opening_post.get_thread()
neko259
Fixed getting posts for a thread. Implemented thread getting test.
r17
neko259
Split up post model into post and thread to normalise models. Still need some refactoring
r398 self.assertEqual(3, thread.replies.count())
neko259
Added localization (not fully working). Added tags posting. Changed the design a bit.
r24
def test_create_post_with_tag(self):
neko259
Moved adding linked posts from view to post manager. Cleaned up tests, added some more tests
r381 """Test adding tag to post"""
neko259
Added localization (not fully working). Added tags posting. Changed the design a bit.
r24 tag = Tag.objects.create(name='test_tag')
post = Post.objects.create_post(title='title', text='text', tags=[tag])
neko259
Split up post model into post and thread to normalise models. Still need some refactoring
r398
neko259
Updated tests to use get_thread() method of post
r628 thread = post.get_thread()
neko259
Split up post model into post and thread to normalise models. Still need some refactoring
r398 self.assertIsNotNone(post, 'Post not created')
self.assertTrue(tag in thread.tags.all(), 'Tag not added to thread')
self.assertTrue(thread in tag.threads.all(), 'Thread not added to tag')
neko259
Added maximum threads count parameter to the settings. Delete the old posts to preserve the max count. Small design tweaks.
r28
def test_thread_max_count(self):
neko259
Moved adding linked posts from view to post manager. Cleaned up tests, added some more tests
r381 """Test deletion of old posts when the max thread count is reached"""
neko259
Added maximum threads count parameter to the settings. Delete the old posts to preserve the max count. Small design tweaks.
r28 for i in range(settings.MAX_THREAD_COUNT + 1):
self._create_post()
self.assertEqual(settings.MAX_THREAD_COUNT,
neko259
Updated paginator for long page lists. Removed old get_threads method in the post manager
r596 len(Thread.objects.filter(archived=False)))
neko259
Compiling regexes for gets. #17 Added pagination. #28 Visually differing the dead (not bumpable) threads.
r46
def test_pages(self):
"""Test that the thread list is properly split into pages"""
for i in range(settings.MAX_THREAD_COUNT):
self._create_post()
neko259
Updated paginator for long page lists. Removed old get_threads method in the post manager
r596 all_threads = Thread.objects.filter(archived=False)
neko259
Compiling regexes for gets. #17 Added pagination. #28 Visually differing the dead (not bumpable) threads.
r46
neko259
Updated paginator for long page lists. Removed old get_threads method in the post manager
r596 paginator = Paginator(Thread.objects.filter(archived=False),
settings.THREADS_PER_PAGE)
posts_in_second_page = paginator.page(2).object_list
neko259
Compiling regexes for gets. #17 Added pagination. #28 Visually differing the dead (not bumpable) threads.
r46 first_post = posts_in_second_page[0]
self.assertEqual(all_threads[settings.THREADS_PER_PAGE].id,
neko259
Fixed unicode tags validation. Moved constants from classes to modules. Added error 404 when trying to get the non-existent thread. This fixes #19
r71 first_post.id)
neko259
Moved adding linked posts from view to post manager. Cleaned up tests, added some more tests
r381
class PagesTest(TestCase):
def test_404(self):
"""Test receiving error 404 when opening a non-existent page"""
tag_name = u'test_tag'
tag = Tag.objects.create(name=tag_name)
client = Client()
Post.objects.create_post('title', TEST_TEXT, tags=[tag])
existing_post_id = Post.objects.all()[0].id
response_existing = client.get(THREAD_PAGE + str(existing_post_id) +
'/')
self.assertEqual(HTTP_CODE_OK, response_existing.status_code,
u'Cannot open existing thread')
response_not_existing = client.get(THREAD_PAGE + str(
existing_post_id + 1) + '/')
neko259
Added django management command to clean old users. Cleaned up failing tests. Fixed error when trying to get a non-existent post
r689 self.assertEqual(PAGE_404, response_not_existing.templates[0].name,
neko259
Moved adding linked posts from view to post manager. Cleaned up tests, added some more tests
r381 u'Not existing thread is opened')
response_existing = client.get(TAG_PAGE + tag_name + '/')
self.assertEqual(HTTP_CODE_OK,
response_existing.status_code,
u'Cannot open existing tag')
response_not_existing = client.get(TAG_PAGE + u'not_tag' + '/')
self.assertEqual(PAGE_404,
response_not_existing.templates[0].name,
u'Not existing tag is opened')
reply_id = Post.objects.create_post('', TEST_TEXT,
neko259
Split up post model into post and thread to normalise models. Still need some refactoring
r398 thread=Post.objects.all()[0]
neko259
Added django management command to clean old users. Cleaned up failing tests. Fixed error when trying to get a non-existent post
r689 .get_thread())
neko259
Moved adding linked posts from view to post manager. Cleaned up tests, added some more tests
r381 response_not_existing = client.get(THREAD_PAGE + str(
reply_id) + '/')
self.assertEqual(PAGE_404,
response_not_existing.templates[0].name,
u'Reply is opened as a thread')
class FormTest(TestCase):
neko259
Fixed unicode tags validation. Moved constants from classes to modules. Added error 404 when trying to get the non-existent thread. This fixes #19
r71 def test_post_validation(self):
client = Client()
valid_tags = u'tag1 tag_2 тег_3'
invalid_tags = u'$%_356 ---'
response = client.post(NEW_THREAD_PAGE, {'title': 'test title',
'text': TEST_TEXT,
'tags': valid_tags})
self.assertEqual(response.status_code, HTTP_CODE_REDIRECT,
msg='Posting new message failed: got code ' +
str(response.status_code))
self.assertEqual(1, Post.objects.count(),
msg='No posts were created')
neko259
Added form validation, added style for the tag panel. This fixes #13
r76 client.post(NEW_THREAD_PAGE, {'text': TEST_TEXT,
'tags': invalid_tags})
neko259
Fixed unicode tags validation. Moved constants from classes to modules. Added error 404 when trying to get the non-existent thread. This fixes #19
r71 self.assertEqual(1, Post.objects.count(), msg='The validation passed '
neko259
Fixed validation of image without text. This refs #13
r77 'where it should fail')
neko259
Fixed page 404 test. Added a cat image to the banned page.
r181 # Change posting delay so we don't have to wait for 30 seconds or more
neko259
Moved imageboard settings to the boards settings module. Added setting to disable archive
r716 old_posting_delay = neboard.settings.POSTING_DELAY
neko259
Made tests properly override posting delay variable
r806 # Wait for the posting delay or we won't be able to post
neboard.settings.POSTING_DELAY = 1
neko259
Moved imageboard settings to the boards settings module. Added setting to disable archive
r716 time.sleep(neboard.settings.POSTING_DELAY + 1)
neko259
Added error 404 for opening not existing thread or tag. This fixes #8
r79 response = client.post(THREAD_PAGE_ONE, {'text': TEST_TEXT,
neko259
Implemented RSS support. This fixes #11
r89 'tags': valid_tags})
neko259
Added error 404 for opening not existing thread or tag. This fixes #8
r79 self.assertEqual(HTTP_CODE_REDIRECT, response.status_code,
msg=u'Posting new message failed: got code ' +
neko259
Fixed validation of image without text. This refs #13
r77 str(response.status_code))
neko259
Fixed page 404 test. Added a cat image to the banned page.
r181 # Restore posting delay
neko259
Made tests properly override posting delay variable
r806 neboard.settings.POSTING_DELAY = old_posting_delay
neko259
Fixed validation of image without text. This refs #13
r77
self.assertEqual(2, Post.objects.count(),
neko259
Added error 404 for opening not existing thread or tag. This fixes #8
r79 msg=u'No posts were created')
neko259
Small refactoring. Added index view test
r415
class ViewTest(TestCase):
neko259
Added test for all views get requests. Fixed banned view failing this test
r545
def test_all_views(self):
neko259
Divided settings manager into base settings manager class and session-based settings manager. This allowes to add other backends to the settings manager
r730 """
neko259
Added test for all views get requests. Fixed banned view failing this test
r545 Try opening all views defined in ulrs.py that don't need additional
parameters
neko259
Divided settings manager into base settings manager class and session-based settings manager. This allowes to add other backends to the settings manager
r730 """
neko259
Added test for all views get requests. Fixed banned view failing this test
r545
neko259
Small refactoring. Added index view test
r415 client = Client()
neko259
Added test for all views get requests. Fixed banned view failing this test
r545 for url in urls.urlpatterns:
try:
view_name = url.name
logger.debug('Testing view %s' % view_name)
neko259
Small refactoring. Added index view test
r415
neko259
Added test for all views get requests. Fixed banned view failing this test
r545 try:
response = client.get(reverse(view_name))
self.assertEqual(HTTP_CODE_OK, response.status_code,
neko259
Divided settings manager into base settings manager class and session-based settings manager. This allowes to add other backends to the settings manager
r730 '%s view not opened' % view_name)
neko259
Added test for all views get requests. Fixed banned view failing this test
r545 except NoReverseMatch:
# This view just needs additional arguments
pass
neko259
Moving neboard to python3 support (no python2 for now until we figure out how...
r765 except Exception as e:
neko259
Added test for all views get requests. Fixed banned view failing this test
r545 self.fail('Got exception %s at %s view' % (e, view_name))
except AttributeError:
# This is normal, some views do not have names
pass
neko259
Divided settings manager into base settings manager class and session-based settings manager. This allowes to add other backends to the settings manager
r730
class AbstractTest(TestCase):
def test_settings_manager(self):
request = MockRequest()
settings_manager = get_settings_manager(request)
settings_manager.set_setting('test_setting', 'test_value')
self.assertEqual('test_value', settings_manager.get_setting(
'test_setting'), u'Setting update failed.')
class MockRequest:
def __init__(self):
neko259
Removed linked tags. Added changelog for 2.0. Fixed reply connection.
r740 self.session = dict()
neko259
Added a test for thread diff api
r801 self.GET = dict()
self.POST = dict()
neko259
Added KeyPair model for signing and verifying data, that will be user for...
r793 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,
neko259
Made tests properly override posting delay variable
r806 key_type='ecdsa')
neko259
Added KeyPair model for signing and verifying data, that will be user for...
r793
self.assertTrue(valid, 'Message verification failed.')
neko259
Added 'primary' parameter for the key to indicate this key would be used in...
r796
def test_primary_constraint(self):
KeyPair.objects.generate_key(key_type='ecdsa', primary=True)
try:
KeyPair.objects.generate_key(key_type='ecdsa', primary=True)
neko259
Made tests properly override posting delay variable
r806 self.fail('Exception should be thrown indicating there can be only'
' one primary key.')
neko259
Added 'primary' parameter for the key to indicate this key would be used in...
r796 except Exception:
pass
neko259
Merged with default branch
r805
neko259
Added a test for thread diff api
r801 class ApiTest(TestCase):
def test_thread_diff(self):
tag = Tag.objects.create(name=TEST_TAG)
opening_post = Post.objects.create_post(title='title', text='text',
neko259
Merged with default branch
r805 tags=[tag])
neko259
Added a test for thread diff api
r801
last_edit_time = datetime_to_epoch(opening_post.last_edit_time)
# Check the exact timestamp post was added
empty_response = api_get_threaddiff(MockRequest(),
neko259
Merged with default branch
r805 str(opening_post.thread_new.id),
str(last_edit_time))
neko259
Added a test for thread diff api
r801 diff = simplejson.loads(empty_response.content)
self.assertEqual(0, len(diff['added']),
neko259
Merged with default branch
r805 'There must be no added posts in the diff.')
neko259
Added a test for thread diff api
r801 self.assertEqual(0, len(diff['updated']),
neko259
Merged with default branch
r805 'There must be no updated posts in the diff.')
neko259
Added a test for thread diff api
r801
reply = Post.objects.create_post(title='',
neko259
Merged with default branch
r805 text='[post]%d[/post]\ntext' % opening_post.id,
thread=opening_post.thread_new)
neko259
Added a test for thread diff api
r801
# Check the timestamp before post was added
response = api_get_threaddiff(MockRequest(),
neko259
Merged with default branch
r805 str(opening_post.thread_new.id),
str(last_edit_time))
neko259
Added a test for thread diff api
r801 diff = simplejson.loads(response.content)
self.assertEqual(1, len(diff['added']),
neko259
Merged with default branch
r805 'There must be 1 added posts in the diff.')
neko259
Added a test for thread diff api
r801 self.assertEqual(1, len(diff['updated']),
neko259
Merged with default branch
r805 'There must be 1 updated posts in the diff.')
neko259
Added a test for thread diff api
r801
empty_response = api_get_threaddiff(MockRequest(),
neko259
Merged with default branch
r805 str(opening_post.thread_new.id),
neko259
Made tests properly override posting delay variable
r806 str(datetime_to_epoch(
reply.last_edit_time)))
neko259
Added a test for thread diff api
r801 diff = simplejson.loads(empty_response.content)
self.assertEqual(0, len(diff['added']),
neko259
Merged with default branch
r805 'There must be no added posts in the diff.')
neko259
Added a test for thread diff api
r801 self.assertEqual(0, len(diff['updated']),
neko259
Merged with default branch
r805 'There must be no updated posts in the diff.')
neko259
Added a test for thread diff api
r801