bug 455369 - Pushlog date parsing screws up on trailing space
authorTed Mielczarek <ted.mielczarek@gmail.com>
Fri, 21 Nov 2008 07:46:39 -0500
changeset 48 485bf1de78f969a2db4d22dd908deaf0da7a6dfd
parent 47 c61d975cece260152cbfcb39b1b48e28bba70ce8
child 49 802d27b80d5952bdaadd427fced12438d5bf56e0
push id22
push usertmielczarek@mozilla.com
push dateFri, 21 Nov 2008 12:46:55 +0000
bugs455369
bug 455369 - Pushlog date parsing screws up on trailing space
pushlog-feed.py
runtests.py
--- a/pushlog-feed.py
+++ b/pushlog-feed.py
@@ -96,16 +96,17 @@ def gettotalpushlogentries(conn):
 def localdate(ts):
     t = time.localtime(ts)
     offset = time.timezone
     if t[8] == 1:
         offset = time.altzone
     return (ts, offset)
 
 def doParseDate(datestring):
+    datestring = datestring.strip()
     try:
         date = time.strptime(datestring, "%Y-%m-%d %H:%M:%S")
     except ValueError:
         date, x = cal.parse(datestring)
     return time.mktime(date)
 
 def pushlogSetup(web, req):
     repo = web.repo
--- a/runtests.py
+++ b/runtests.py
@@ -52,18 +52,18 @@ class TestPushlog(unittest.TestCase):
         write_hgrc(repodir)
         ensure_templates()
         # read our expected json data
         f = file(os.path.join(mydir, "testdata/test-repo-data.json"))
         self.expectedjson = simplejson.loads(''.join(f.readlines()))
         f.close()
         # now run hg serve on it
         self.hgwebprocess = Popen(["hg", "-R", repodir, "serve"], stdout=devnull, stderr=STDOUT)
-        # give it a few seconds to be ready
-        sleep(2)
+        # give it a second to be ready
+        sleep(1)
         os.environ['TZ'] = "America/New_York"
 
     def tearDown(self):
         # kill hgweb process
         if self.hgwebprocess is not None:
             os.kill(self.hgwebprocess.pid, SIGTERM)
             self.hgwebprocess = None
 
@@ -132,10 +132,16 @@ class TestPushlog(unittest.TestCase):
         self.assertEqualFeeds(testfeed, expectedfeed)
 
     def testchangesetquerytipsonlyatom(self):
         """Get some tipsonly ATOM data via pushlog changeset query."""
         testfeed = feedparser.parse("http://localhost:8000/pushlog?fromchange=4ccee53e18ac&tochange=a79451771352&tipsonly=1")
         expectedfeed = feedparser.parse(os.path.join(mydir, "testdata/test-repo-changeset-query-tipsonly-data.xml"))
         self.assertEqualFeeds(testfeed, expectedfeed)
 
+    def testdatequerytrailingspaceatom(self):
+        """Dates with leading/trailing spaces should work properly."""
+        testfeed = feedparser.parse("http://localhost:8000/pushlog?startdate=%202008-11-20%2010:52:25%20&enddate=%202008-11-20%2010:53:25%20&foo=bar")
+        expectedfeed = feedparser.parse(os.path.join(mydir, "testdata/test-repo-date-query-data.xml"))
+        self.assertEqualFeeds(testfeed, expectedfeed)
+
 if __name__ == '__main__':
     unittest.main()