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