From: Torsten Werner Date: Sun, 6 Feb 2011 18:06:59 +0000 (+0100) Subject: Add a test for class BinContents. X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9d7967ab9281ba8f125d9e03b360d23f288bff5b;p=dak Add a test for class BinContents. Signed-off-by: Torsten Werner --- diff --git a/daklib/dbconn.py b/daklib/dbconn.py index dc5518a9..14ed7faa 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 00000000..d6619e70 --- /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()