view test/test_info_data.py @ 462:058856954e2d

Make the compress_all_logs call builder independent and also compress if an error occurs before the builders are executed.
author Andre Heinecke <aheinecke@intevation.de>
date Tue, 31 Aug 2010 15:56:46 +0000
parents 4980f8d5014a
children c8268d40d35d
line wrap: on
line source
# Copyright (C) 2010 by Intevation GmbH
# Authors:
# Bjoern Ricks <bjoern.ricks@intevation.de>
#
# This program is free software under the GPL (>=v2)
# Read the file COPYING coming with the software for details.

"""Tests for treepkg.info.data"""

import unittest
import os.path
import sys

test_dir = os.path.dirname(__file__)
sys.path.append(os.path.join(test_dir, os.pardir))

from treepkg.info.data import Package
from treepkg.info.data import CacheDb
from filesupport import FileTestMixin

class TestCacheDb(unittest.TestCase, FileTestMixin):

    def test_cache_db(self):
        tmpdir = self.create_test_specific_temp_dir()
        package = Package("/tmp/abc/abc_0.1_i386.deb", "abc",
            "abc_0.1_i386.deb", "/source/abc/abc_0.1_i386.deb", 
            "binary-i386", "1234567")
#        tmpfile = self.create_temp_file("cachedb1", "abc")
#        with self.assertRaises(Exception):
#            db = CacheDb(tmpfile)

        dbfile = os.path.join(tmpdir, "cachedb2")
        db = CacheDb(dbfile)
        # insert
        filename = package.filename
        db.add_package(package)
        package = db.get_package(filename)
        self.assertEquals("1234567", package.md5sum)
        # update
        package.md5sum = "01234567"
        db.add_package(package)
        package = db.get_package(filename)
        self.assertEquals("01234567", package.md5sum)

        # test get_package
        package2 = db.get_package(package.filename)
        self.assertNotEquals(None, package2)
        self.assertEquals(package.filename, package2.filename)
        self.assertEquals(package.name, package2.name)
        self.assertEquals(package.sourcepath, package2.sourcepath)
        self.assertEquals(package.arch, package2.arch)
        self.assertEquals(package.md5sum, package2.md5sum)

        package3 = Package("/tmp/foo/foo_0.2.i386.deb", "foo",
            "foo_0.2_i386.deb", "/tmp/source/foo/foo_0.2.i386.deb",
            "binary-i386", "987654321")
        package4 = Package("/tmp/john/doe_0.3.i386.deb", "john",
            "doe_0.3.i386.deb", "/tmp/source/john/doe_0.3.i386.deb",
            "binary-i386", "5671234")
        db.add_package(package3)
        db.add_package(package4)

        # test get_old_packages
        oldpackages = db.get_old_packages([package.filename])
        self.assertEquals(2, len(oldpackages))
        packages = db.get_packages()
        self.assertEquals(3, len(packages))
        db.remove_packages(oldpackages)
        packages = db.get_packages()
        self.assertEquals(1, len(packages))

if __name__ == '__main__':
    unittest.main()
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)