add some more tests
authorTed Mielczarek <ted.mielczarek@gmail.com>
Fri, 21 Nov 2008 10:47:02 -0500
changeset 51 ecae764132773e8e983cc6fb09f9cf0c63b16945
parent 50 3b7407f0c22c06dce5c9da3bf5397450a1fe5eed
child 52 1ecaabab0765c903b50cce67f5356d12a326a909
push id25
push usertmielczarek@mozilla.com
push dateFri, 21 Nov 2008 15:47:06 +0000
add some more tests
runtests.py
testdata/test-repo-fromchange-enddate-query.json
testdata/test-repo-fromchange-endid-query.json
testdata/test-repo-startdate-endid-query.json
testdata/test-repo-startdate-tochange-query.json
testdata/test-repo-startid-enddate-query.json
testdata/test-repo-startid-tochange-query.json
--- a/runtests.py
+++ b/runtests.py
@@ -63,55 +63,65 @@ class TestEmptyRepo(unittest.TestCase):
         conn = HTTPConnection("localhost", 8000)
         conn.request("GET", "/pushlog")
         r = conn.getresponse()
         conn.close()
         self.assertEqual(r.status, 200, "empty pushlog should not error (got HTTP status %d, expected 200)" % r.status)
 
 class TestPushlog(unittest.TestCase):
     hgwebprocess = None
+    repodir = ''
 
-    repodir = ''
     def setUp(self):
         "Untar the test repo and add the pushlog extension to it."
         # unpack the test repo
         repoarchive = os.path.join(mydir, "testdata/test-repo.tar.bz2")
         repodir = "/tmp/hg-test/"
         self.repodir = repodir
         check_call(["rm", "-rf", repodir])
         check_call(["tar", "xjf", repoarchive], cwd="/tmp")
         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 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
 
+    def loadjsonurl(self, url):
+        """Load JSON from a URL into an object."""
+        u = urlopen(url)
+        j = simplejson.loads(''.join(u.readlines()))
+        u.close()
+        return j
+
+    def loadjsonfile(self, f):
+        """Given a file path relative to the srcdir, load the file as a JSON object."""
+        f = file(os.path.join(mydir, f))
+        j = simplejson.loads(''.join(f.readlines()))
+        f.close()
+        return j
+        
     def testalljsonpushes(self):
         """Get all json data from json-pushes."""
-        u = urlopen("http://localhost:8000/json-pushes?startID=0")
-        j = simplejson.loads(''.join(u.readlines()))
-        u.close()
-        self.assertEqual(j, self.expectedjson, "json-pushes did not yield expected json data!")
+        testjson = self.loadjsonurl("http://localhost:8000/json-pushes?startID=0")
+        expectedjson = self.loadjsonfile("testdata/test-repo-data.json")
+        self.assertEqual(testjson, expectedjson, "json-pushes did not yield expected json data!")
 
     def testprintpushlog(self):
         """Get all json data via 'hg printpushlog'."""
-        j = simplejson.loads(Popen(["hg", "-R", self.repodir, "printpushlog"], stdout=PIPE).communicate()[0])
-        self.assertEqual(j, self.expectedjson, "printpushlog did not yield expected json data!")
+        testjson = simplejson.loads(Popen(["hg", "-R", self.repodir, "printpushlog"], stdout=PIPE).communicate()[0])
+        expectedjson = self.loadjsonfile("testdata/test-repo-data.json")
+        self.assertEqual(testjson, expectedjson, "printpushlog did not yield expected json data!")
 
     def assertEqualFeeds(self, a, b):
         self.assertEqual(a.feed.title, b.feed.title, "not the same title, %s != %s" % (a.feed.title, b.feed.title))
         self.assertEqual(a.feed.updated, b.feed.updated, "not the same updated time, %s != %s" % (a.feed.updated, b.feed.updated))
         self.assertEqual(len(a.entries), len(b.entries), "not the same number of entries, %d != %d" % (len(a.entries), len(b.entries)))
         for ae, be in zip(a.entries, b.entries):
             self.assertEqual(ae.updated, be.updated, "not the same updated time, %s != %s" % (ae.updated, be.updated))
             self.assertEqual(ae.title, be.title, "not the same title, %s != %s" % (ae.title, be.title))
@@ -167,10 +177,46 @@ class TestPushlog(unittest.TestCase):
         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)
 
+    def teststartidtoenddatequery(self):
+        """Query with a startID and an enddate."""
+        testjson = self.loadjsonurl("http://localhost:8000/json-pushes?startID=5&enddate=2008-11-20%2010:53:25")
+        expectedjson = self.loadjsonfile("testdata/test-repo-startid-enddate-query.json")
+        self.assertEqual(testjson, expectedjson, "json-pushes did not yield expected json data!")
+
+    def teststartdatetoendidquery(self):
+        """Query with a startdate and an endID."""
+        testjson = self.loadjsonurl("http://localhost:8000/json-pushes?startdate=2008-11-20%2010:52:25&endID=15")
+        expectedjson = self.loadjsonfile("testdata/test-repo-startdate-endid-query.json")
+        self.assertEqual(testjson, expectedjson, "json-pushes did not yield expected json data!")
+
+    def testfromchangetoendidquery(self):
+        """Query with fromchange and an endID."""
+        testjson = self.loadjsonurl("http://localhost:8000/json-pushes?fromchange=cc07cc0e87f8&endID=15")
+        expectedjson = self.loadjsonfile("testdata/test-repo-fromchange-endid-query.json")
+        self.assertEqual(testjson, expectedjson, "json-pushes did not yield expected json data!")
+
+    def teststartidtochangequery(self):
+        """Query with a startID and tochange."""
+        testjson = self.loadjsonurl("http://localhost:8000/json-pushes?startID=5&tochange=af5fb85d9324")
+        expectedjson = self.loadjsonfile("testdata/test-repo-startid-tochange-query.json")
+        self.assertEqual(testjson, expectedjson, "json-pushes did not yield expected json data!")
+
+    def testfromchangetoenddatequery(self):
+        """Query with fromchange and an enddate."""
+        testjson = self.loadjsonurl("http://localhost:8000/json-pushes?fromchange=cc07cc0e87f8&enddate=2008-11-20%2010:52:56")
+        expectedjson = self.loadjsonfile("testdata/test-repo-fromchange-enddate-query.json")
+        self.assertEqual(testjson, expectedjson, "json-pushes did not yield expected json data!")
+
+    def teststartdatetochangequery(self):
+        """Query with a startdate and tochange."""
+        testjson = self.loadjsonurl("http://localhost:8000/json-pushes?startdate=2008-11-20%2010:52:25&tochange=af5fb85d9324")
+        expectedjson = self.loadjsonfile("testdata/test-repo-startdate-tochange-query.json")
+        self.assertEqual(testjson, expectedjson, "json-pushes did not yield expected json data!")
+
 if __name__ == '__main__':
     unittest.main()
new file mode 100644
--- /dev/null
+++ b/testdata/test-repo-fromchange-enddate-query.json
@@ -0,0 +1,1 @@
+{}
\ No newline at end of file
new file mode 100644
--- /dev/null
+++ b/testdata/test-repo-fromchange-endid-query.json
@@ -0,0 +1,26 @@
+{
+ "13": {
+  "date": 1227196380, 
+  "changesets": [
+   "7d6c2c9744fe87b74aa6adce043c597dbdbb53b5", 
+   "4ccee53e18ac923ff9ac995805748167128327a9"
+  ], 
+  "user": "luser"
+ }, 
+ "14": {
+  "date": 1227196385, 
+  "changesets": [
+   "db80b071182be2384ba703f77a135a637e9a184a", 
+   "853ae4aff7ec183c47f8b9b08faff9f8f4083855"
+  ], 
+  "user": "luser"
+ }, 
+ "15": {
+  "date": 1227196390, 
+  "changesets": [
+   "41720e1fcc1c24ffd16cd988b5d8fbbe1fe23c90", 
+   "af5fb85d93246318a4050c4def448cbcfd068e57"
+  ], 
+  "user": "luser"
+ }
+}
\ No newline at end of file
new file mode 100644
--- /dev/null
+++ b/testdata/test-repo-startdate-endid-query.json
@@ -0,0 +1,74 @@
+{
+ "7": {
+  "date": 1227196348, 
+  "changesets": [
+   "2d6b2af9c95bc8884d9555aba5e4f4a843f3550b", 
+   "1ab7868c33f5a8db756bfaaa4fef148af7a983e3"
+  ], 
+  "user": "luser"
+ }, 
+ "8": {
+  "date": 1227196353, 
+  "changesets": [
+   "01ffeda797534f3045ad1cd941fddc3b775d8335", 
+   "82883a615a97e9d5bd2083787fba2589dcfb4d7f"
+  ], 
+  "user": "luser"
+ }, 
+ "9": {
+  "date": 1227196359, 
+  "changesets": [
+   "14f8472e2d04432be45987fe3ac2d3440b11264d", 
+   "d091969e89a9581fd89f7ed0afce10aaaa0c24bf"
+  ], 
+  "user": "luser"
+ }, 
+ "10": {
+  "date": 1227196364, 
+  "changesets": [
+   "ccf92322df622434a5b74cdecb52f5c01e7b4386", 
+   "a19f3496dc6d46e9b22bda92676bb20bacd3124a"
+  ], 
+  "user": "luser"
+ }, 
+ "11": {
+  "date": 1227196369, 
+  "changesets": [
+   "d19fa6e892483a197ba0138d996ef3621828f9ea", 
+   "e9ea8b142bf4e2aa230cbd46d68ec73f45c1e080"
+  ], 
+  "user": "luser"
+ }, 
+ "12": {
+  "date": 1227196375, 
+  "changesets": [
+   "cc07cc0e87f8d80baf8242a2f27b610bc16e03a8", 
+   "7886a3f7fcba196c29bd9de0cc4d858cdc4910b9"
+  ], 
+  "user": "luser"
+ }, 
+ "13": {
+  "date": 1227196380, 
+  "changesets": [
+   "7d6c2c9744fe87b74aa6adce043c597dbdbb53b5", 
+   "4ccee53e18ac923ff9ac995805748167128327a9"
+  ], 
+  "user": "luser"
+ }, 
+ "14": {
+  "date": 1227196385, 
+  "changesets": [
+   "db80b071182be2384ba703f77a135a637e9a184a", 
+   "853ae4aff7ec183c47f8b9b08faff9f8f4083855"
+  ], 
+  "user": "luser"
+ }, 
+ "15": {
+  "date": 1227196390, 
+  "changesets": [
+   "41720e1fcc1c24ffd16cd988b5d8fbbe1fe23c90", 
+   "af5fb85d93246318a4050c4def448cbcfd068e57"
+  ], 
+  "user": "luser"
+ }
+}
\ No newline at end of file
new file mode 100644
--- /dev/null
+++ b/testdata/test-repo-startdate-tochange-query.json
@@ -0,0 +1,74 @@
+{
+ "7": {
+  "date": 1227196348, 
+  "changesets": [
+   "2d6b2af9c95bc8884d9555aba5e4f4a843f3550b", 
+   "1ab7868c33f5a8db756bfaaa4fef148af7a983e3"
+  ], 
+  "user": "luser"
+ }, 
+ "8": {
+  "date": 1227196353, 
+  "changesets": [
+   "01ffeda797534f3045ad1cd941fddc3b775d8335", 
+   "82883a615a97e9d5bd2083787fba2589dcfb4d7f"
+  ], 
+  "user": "luser"
+ }, 
+ "9": {
+  "date": 1227196359, 
+  "changesets": [
+   "14f8472e2d04432be45987fe3ac2d3440b11264d", 
+   "d091969e89a9581fd89f7ed0afce10aaaa0c24bf"
+  ], 
+  "user": "luser"
+ }, 
+ "10": {
+  "date": 1227196364, 
+  "changesets": [
+   "ccf92322df622434a5b74cdecb52f5c01e7b4386", 
+   "a19f3496dc6d46e9b22bda92676bb20bacd3124a"
+  ], 
+  "user": "luser"
+ }, 
+ "11": {
+  "date": 1227196369, 
+  "changesets": [
+   "d19fa6e892483a197ba0138d996ef3621828f9ea", 
+   "e9ea8b142bf4e2aa230cbd46d68ec73f45c1e080"
+  ], 
+  "user": "luser"
+ }, 
+ "12": {
+  "date": 1227196375, 
+  "changesets": [
+   "cc07cc0e87f8d80baf8242a2f27b610bc16e03a8", 
+   "7886a3f7fcba196c29bd9de0cc4d858cdc4910b9"
+  ], 
+  "user": "luser"
+ }, 
+ "13": {
+  "date": 1227196380, 
+  "changesets": [
+   "7d6c2c9744fe87b74aa6adce043c597dbdbb53b5", 
+   "4ccee53e18ac923ff9ac995805748167128327a9"
+  ], 
+  "user": "luser"
+ }, 
+ "14": {
+  "date": 1227196385, 
+  "changesets": [
+   "db80b071182be2384ba703f77a135a637e9a184a", 
+   "853ae4aff7ec183c47f8b9b08faff9f8f4083855"
+  ], 
+  "user": "luser"
+ }, 
+ "15": {
+  "date": 1227196390, 
+  "changesets": [
+   "41720e1fcc1c24ffd16cd988b5d8fbbe1fe23c90", 
+   "af5fb85d93246318a4050c4def448cbcfd068e57"
+  ], 
+  "user": "luser"
+ }
+}
\ No newline at end of file
new file mode 100644
--- /dev/null
+++ b/testdata/test-repo-startid-enddate-query.json
@@ -0,0 +1,98 @@
+{
+ "6": {
+  "date": 1227196343, 
+  "changesets": [
+   "784ff898cfb79d00df5fcbad75af3d64bed6c696", 
+   "5a12fe530992a84722c00ec6afa632c7fcf31093"
+  ], 
+  "user": "luser"
+ }, 
+ "7": {
+  "date": 1227196348, 
+  "changesets": [
+   "2d6b2af9c95bc8884d9555aba5e4f4a843f3550b", 
+   "1ab7868c33f5a8db756bfaaa4fef148af7a983e3"
+  ], 
+  "user": "luser"
+ }, 
+ "8": {
+  "date": 1227196353, 
+  "changesets": [
+   "01ffeda797534f3045ad1cd941fddc3b775d8335", 
+   "82883a615a97e9d5bd2083787fba2589dcfb4d7f"
+  ], 
+  "user": "luser"
+ }, 
+ "9": {
+  "date": 1227196359, 
+  "changesets": [
+   "14f8472e2d04432be45987fe3ac2d3440b11264d", 
+   "d091969e89a9581fd89f7ed0afce10aaaa0c24bf"
+  ], 
+  "user": "luser"
+ }, 
+ "10": {
+  "date": 1227196364, 
+  "changesets": [
+   "ccf92322df622434a5b74cdecb52f5c01e7b4386", 
+   "a19f3496dc6d46e9b22bda92676bb20bacd3124a"
+  ], 
+  "user": "luser"
+ }, 
+ "11": {
+  "date": 1227196369, 
+  "changesets": [
+   "d19fa6e892483a197ba0138d996ef3621828f9ea", 
+   "e9ea8b142bf4e2aa230cbd46d68ec73f45c1e080"
+  ], 
+  "user": "luser"
+ }, 
+ "12": {
+  "date": 1227196375, 
+  "changesets": [
+   "cc07cc0e87f8d80baf8242a2f27b610bc16e03a8", 
+   "7886a3f7fcba196c29bd9de0cc4d858cdc4910b9"
+  ], 
+  "user": "luser"
+ }, 
+ "13": {
+  "date": 1227196380, 
+  "changesets": [
+   "7d6c2c9744fe87b74aa6adce043c597dbdbb53b5", 
+   "4ccee53e18ac923ff9ac995805748167128327a9"
+  ], 
+  "user": "luser"
+ }, 
+ "14": {
+  "date": 1227196385, 
+  "changesets": [
+   "db80b071182be2384ba703f77a135a637e9a184a", 
+   "853ae4aff7ec183c47f8b9b08faff9f8f4083855"
+  ], 
+  "user": "luser"
+ }, 
+ "15": {
+  "date": 1227196390, 
+  "changesets": [
+   "41720e1fcc1c24ffd16cd988b5d8fbbe1fe23c90", 
+   "af5fb85d93246318a4050c4def448cbcfd068e57"
+  ], 
+  "user": "luser"
+ }, 
+ "16": {
+  "date": 1227196396, 
+  "changesets": [
+   "91826025c77c6a8e5711735adaa9766dd4eac7fc", 
+   "25f2a69ac7ac2919ef35c0b937b862fbb9e7e1f7"
+  ], 
+  "user": "luser"
+ }, 
+ "17": {
+  "date": 1227196401, 
+  "changesets": [
+   "759b21a48c09dfc221107268e84c71c32d48c84b", 
+   "6437207053fb9701290b738d720044803436ba3e"
+  ], 
+  "user": "luser"
+ }
+}
\ No newline at end of file
new file mode 100644
--- /dev/null
+++ b/testdata/test-repo-startid-tochange-query.json
@@ -0,0 +1,82 @@
+{
+ "6": {
+  "date": 1227196343, 
+  "changesets": [
+   "784ff898cfb79d00df5fcbad75af3d64bed6c696", 
+   "5a12fe530992a84722c00ec6afa632c7fcf31093"
+  ], 
+  "user": "luser"
+ }, 
+ "7": {
+  "date": 1227196348, 
+  "changesets": [
+   "2d6b2af9c95bc8884d9555aba5e4f4a843f3550b", 
+   "1ab7868c33f5a8db756bfaaa4fef148af7a983e3"
+  ], 
+  "user": "luser"
+ }, 
+ "8": {
+  "date": 1227196353, 
+  "changesets": [
+   "01ffeda797534f3045ad1cd941fddc3b775d8335", 
+   "82883a615a97e9d5bd2083787fba2589dcfb4d7f"
+  ], 
+  "user": "luser"
+ }, 
+ "9": {
+  "date": 1227196359, 
+  "changesets": [
+   "14f8472e2d04432be45987fe3ac2d3440b11264d", 
+   "d091969e89a9581fd89f7ed0afce10aaaa0c24bf"
+  ], 
+  "user": "luser"
+ }, 
+ "10": {
+  "date": 1227196364, 
+  "changesets": [
+   "ccf92322df622434a5b74cdecb52f5c01e7b4386", 
+   "a19f3496dc6d46e9b22bda92676bb20bacd3124a"
+  ], 
+  "user": "luser"
+ }, 
+ "11": {
+  "date": 1227196369, 
+  "changesets": [
+   "d19fa6e892483a197ba0138d996ef3621828f9ea", 
+   "e9ea8b142bf4e2aa230cbd46d68ec73f45c1e080"
+  ], 
+  "user": "luser"
+ }, 
+ "12": {
+  "date": 1227196375, 
+  "changesets": [
+   "cc07cc0e87f8d80baf8242a2f27b610bc16e03a8", 
+   "7886a3f7fcba196c29bd9de0cc4d858cdc4910b9"
+  ], 
+  "user": "luser"
+ }, 
+ "13": {
+  "date": 1227196380, 
+  "changesets": [
+   "7d6c2c9744fe87b74aa6adce043c597dbdbb53b5", 
+   "4ccee53e18ac923ff9ac995805748167128327a9"
+  ], 
+  "user": "luser"
+ }, 
+ "14": {
+  "date": 1227196385, 
+  "changesets": [
+   "db80b071182be2384ba703f77a135a637e9a184a", 
+   "853ae4aff7ec183c47f8b9b08faff9f8f4083855"
+  ], 
+  "user": "luser"
+ }, 
+ "15": {
+  "date": 1227196390, 
+  "changesets": [
+   "41720e1fcc1c24ffd16cd988b5d8fbbe1fe23c90", 
+   "af5fb85d93246318a4050c4def448cbcfd068e57"
+  ], 
+  "user": "luser"
+ }
+}
\ No newline at end of file