changeset 16:aa2e7f3731c1

test suite now uses a test db instead of a fake one
author Atul Varma <varmaa@toolness.com>
date Wed, 23 Dec 2009 21:25:29 -0800
parents 07974aeffefe
children 5e68520b8d1f
files test.py
diffstat 1 files changed, 19 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/test.py	Wed Dec 23 21:06:31 2009 -0800
+++ b/test.py	Wed Dec 23 21:25:29 2009 -0800
@@ -3,6 +3,7 @@
 import copy
 
 import simplejson as json
+import pymongo
 import bzapi
 
 FAKE_CONFIG = {'product': {}}
@@ -42,14 +43,10 @@
     def urlopen(self, request):
         return StringIO.StringIO(self._responses[request.url])
 
-class FakeCollection(object):
-    def find_one(self, *args, **kwargs):
-        return None
+connection = pymongo.Connection('localhost', 27017)
+testdb = connection.bzapi_testing_db
 
-    def insert(self, obj):
-        pass
-
-class Tests(unittest.TestCase):
+class TimestampTests(unittest.TestCase):
     def test_datetime_from_iso(self):
         date = bzapi.datetime_from_iso('2009-06-11T22:31:24Z')
         self.assertEqual(str(date), '2009-06-11 22:31:24')
@@ -58,6 +55,7 @@
         date = bzapi.datetime_from_rfc1123('Wed, 23 Dec 2009 20:42:59 GMT')
         self.assertEqual(str(date), '2009-12-23 20:42:59')
 
+class OpenUrlTests(unittest.TestCase):
     def test_open_url_works_without_query_args(self):
         urllib2 = FakeUrllib2()
         urllib2.set_url('http://foo/', 'boo')
@@ -79,11 +77,24 @@
             'meh'
             )
 
+class ApiTests(unittest.TestCase):
+    _collections = ['api', 'bugs']
+
+    def _reset_collections(self):
+        for name in self._collections:
+            testdb[name].remove({})
+
+    def setUp(self):
+        self._reset_collections()
+
+    def tearDown(self):
+        self._reset_collections()
+
     def _get_basic_fake_api(self, config=FAKE_CONFIG, **kwargs):
         opener = FakeOpenUrl()
         opener.set('http://foo/latest/configuration', kwargs,
                    config)
-        api = bzapi.BugzillaApi('http://foo/latest', FakeCollection(),
+        api = bzapi.BugzillaApi('http://foo/latest', testdb.api,
                                 open_url=opener, **kwargs)
         return api