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