[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

[dak/master] Add a test for class BinContents.



Signed-off-by: Torsten Werner <twerner@debian.org>
---
 daklib/dbconn.py         |    6 ++++-
 tests/dbtest_contents.py |   61 ++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 66 insertions(+), 1 deletions(-)
 create mode 100755 tests/dbtest_contents.py

diff --git a/daklib/dbconn.py b/daklib/dbconn.py
index dc5518a..14ed7fa 100755
--- a/daklib/dbconn.py
+++ b/daklib/dbconn.py
@@ -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
index 0000000..d6619e7
--- /dev/null
+++ b/tests/dbtest_contents.py
@@ -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()
-- 
1.5.6.5



Reply to: