]> git.decadent.org.uk Git - dak.git/commitdiff
Improve test_maintainers().
authorTorsten Werner <twerner@debian.org>
Thu, 20 Jan 2011 19:48:38 +0000 (20:48 +0100)
committerTorsten Werner <twerner@debian.org>
Thu, 20 Jan 2011 19:48:38 +0000 (20:48 +0100)
Signed-off-by: Torsten Werner <twerner@debian.org>
daklib/dbconn.py
tests/db_test.py
tests/dbtest_packages.py
tests/dbtest_timestamps.py

index e685d9190f9bc8b2460e1f379696f05ff83efcaa..a1c282105f32960eab934e30cdfdf8eada0445e2 100755 (executable)
@@ -2074,9 +2074,14 @@ __all__.append('get_sections')
 ################################################################################
 
 class DBSource(object):
-    def __init__(self, maintainer = None, changedby = None):
+    def __init__(self, source = None, version = None, maintainer = None, \
+        changedby = None, poolfile = None, install_date = None):
+        self.source = source
+        self.version = version
         self.maintainer = maintainer
         self.changedby = changedby
+        self.poolfile = poolfile
+        self.install_date = install_date
 
     def __repr__(self):
         return '<DBSource %s (%s)>' % (self.source, self.version)
index 4f01f6d5d1583a89128a4b12c1fd41c9546fd88e..fc9ce893d61d4c25aef3f1adc269cb6c21c7dc43 100644 (file)
@@ -3,7 +3,7 @@ from base_test import DakTestCase, fixture
 from daklib.config import Config
 from daklib.dbconn import DBConn
 
-from sqlalchemy import create_engine, __version__
+from sqlalchemy import create_engine, func, __version__
 from sqlalchemy.exc import SADeprecationWarning
 from sqlalchemy.schema import DDL
 
@@ -72,6 +72,15 @@ class DBDakTestCase(DakTestCase):
             self.initialize()
         self.session = DBConn().session()
 
+    def now(self):
+        "returns the current time at the db server"
+
+        # we fetch a fresh session each time to avoid caching
+        local_session = DBConn().session()
+        current_time = local_session.query(func.now()).scalar()
+        local_session.close()
+        return current_time
+
     def classes_to_clean(self):
         """
         The function classes_to_clean() returns a list of classes. All objects
index c35123ce56c786ce5d2c7c94d7f44bb4a97ecb44..249ad81eabf4c96d7e21df93966e863ac2791c66 100755 (executable)
@@ -102,6 +102,7 @@ class PackageTestCase(DBDakTestCase):
     def setup_poolfiles(self):
         'create some PoolFile objects'
 
+        self.setup_locations()
         self.file = {}
         self.file['hello'] = PoolFile(filename = 'main/h/hello/hello_2.2-2.dsc', \
             location = self.loc['main'], filesize = 0, md5sum = '')
@@ -121,7 +122,7 @@ class PackageTestCase(DBDakTestCase):
 
         somelocation.files.append(somefile)
         '''
-        self.setup_locations()
+
         self.setup_poolfiles()
         location = self.session.query(Location)[0]
         self.assertEqual('/srv/ftp-master.debian.org/ftp/pool/', location.path)
@@ -179,8 +180,11 @@ class PackageTestCase(DBDakTestCase):
     def setup_sources(self):
         'create a DBSource object; but it cannot be stored in the DB yet'
 
-        self.source = DBSource(maintainer = self.maintainer['maintainer'],
-            changedby = self.maintainer['uploader'])
+        self.setup_poolfiles()
+        self.source = DBSource(source = 'hello', version = '2.2-2', \
+            maintainer = self.maintainer['maintainer'], \
+            changedby = self.maintainer['uploader'], \
+            poolfile = self.file['hello'], install_date = self.now())
 
     def test_maintainers(self):
         '''
@@ -200,13 +204,12 @@ class PackageTestCase(DBDakTestCase):
         self.assertEqual(lazyguy,
             self.session.query(Maintainer).get(lazyguy.maintainer_id))
         self.setup_sources()
-        #TODO: needs File and Location
-        #self.assertEqual(maintainer.maintains_sources, [self.source])
-        #self.assertEqual(maintainer.changed_sources, [])
-        #self.assertEqual(uploader.maintains_sources, [])
-        #self.assertEqual(uploader.changed_sources, [self.source])
-        #self.assertEqual(lazyguy.maintains_sources, [])
-        #self.assertEqual(lazyguy.changed_sources, [])
+        self.assertEqual(maintainer.maintains_sources, [self.source])
+        self.assertEqual(maintainer.changed_sources, [])
+        self.assertEqual(uploader.maintains_sources, [])
+        self.assertEqual(uploader.changed_sources, [self.source])
+        self.assertEqual(lazyguy.maintains_sources, [])
+        self.assertEqual(lazyguy.changed_sources, [])
 
 
 if __name__ == '__main__':
index 1a53ae8665da5c9241370165bc5136c5926533a8..8b35c63f804041f87e51e6e5a77ddc0f741f7d6d 100755 (executable)
@@ -4,7 +4,6 @@ from db_test import DBDakTestCase
 
 from daklib.dbconn import DBConn, Uid
 
-from sqlalchemy import func
 import time
 import unittest
 
@@ -16,15 +15,6 @@ class TimestampTestCase(DBDakTestCase):
     TODO: Should we check all tables?
     """
 
-    def now(self):
-        "returns the current time at the db server"
-
-        # we fetch a fresh session each time to avoid caching
-        local_session = DBConn().session()
-        current_time = local_session.query(func.now()).scalar()
-        local_session.close()
-        return current_time
-
     def sleep(self):
         time.sleep(0.001)