##// END OF EJS Templates
python2.5 safe parsing of datetime string with microseconds
marcink -
r3074:09cef303 beta
parent child Browse files
Show More
@@ -17,13 +17,26 b' class TestAdminController(TestController'
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 = datetime.datetime.strptime(v, '%Y-%m-%d %H:%M:%S.%f')
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
@@ -134,4 +147,4 b' class TestAdminController(TestController'
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