Show More
@@ -1,115 +1,116 | |||
|
1 | from __future__ import with_statement | |
|
1 | 2 | import os |
|
2 | 3 | import csv |
|
3 | 4 | import datetime |
|
4 | 5 | from rhodecode.tests import * |
|
5 | 6 | from rhodecode.model.db import UserLog |
|
6 | 7 | from rhodecode.model.meta import Session |
|
7 | 8 | from rhodecode.lib.utils2 import safe_unicode |
|
8 | 9 | |
|
9 | 10 | dn = os.path.dirname |
|
10 | 11 | FIXTURES = os.path.join(dn(dn(os.path.abspath(__file__))), 'fixtures') |
|
11 | 12 | |
|
12 | 13 | |
|
13 | 14 | class TestAdminController(TestController): |
|
14 | 15 | |
|
15 | 16 | @classmethod |
|
16 | 17 | def setup_class(cls): |
|
17 | 18 | UserLog.query().delete() |
|
18 | 19 | Session().commit() |
|
19 | 20 | with open(os.path.join(FIXTURES, 'journal_dump.csv')) as f: |
|
20 | 21 | for row in csv.DictReader(f): |
|
21 | 22 | ul = UserLog() |
|
22 | 23 | for k, v in row.iteritems(): |
|
23 | 24 | v = safe_unicode(v) |
|
24 | 25 | if k == 'action_date': |
|
25 | 26 | v = datetime.datetime.strptime(v, '%Y-%m-%d %H:%M:%S.%f') |
|
26 | 27 | setattr(ul, k, v) |
|
27 | 28 | Session().add(ul) |
|
28 | 29 | Session().commit() |
|
29 | 30 | |
|
30 | 31 | @classmethod |
|
31 | 32 | def teardown_class(cls): |
|
32 | 33 | UserLog.query().delete() |
|
33 | 34 | Session().commit() |
|
34 | 35 | |
|
35 | 36 | def test_index(self): |
|
36 | 37 | self.log_user() |
|
37 | 38 | response = self.app.get(url(controller='admin/admin', action='index')) |
|
38 | 39 | response.mustcontain('Admin journal') |
|
39 | 40 | |
|
40 | 41 | def test_filter_all_entries(self): |
|
41 | 42 | self.log_user() |
|
42 | 43 | response = self.app.get(url(controller='admin/admin', action='index',)) |
|
43 | 44 | response.mustcontain('2034 entries') |
|
44 | 45 | |
|
45 | 46 | def test_filter_journal_filter_exact_match_on_repository(self): |
|
46 | 47 | self.log_user() |
|
47 | 48 | response = self.app.get(url(controller='admin/admin', action='index', |
|
48 | 49 | filter='repository:rhodecode')) |
|
49 | 50 | response.mustcontain('3 entries') |
|
50 | 51 | |
|
51 | 52 | def test_filter_journal_filter_wildcard_on_repository(self): |
|
52 | 53 | self.log_user() |
|
53 | 54 | response = self.app.get(url(controller='admin/admin', action='index', |
|
54 | 55 | filter='repository:*test*')) |
|
55 | 56 | response.mustcontain('862 entries') |
|
56 | 57 | |
|
57 | 58 | def test_filter_journal_filter_prefix_on_repository(self): |
|
58 | 59 | self.log_user() |
|
59 | 60 | response = self.app.get(url(controller='admin/admin', action='index', |
|
60 | 61 | filter='repository:test*')) |
|
61 | 62 | response.mustcontain('257 entries') |
|
62 | 63 | |
|
63 | 64 | def test_filter_journal_filter_prefix_on_repository_and_user(self): |
|
64 | 65 | self.log_user() |
|
65 | 66 | response = self.app.get(url(controller='admin/admin', action='index', |
|
66 | 67 | filter='repository:test* AND username:demo')) |
|
67 | 68 | response.mustcontain('130 entries') |
|
68 | 69 | |
|
69 | 70 | def test_filter_journal_filter_prefix_on_repository_or_other_repo(self): |
|
70 | 71 | self.log_user() |
|
71 | 72 | response = self.app.get(url(controller='admin/admin', action='index', |
|
72 | 73 | filter='repository:test* OR repository:rhodecode')) |
|
73 | 74 | response.mustcontain('260 entries') # 257 + 3 |
|
74 | 75 | |
|
75 | 76 | def test_filter_journal_filter_exact_match_on_username(self): |
|
76 | 77 | self.log_user() |
|
77 | 78 | response = self.app.get(url(controller='admin/admin', action='index', |
|
78 | 79 | filter='username:demo')) |
|
79 | 80 | response.mustcontain('1087 entries') |
|
80 | 81 | |
|
81 | 82 | def test_filter_journal_filter_wildcard_on_username(self): |
|
82 | 83 | self.log_user() |
|
83 | 84 | response = self.app.get(url(controller='admin/admin', action='index', |
|
84 | 85 | filter='username:*test*')) |
|
85 | 86 | response.mustcontain('100 entries') |
|
86 | 87 | |
|
87 | 88 | def test_filter_journal_filter_prefix_on_username(self): |
|
88 | 89 | self.log_user() |
|
89 | 90 | response = self.app.get(url(controller='admin/admin', action='index', |
|
90 | 91 | filter='username:demo*')) |
|
91 | 92 | response.mustcontain('1101 entries') |
|
92 | 93 | |
|
93 | 94 | def test_filter_journal_filter_prefix_on_user_or_other_user(self): |
|
94 | 95 | self.log_user() |
|
95 | 96 | response = self.app.get(url(controller='admin/admin', action='index', |
|
96 | 97 | filter='username:demo OR username:volcan')) |
|
97 | 98 | response.mustcontain('1095 entries') # 1087 + 8 |
|
98 | 99 | |
|
99 | 100 | def test_filter_journal_filter_wildcard_on_action(self): |
|
100 | 101 | self.log_user() |
|
101 | 102 | response = self.app.get(url(controller='admin/admin', action='index', |
|
102 | 103 | filter='action:*pull_request*')) |
|
103 | 104 | response.mustcontain('187 entries') |
|
104 | 105 | |
|
105 | 106 | def test_filter_journal_filter_on_date(self): |
|
106 | 107 | self.log_user() |
|
107 | 108 | response = self.app.get(url(controller='admin/admin', action='index', |
|
108 | 109 | filter='date:20121010')) |
|
109 | 110 | response.mustcontain('47 entries') |
|
110 | 111 | |
|
111 | 112 | def test_filter_journal_filter_on_date_2(self): |
|
112 | 113 | self.log_user() |
|
113 | 114 | response = self.app.get(url(controller='admin/admin', action='index', |
|
114 | 115 | filter='date:20121020')) |
|
115 | 116 | response.mustcontain('17 entries') No newline at end of file |
General Comments 0
You need to be logged in to leave comments.
Login now