dbtest_cruft.py 3.57 KB
Newer Older
1 2 3 4 5 6 7 8 9
#!/usr/bin/env python

from db_test import DBDakTestCase

from daklib.dbconn import *
from daklib.cruft import *

import unittest

10

11
class CruftTestCase(DBDakTestCase):
12

13 14 15 16 17 18
    """
    This class checks various functions of cruft-report.
    """

    def setUp(self):
        super(CruftTestCase, self).setUp()
19
        self.install_date = self.now()
20 21 22 23 24 25 26 27 28
        self.setup_binaries()
        # flush to make sure that the setup is correct
        self.session.flush()

    def test_newer_version(self):
        'tests newer_version()'

        list = newer_version('squeeze', 'sid', self.session)
        self.assertEqual([], list)
29 30 31 32 33 34 35 36 37 38 39
        self.file[
            'sl_3.03-17.dsc'] = PoolFile(filename='main/s/sl/sl_3.03-17.dsc',
                                         filesize=0, md5sum='')
        self.file['sl_3.03-17.dsc'].sha1sum = 'sha1sum'
        self.file['sl_3.03-17.dsc'].sha256sum = 'sha256sum'
        self.source['sl_3.03-17'] = DBSource(source='sl', version='3.03-17',
                                             maintainer=self.maintainer[
                                                 'maintainer'],
                                             changedby=self.maintainer[
                                                 'uploader'],
                                             poolfile=self.file['sl_3.03-17.dsc'], install_date=self.install_date)
40 41 42 43
        self.source['sl_3.03-17'].suites.append(self.suite['squeeze'])
        list = newer_version('squeeze', 'sid', self.session)
        self.assertEqual([('sl', '3.03-16', '3.03-17')], list)

44 45 46 47 48
    def test_multiple_source(self):
        'tests functions related to report_multiple_source()'

        # test get_package_names()
        suite = get_suite('sid', self.session)
49 50
        self.assertEqual([('gnome-hello', ), ('hello', )],
                         get_package_names(suite).all())
51 52 53 54 55 56 57 58 59
        # test class NamedSource
        src = NamedSource(suite, 'hello')
        self.assertEqual('hello', src.source)
        self.assertEqual(['2.2-1', '2.2-2'], src.versions)
        self.assertEqual('hello(2.2-1, 2.2-2)', str(src))
        # test class DejavuBinary
        bin = DejavuBinary(suite, 'hello')
        self.assertEqual(False, bin.has_multiple_sources())
        # add another binary
60 61 62 63 64 65 66 67 68 69 70 71 72
        self.file[
            'hello_2.2-3'] = PoolFile(filename='main/s/sl/hello_2.2-3_i386.deb',
                                      filesize=0, md5sum='')
        self.file['hello_2.2-3'].sha1sum = 'sha1sum'
        self.file['hello_2.2-3'].sha256sum = 'sha256sum'
        self.binary['hello_2.2-3_i386'] = DBBinary(package='hello',
                                                   source=self.source[
                                                       'sl_3.03-16'], version='2.2-3',
                                                   maintainer=self.maintainer[
                                                       'maintainer'],
                                                   architecture=self.arch[
                                                       'i386'],
                                                   poolfile=self.file['hello_2.2-3'])
73 74 75 76 77 78 79
        self.session.add(self.binary['hello_2.2-3_i386'])
        bin = DejavuBinary(suite, 'hello')
        self.assertEqual(False, bin.has_multiple_sources())
        # add it to suite sid
        self.binary['hello_2.2-3_i386'].suites.append(self.suite['sid'])
        bin = DejavuBinary(suite, 'hello')
        self.assertEqual(True, bin.has_multiple_sources())
80 81
        self.assertEqual('hello built by: hello(2.2-1, 2.2-2), sl(3.03-16)',
                         str(bin))
82

83

84 85
if __name__ == '__main__':
    unittest.main()