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