Parent: [a6131c] (diff)

Child: [f1ef58] (diff)

Download this file

test_root.py    160 lines (132 with data), 6.0 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
import os
from nose.tools import assert_true
from forgewiki.tests import TestController
from forgewiki import model
# These are needed for faking reactor actions
import mock
from pyforge.lib import helpers as h
from pyforge.command import reactor
from pyforge.ext.search import search_main
from ming.orm.ormsession import ThreadLocalORMSession
#---------x---------x---------x---------x---------x---------x---------x
# RootController methods exposed:
# index, new_page, search
# PageController methods exposed:
# index, edit, history, diff, raw, revert, update
# CommentController methods exposed:
# reply, delete
class TestRootController(TestController):
def test_root_index(self):
response = self.app.get('/Wiki/TEST/index')
assert 'TEST' in response
def test_root_markdown_syntax(self):
response = self.app.get('/Wiki/markdown_syntax/')
assert 'Markdown Syntax' in response
def test_root_wiki_help(self):
response = self.app.get('/Wiki/wiki_help/')
assert 'Wiki Help' in response
def test_root_browse_tags(self):
response = self.app.get('/Wiki/browse_tags/')
assert 'Browse Tags' in response
def test_root_browse_pages(self):
response = self.app.get('/Wiki/browse_pages/')
assert 'Browse Pages' in response
def test_root_new_page(self):
response = self.app.get('/Wiki/new_page?title=TEST')
assert 'TEST' in response
def test_root_new_search(self):
self.app.get('/Wiki/TEST/index')
response = self.app.get('/Wiki/search?q=TEST')
assert 'ForgeWiki Search' in response
def test_page_index(self):
response = self.app.get('/Wiki/TEST/index/')
assert 'TEST' in response
def test_page_edit(self):
self.app.get('/Wiki/TEST/index/')
response = self.app.post('/Wiki/TEST/edit')
assert 'TEST' in response
def test_page_history(self):
response = self.app.get('/Wiki/TEST/history')
assert 'TEST' in response
def test_page_diff(self):
self.app.get('/Wiki/TEST/index/')
self.app.get('/Wiki/TEST/revert?version=1')
response = self.app.get('/Wiki/TEST/diff?v1=0&v2=0')
assert 'TEST' in response
def test_page_raw(self):
self.app.get('/Wiki/TEST/index/')
response = self.app.get('/Wiki/TEST/raw')
assert 'TEST' in response
def test_page_revert_no_text(self):
self.app.get('/Wiki/TEST/index/')
response = self.app.get('/Wiki/TEST/revert?version=1')
assert 'TEST' in response
def test_page_revert_with_text(self):
self.app.get('/Wiki/TEST/index/')
self.app.get('/Wiki/TEST/update?text=sometext&tags=&tags_old=')
response = self.app.get('/Wiki/TEST/revert?version=1')
assert 'TEST' in response
def test_page_update(self):
self.app.get('/Wiki/TEST/index/')
response = self.app.get('/Wiki/TEST/update?text=sometext&tags=&tags_old=')
assert 'TEST' in response
def test_page_tag_untag(self):
self.app.get('/Wiki/TEST/index/')
response = self.app.get('/Wiki/TEST/update?text=sometext&tags=red,blue&tags_old=red,blue')
assert 'TEST' in response
response = self.app.get('/Wiki/TEST/update?text=sometext&tags=red&tags_old=red')
assert 'TEST' in response
def test_comment_reply(self):
self.app.get('/Wiki/TEST/index')
response = self.app.post('/Wiki/TEST/comments/reply?text=sometext')
# def test_comment_delete(self):
# response = self.app.get('/Wiki/TEST/index')
# response = self.app.post('/Wiki/TEST/comments/reply?text=sometext')
# response = self.app.post('/Wiki/TEST/comments/delete')
def test_new_attachment(self):
self.app.get('/Wiki/TEST/index')
content = file(__file__).read()
response = self.app.post('/Wiki/TEST/attach', upload_files=[('file_info', 'test_root.py', content)]).follow()
assert 'test_root.py' in response
def test_sidebar_static_page(self):
response = self.app.get('/Wiki/TEST/')
assert 'Edit this page' not in response
assert 'Related Pages' not in response
def test_sidebar_dynamic_page(self):
response = self.app.get('/Wiki/TEST/').follow()
assert 'Edit this page' in response
assert 'Related Pages' not in response
self.app.get('/Wiki/aaa/')
self.app.get('/Wiki/bbb/')
# Fake out updating the pages since reactor doesn't work with tests
app = search_main.SearchApp
cmd = reactor.ReactorCommand('reactor')
cmd.args = [ os.environ.get('SANDBOX') and 'sandbox-test.ini' or 'test.ini' ]
cmd.options = mock.Mock()
cmd.options.dry_run = True
cmd.options.proc = 1
configs = cmd.command()
add_artifacts = cmd.route_audit('search', app.add_artifacts)
del_artifacts = cmd.route_audit('search', app.del_artifacts)
msg = mock.Mock()
msg.ack = lambda:None
msg.delivery_info = dict(routing_key='search.add_artifacts')
h.set_context('test', 'wiki')
a = model.Page.query.find(dict(title='aaa')).first()
a.text = '\n[TEST]\n'
msg.data = dict(project_id=a.project_id,
mount_point=a.app_config.options.mount_point,
artifacts=[a.dump_ref()])
add_artifacts(msg.data, msg)
b = model.Page.query.find(dict(title='TEST')).first()
b.text = '\n[bbb]\n'
msg.data = dict(project_id=b.project_id,
mount_point=b.app_config.options.mount_point,
artifacts=[b.dump_ref()])
add_artifacts(msg.data, msg)
ThreadLocalORMSession.flush_all()
ThreadLocalORMSession.close_all()
response = self.app.get('/Wiki/TEST/')
assert 'Related Pages' in response
assert 'aaa' in response
assert 'bbb' in response