]> git.decadent.org.uk Git - dak.git/commitdiff
Add a test for class BinContents.
authorTorsten Werner <twerner@debian.org>
Sun, 6 Feb 2011 18:06:59 +0000 (19:06 +0100)
committerTorsten Werner <twerner@debian.org>
Sun, 6 Feb 2011 18:08:46 +0000 (19:08 +0100)
Signed-off-by: Torsten Werner <twerner@debian.org>
daklib/dbconn.py
tests/dbtest_contents.py [new file with mode: 0755]

index dc5518a9a698363b5e7411bd1fd1bc4e001f554e..14ed7faaa9ed9c8f5763294745a15f323fd28699 100755 (executable)
@@ -467,7 +467,11 @@ __all__.append('get_archive')
 ################################################################################
 
 class BinContents(ORMObject):
-    def properties(silf):
+    def __init__(self, file = None, binary = None):
+        self.file = file
+        self.binary = binary
+
+    def properties(self):
         return ['file', 'binary']
 
 __all__.append('BinContents')
diff --git a/tests/dbtest_contents.py b/tests/dbtest_contents.py
new file mode 100755 (executable)
index 0000000..d6619e7
--- /dev/null
@@ -0,0 +1,61 @@
+#!/usr/bin/env python
+
+from db_test import DBDakTestCase
+
+from daklib.dbconn import DBConn, BinContents
+
+from sqlalchemy.exc import FlushError, IntegrityError
+import unittest
+
+class ContentsTestCase(DBDakTestCase):
+    """
+    This TestCase checks the behaviour of contents generation.
+    """
+
+    def test_duplicates1(self):
+        '''
+        Test the BinContents class for duplication problems.
+        '''
+        self.setup_binaries()
+        contents1 = BinContents(file = 'usr/bin/hello', \
+            binary = self.binary['hello_2.2-1_i386'])
+        self.session.add(contents1)
+        self.session.flush()
+        # test duplicates
+        contents2 = BinContents(file = 'usr/bin/hello', \
+            binary = self.binary['hello_2.2-1_i386'])
+        self.session.add(contents2)
+        self.assertRaises(FlushError, self.session.flush)
+
+    def test_duplicates2(self):
+        '''
+        Test the BinContents class for more duplication problems.
+        '''
+        self.setup_binaries()
+        contents1 = BinContents(file = 'usr/bin/hello', \
+            binary = self.binary['hello_2.2-1_i386'])
+        self.session.add(contents1)
+        contents2 = BinContents(file = 'usr/bin/gruezi', \
+            binary = self.binary['hello_2.2-1_i386'])
+        self.session.add(contents2)
+        self.session.flush()
+        # test duplicates
+        contents2.file = 'usr/bin/hello'
+        self.assertRaises(IntegrityError, self.session.flush)
+
+    def test_duplicates3(self):
+        '''
+        Test the BinContents class even more.
+        '''
+        self.setup_binaries()
+        contents1 = BinContents(file = 'usr/bin/hello', \
+            binary = self.binary['hello_2.2-1_i386'])
+        self.session.add(contents1)
+        # same file in different binary packages should be okay
+        contents2 = BinContents(file = 'usr/bin/hello', \
+            binary = self.binary['gnome-hello_2.2-1_i386'])
+        self.session.add(contents2)
+        self.session.flush()
+
+if __name__ == '__main__':
+    unittest.main()