]> git.decadent.org.uk Git - dak.git/blobdiff - tests/db_test.py
Merge remote-tracking branch 'jcristau/formatone-no-tar-sig'
[dak.git] / tests / db_test.py
index f91c15a82b783a7963a1ad51023b00b7eb767be2..9ae23017be550ce74ee0bdfc0f36c2d034375ff0 100644 (file)
@@ -101,8 +101,8 @@ class DBDakTestCase(DakTestCase):
         if 'comp' in self.__dict__:
             return
         self.comp = {}
-        self.comp['main'] = Component(component_name = 'main')
-        self.comp['contrib'] = Component(component_name = 'contrib')
+        for name in ('main', 'contrib', 'non-free'):
+            self.comp[name] = Component(component_name = name)
         self.session.add_all(self.comp.values())
 
     def setup_locations(self):
@@ -113,11 +113,9 @@ class DBDakTestCase(DakTestCase):
         self.setup_components()
         self.loc = {}
         self.loc['main'] = Location( \
-            path = '/srv/ftp-master.debian.org/ftp/pool/', \
-            component = self.comp['main'])
+            path = fixture('ftp/pool/'), component = self.comp['main'])
         self.loc['contrib'] = Location( \
-            path = '/srv/ftp-master.debian.org/ftp/pool/', \
-            component = self.comp['contrib'])
+            path = fixture('ftp/pool/'), component = self.comp['contrib'])
         self.session.add_all(self.loc.values())
 
     def setup_poolfiles(self):
@@ -171,6 +169,7 @@ class DBDakTestCase(DakTestCase):
 
         if 'source' in self.__dict__:
             return
+        install_date = self.now()
         self.setup_maintainers()
         self.setup_suites()
         self.setup_poolfiles()
@@ -178,22 +177,22 @@ class DBDakTestCase(DakTestCase):
         self.source['hello_2.2-2'] = DBSource(source = 'hello', version = '2.2-2', \
             maintainer = self.maintainer['maintainer'], \
             changedby = self.maintainer['uploader'], \
-            poolfile = self.file['hello_2.2-2.dsc'], install_date = self.now())
+            poolfile = self.file['hello_2.2-2.dsc'], install_date = install_date)
         self.source['hello_2.2-2'].suites.append(self.suite['sid'])
         self.source['hello_2.2-1'] = DBSource(source = 'hello', version = '2.2-1', \
             maintainer = self.maintainer['maintainer'], \
             changedby = self.maintainer['uploader'], \
-            poolfile = self.file['hello_2.2-1.dsc'], install_date = self.now())
+            poolfile = self.file['hello_2.2-1.dsc'], install_date = install_date)
         self.source['hello_2.2-1'].suites.append(self.suite['sid'])
         self.source['gnome-hello_3.0-1'] = DBSource(source = 'gnome-hello', \
             version = '3.0-1', maintainer = self.maintainer['maintainer'], \
             changedby = self.maintainer['uploader'], \
-            poolfile = self.file['gnome-hello_3.0-1.dsc'], install_date = self.now())
+            poolfile = self.file['gnome-hello_3.0-1.dsc'], install_date = install_date)
         self.source['gnome-hello_3.0-1'].suites.append(self.suite['sid'])
         self.source['sl_3.03-16'] = DBSource(source = 'sl', version = '3.03-16', \
             maintainer = self.maintainer['maintainer'], \
             changedby = self.maintainer['uploader'], \
-            poolfile = self.file['sl_3.03-16.dsc'], install_date = self.now())
+            poolfile = self.file['sl_3.03-16.dsc'], install_date = install_date)
         self.source['sl_3.03-16'].suites.append(self.suite['squeeze'])
         self.source['sl_3.03-16'].suites.append(self.suite['sid'])
         self.session.add_all(self.source.values())
@@ -234,19 +233,81 @@ class DBDakTestCase(DakTestCase):
         self.binary['python-hello_2.2-1_i386'].suites.append(self.suite['squeeze'])
         self.session.add_all(self.binary.values())
 
+    def setup_overridetypes(self):
+        '''
+        Setup self.otype of class OverrideType.
+        '''
+        if 'otype' in self.__dict__:
+            return
+        self.otype = {}
+        for type_ in ('deb', 'udeb'):
+            self.otype[type_] = OverrideType(overridetype = type_)
+        self.session.add_all(self.otype.values())
+        self.session.flush()
+
+    def setup_sections(self):
+        '''
+        Setup self.section of class Section.
+        '''
+        if 'section' in self.__dict__:
+            return
+        self.section = {}
+        self.section['python'] = Section(section = 'python')
+        self.session.add_all(self.section.values())
+        self.session.flush()
+
+    def setup_priorities(self):
+        '''
+        Setup self.prio of class Priority.
+        '''
+        if 'prio' in self.__dict__:
+            return
+        self.prio = {}
+        self.prio['standard'] = Priority(priority = 'standard', level = 7)
+        self.session.add_all(self.prio.values())
+        self.session.flush()
+
+    def setup_overrides(self):
+        '''
+        Setup self.override of class Override.
+        '''
+        if 'override' in self.__dict__:
+            return
+        self.setup_suites()
+        self.setup_components()
+        self.setup_overridetypes()
+        self.setup_sections()
+        self.setup_priorities()
+        self.override = {}
+        self.override['hello_sid_main_udeb'] = Override(package = 'hello', \
+            suite = self.suite['sid'], component = self.comp['main'], \
+            overridetype = self.otype['udeb'], \
+            section = self.section['python'], priority = self.prio['standard'])
+        self.override['hello_squeeze_main_deb'] = Override(package = 'hello', \
+            suite = self.suite['squeeze'], component = self.comp['main'], \
+            overridetype = self.otype['deb'], \
+            section = self.section['python'], priority = self.prio['standard'])
+        self.override['hello_lenny_contrib_deb'] = Override(package = 'hello', \
+            suite = self.suite['lenny'], component = self.comp['contrib'], \
+            overridetype = self.otype['deb'], \
+            section = self.section['python'], priority = self.prio['standard'])
+        self.session.add_all(self.override.values())
+        self.session.flush()
+
     def setUp(self):
         if self.metadata is None:
             self.initialize()
         self.session = DBConn().session()
 
     def now(self):
-        "returns the current time at the db server"
+        """
+        Returns the current time at the db server. Please note the function
+        returns the same value as long as it is in the same transaction. You
+        should self.session.rollback() (or commit) if you rely on getting a
+        fresh timestamp.
+        """
 
-        # 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
+        return self.session.query(func.now()).scalar()
 
     def classes_to_clean(self):
         """
@@ -259,7 +320,8 @@ class DBDakTestCase(DakTestCase):
     def tearDown(self):
         self.session.rollback()
         for class_ in self.classes_to_clean():
-            self.session.query(class_).delete()
+            for object_ in self.session.query(class_):
+                self.session.delete(object_)
         self.session.commit()
         # usually there is no need to drop all tables here
         #self.metadata.drop_all()