• R/O
  • HTTP
  • SSH
  • HTTPS

提交

標籤
無標籤

Frequently used words (click to add to your profile)

javac++androidlinuxc#objective-cqt誰得cocoawindowspythonphprubygameguibathyscaphec翻訳omegat計画中(planning stage)frameworktwittertestdombtronvb.netdirectxarduinopreviewerゲームエンジン

allura


Commit MetaInfo

修訂6ccf2baf28186cdc6d2df1c9f13e6889905d04b7 (tree)
時間2012-03-24 05:40:16
作者Yaroslav Luzin <jardev@gmai...>
CommiterYaroslav Luzin

Log Message

Merge branch 't12_macro_project_sorting'

Change Summary

差異

--- a/Allura/allura/lib/macro.py
+++ b/Allura/allura/lib/macro.py
@@ -164,6 +164,10 @@ def projects(category=None, display_mode='grid', sort='last_updated',
164164 sort_key, sort_dir = 'name', pymongo.ASCENDING
165165 elif sort == 'random':
166166 sort_key, sort_dir = None, None
167+ elif sort == 'last_registred':
168+ sort_key, sort_dir = '_id', pymongo.DESCENDING
169+ elif sort == '_id':
170+ sort_key, sort_dir = '_id', pymongo.DESCENDING
167171
168172 projects = []
169173 if private:
--- /dev/null
+++ b/Allura/allura/tests/functional/test_wiki_macro.py
@@ -0,0 +1,60 @@
1+from allura import model as M
2+from allura.tests import TestController
3+from allura.tests import decorators as td
4+
5+class TestNeighborhood(TestController):
6+
7+ @staticmethod
8+ def get_project_names(r):
9+ """
10+ Extracts a list of project names from a wiki page HTML.
11+ """
12+ # projects short names are in h2 elements without any attributes
13+ # there is one more h2 element, but it has `class` attribute
14+ return [e.text for e in r.html.findAll('h2') if not e.attrs]
15+
16+ @staticmethod
17+ def get_projects_property_in_the_same_order(names, prop):
18+ """
19+ Returns a list of projects properties `prop` in the same order as
20+ project `names`.
21+ It is required because results of the query are not in the same order as names.
22+ """
23+ projects = M.Project.query.find(dict(name={'$in': names})).all()
24+ projects_dict = dict([(p['name'],p[prop]) for p in projects])
25+ return [projects_dict[name] for name in names]
26+
27+ @td.with_wiki
28+ def test_sort_alpha(self):
29+ r = self.app.post('/p/wiki/Home/update',
30+ params={
31+ 'title': 'Home',
32+ 'text': '[[projects sort=alpha]]'
33+ },
34+ extra_environ=dict(username='root'), upload_files=[]).follow()
35+ project_list = self.get_project_names(r)
36+ assert project_list == sorted(project_list)
37+
38+ @td.with_wiki
39+ def test_sort_registered(self):
40+ r = self.app.post('/p/wiki/Home/update',
41+ params={
42+ 'title': 'Home',
43+ 'text': '[[projects sort=last_registred]]'
44+ },
45+ extra_environ=dict(username='root'), upload_files=[]).follow()
46+ project_names = self.get_project_names(r)
47+ ids = self.get_projects_property_in_the_same_order(project_names, '_id')
48+ assert ids == sorted(ids, reverse=True)
49+
50+ @td.with_wiki
51+ def test_sort_updated(self):
52+ r = self.app.post('/p/wiki/Home/update',
53+ params={
54+ 'title': 'Home',
55+ 'text': '[[projects sort=last_updated]]'
56+ },
57+ extra_environ=dict(username='root'), upload_files=[]).follow()
58+ project_names = self.get_project_names(r)
59+ updated_at = self.get_projects_property_in_the_same_order(project_names, 'last_updated')
60+ assert updated_at == sorted(updated_at, reverse=True)