allura
Revisão | e764e2aefccdb3207ed3f6fcd5240aff1021d4a9 (tree) |
---|---|
Hora | 2012-04-17 01:23:23 |
Autor | Artem Dudarev for 42cc <dudarev+42cc@gmai...> |
Commiter | Dave Brondsema |
ticket:12 tests for wiki macro for project sorting
@@ -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) |