Parent: [ce18b1] (diff)

Child: [9a53c0] (diff)

Download this file

test_wiki_macro.py    137 lines (122 with data), 6.2 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
from ming.orm.ormsession import ThreadLocalORMSession
from allura import model as M
from allura.tests import TestController
from allura.tests import decorators as td
class TestWikiMacro(TestController):
@staticmethod
def get_project_names(r):
"""
Extracts a list of project names from a wiki page HTML.
"""
# projects short names are in h2 elements without any attributes
# there is one more h2 element, but it has `class` attribute
return [e.text for e in r.html.findAll('h2') if not e.attrs]
@staticmethod
def get_projects_property_in_the_same_order(names, prop):
"""
Returns a list of projects properties `prop` in the same order as
project `names`.
It is required because results of the query are not in the same order as names.
"""
projects = M.Project.query.find(dict(name={'$in': names})).all()
projects_dict = dict([(p['name'],p[prop]) for p in projects])
return [projects_dict[name] for name in names]
@td.with_wiki
def test_sort_alpha(self):
r = self.app.post('/p/wiki/Home/update',
params={
'title': 'Home',
'text': '[[projects sort=alpha]]'
},
extra_environ=dict(username='root'), upload_files=[]).follow()
project_list = self.get_project_names(r)
assert project_list == sorted(project_list)
@td.with_wiki
def test_sort_registered(self):
r = self.app.post('/p/wiki/Home/update',
params={
'title': 'Home',
'text': '[[projects sort=last_registred]]'
},
extra_environ=dict(username='root'), upload_files=[]).follow()
project_names = self.get_project_names(r)
ids = self.get_projects_property_in_the_same_order(project_names, '_id')
assert ids == sorted(ids, reverse=True)
@td.with_wiki
def test_sort_updated(self):
r = self.app.post('/p/wiki/Home/update',
params={
'title': 'Home',
'text': '[[projects sort=last_updated]]'
},
extra_environ=dict(username='root'), upload_files=[]).follow()
project_names = self.get_project_names(r)
updated_at = self.get_projects_property_in_the_same_order(project_names, 'last_updated')
assert updated_at == sorted(updated_at, reverse=True)
@td.with_wiki
def test_filtering(self):
# set up for test
from random import choice
trove_count = M.TroveCategory.query.find().count()
random_trove = M.TroveCategory.query.get(trove_cat_id=choice(range(trove_count)) + 1)
test_project = M.Project.query.get(name='test')
test_project_troves = getattr(test_project, 'trove_' + random_trove.type)
test_project_troves.append(random_trove._id)
ThreadLocalORMSession.flush_all()
# test itself
r = self.app.post('/p/wiki/Home/update',
params={
'title': 'Home',
'text': '[[projects category="' + random_trove.fullpath + '"]]'
},
extra_environ=dict(username='root'), upload_files=[]).follow()
project_names = self.get_project_names(r)
assert [test_project.name, ] == project_names
@td.with_wiki
def test_projects_makro(self):
# test columns
two_column_style = 'width: 330px;'
r = self.app.post('/p/wiki/Home/update',
params={
'title': 'Home',
'text': '[[projects display_mode=list columns=2]]'
},
extra_environ=dict(username='root'), upload_files=[]).follow()
assert two_column_style in r
r = self.app.post('/p/wiki/Home/update',
params={
'title': 'Home',
'text': '[[projects display_mode=list columns=3]]'
},
extra_environ=dict(username='root'), upload_files=[]).follow()
assert two_column_style not in r
# test project icon
r = self.app.post('/p/wiki/Home/update',
params={
'title': 'Home',
'text': '[[projects display_mode=list show_proj_icon=on]]'
},
extra_environ=dict(username='root'), upload_files=[]).follow()
assert 'test Logo' in r
r = self.app.post('/p/wiki/Home/update',
params={
'title': 'Home',
'text': '[[projects display_mode=list show_proj_icon=off]]'
},
extra_environ=dict(username='root'), upload_files=[]).follow()
assert 'test Logo' not in r
# test project download button
r = self.app.post('/p/wiki/Home/update',
params={
'title': 'Home',
'text': '[[projects display_mode=list show_download_button=on]]'
},
extra_environ=dict(username='root'), upload_files=[]).follow()
assert 'download-button' in r
r = self.app.post('/p/wiki/Home/update',
params={
'title': 'Home',
'text': '[[projects display_mode=list show_download_button=off]]'
},
extra_environ=dict(username='root'), upload_files=[]).follow()
assert 'download-button' not in r