2014-10-22 23:38:32 +03:00
|
|
|
import json
|
2014-10-10 00:30:34 +03:00
|
|
|
from nose.tools import *
|
|
|
|
from flask import url_for
|
2014-11-13 01:06:56 +02:00
|
|
|
from realms.lib.util import cname_to_filename, filename_to_cname
|
2014-10-22 00:06:27 +03:00
|
|
|
from realms.lib.test import BaseTest
|
2014-10-10 00:30:34 +03:00
|
|
|
|
|
|
|
|
2014-10-22 23:38:32 +03:00
|
|
|
class WikiBaseTest(BaseTest):
|
2014-10-31 00:59:19 +02:00
|
|
|
def update_page(self, name, message=None, content=None):
|
|
|
|
return self.client.post(url_for('wiki.page_write', name=name),
|
|
|
|
data=dict(message=message, content=content))
|
|
|
|
|
|
|
|
def create_page(self, name, message=None, content=None):
|
2014-10-22 23:38:32 +03:00
|
|
|
return self.client.post(url_for('wiki.page_write', name=name),
|
|
|
|
data=dict(message=message, content=content))
|
2014-10-10 00:30:34 +03:00
|
|
|
|
|
|
|
|
2014-10-22 23:38:32 +03:00
|
|
|
class UtilTest(WikiBaseTest):
|
|
|
|
def test_cname_to_filename(self):
|
|
|
|
eq_(cname_to_filename('test'), 'test.md')
|
|
|
|
|
|
|
|
def test_filename_to_cname(self):
|
|
|
|
eq_(filename_to_cname('test-1-2-3.md'), 'test-1-2-3')
|
|
|
|
|
|
|
|
|
|
|
|
class WikiTest(WikiBaseTest):
|
|
|
|
def test_routes(self):
|
2014-10-10 00:30:34 +03:00
|
|
|
self.assert_200(self.client.get(url_for("wiki.create")))
|
2014-10-31 00:59:19 +02:00
|
|
|
self.create_page('test', message='test message', content='testing')
|
2014-10-10 00:30:34 +03:00
|
|
|
|
2014-10-22 23:38:32 +03:00
|
|
|
for route in ['page', 'edit', 'history']:
|
2014-10-10 00:30:34 +03:00
|
|
|
rv = self.client.get(url_for("wiki.%s" % route, name='test'))
|
|
|
|
self.assert_200(rv, "wiki.%s: %s" % (route, rv.status_code))
|
2014-10-22 23:38:32 +03:00
|
|
|
|
|
|
|
self.assert_200(self.client.get(url_for('wiki.index')))
|
2014-10-10 00:30:34 +03:00
|
|
|
|
|
|
|
def test_write_page(self):
|
2014-10-31 00:59:19 +02:00
|
|
|
self.assert_200(self.create_page('test', message='test message', content='testing'))
|
2014-10-22 23:38:32 +03:00
|
|
|
|
|
|
|
rv = self.client.get(url_for('wiki.page', name='test'))
|
|
|
|
self.assert_200(rv)
|
2014-10-22 00:06:27 +03:00
|
|
|
|
2014-10-22 23:38:32 +03:00
|
|
|
self.assert_context('name', 'test')
|
|
|
|
eq_(self.get_context_variable('page')['info']['message'], 'test message')
|
|
|
|
eq_(self.get_context_variable('page')['data'], 'testing')
|
|
|
|
|
|
|
|
def test_history(self):
|
|
|
|
self.assert_200(self.client.get(url_for('wiki.history', name='test')))
|
2014-10-22 00:06:27 +03:00
|
|
|
|
|
|
|
def test_delete_page(self):
|
2014-10-22 23:38:32 +03:00
|
|
|
self.app.config['WIKI_LOCKED_PAGES'] = ['test']
|
|
|
|
self.assert_403(self.client.delete(url_for('wiki.page_write', name='test')))
|
|
|
|
self.app.config['WIKI_LOCKED_PAGES'] = []
|
|
|
|
|
2014-10-22 00:06:27 +03:00
|
|
|
self.assert_200(self.client.delete(url_for('wiki.page_write', name='test')))
|
2014-10-22 23:38:32 +03:00
|
|
|
|
|
|
|
rv = self.client.get(url_for('wiki.page', name='test'))
|
|
|
|
self.assert_status(rv, 302)
|
2014-10-10 00:30:34 +03:00
|
|
|
|
|
|
|
def test_revert(self):
|
2014-10-31 00:59:19 +02:00
|
|
|
rv1 = self.create_page('test', message='test message', content='testing_old')
|
|
|
|
self.update_page('test', message='test message', content='testing_new')
|
2014-10-22 23:38:32 +03:00
|
|
|
data = json.loads(rv1.data)
|
|
|
|
self.client.post(url_for('wiki.revert'), data=dict(name='test', commit=data['sha']))
|
|
|
|
self.client.get(url_for('wiki.page', name='test'))
|
|
|
|
eq_(self.get_context_variable('page')['data'], 'testing_old')
|
|
|
|
self.assert_404(self.client.post(url_for('wiki.revert'), data=dict(name='test', commit='does not exist')))
|
2014-10-10 00:30:34 +03:00
|
|
|
|
2014-10-22 23:38:32 +03:00
|
|
|
self.app.config['WIKI_LOCKED_PAGES'] = ['test']
|
|
|
|
self.assert_403(self.client.post(url_for('wiki.revert'), data=dict(name='test', commit=data['sha'])))
|
|
|
|
self.app.config['WIKI_LOCKED_PAGES'] = []
|
2014-10-10 00:30:34 +03:00
|
|
|
|
2014-10-31 00:59:19 +02:00
|
|
|
def test_anon(self):
|
|
|
|
rv1 = self.create_page('test', message='test message', content='testing_old')
|
|
|
|
self.update_page('test', message='test message', content='testing_new')
|
|
|
|
data = json.loads(rv1.data)
|
|
|
|
self.app.config['ALLOW_ANON'] = False
|
|
|
|
self.assert_403(self.update_page('test', message='test message', content='testing_again'))
|
|
|
|
self.assert_403(self.client.post(url_for('wiki.revert'), data=dict(name='test', commit=data['sha'])))
|
|
|
|
|
2014-10-22 23:38:32 +03:00
|
|
|
|
|
|
|
class RelativePathTest(WikiTest):
|
|
|
|
def configure(self):
|
|
|
|
return dict(RELATIVE_PATH='wiki')
|