annotate test/test_info.py @ 413:94a6ae627b31 treepkg-status

implemented CacheDb to store copied Packages from build host
author Bjoern Ricks <bricks@intevation.de>
date Fri, 23 Jul 2010 16:40:38 +0000
parents e2afbd3c2bf1
children e0539b483b04
rev   line source
388
1af04bfbb1d0 moved test file to test main dir
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
1 # Copyright (C) 2010 by Intevation GmbH
1af04bfbb1d0 moved test file to test main dir
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
2 # Authors:
1af04bfbb1d0 moved test file to test main dir
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
3 # Bjoern Ricks <bjoern.ricks@intevation.de>
1af04bfbb1d0 moved test file to test main dir
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
4 #
1af04bfbb1d0 moved test file to test main dir
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
5 # This program is free software under the GPL (>=v2)
1af04bfbb1d0 moved test file to test main dir
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
6 # Read the file COPYING coming with the software for details.
1af04bfbb1d0 moved test file to test main dir
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
7
1af04bfbb1d0 moved test file to test main dir
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
8 """Tests for treepkg.status.status"""
1af04bfbb1d0 moved test file to test main dir
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
9
1af04bfbb1d0 moved test file to test main dir
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
10 import unittest
1af04bfbb1d0 moved test file to test main dir
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
11 import os.path
1af04bfbb1d0 moved test file to test main dir
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
12 import sys
1af04bfbb1d0 moved test file to test main dir
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
13
1af04bfbb1d0 moved test file to test main dir
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
14 test_dir = os.path.dirname(__file__)
1af04bfbb1d0 moved test file to test main dir
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
15 sys.path.append(os.path.join(test_dir, os.pardir))
413
94a6ae627b31 implemented CacheDb to store copied Packages from build host
Bjoern Ricks <bricks@intevation.de>
parents: 392
diff changeset
16 sys.path.append(os.path.join(test_dir, os.pardir, "bin"))
388
1af04bfbb1d0 moved test file to test main dir
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
17
392
e2afbd3c2bf1 write first info about tracks
Bjoern Ricks <bricks@intevation.de>
parents: 388
diff changeset
18 from treepkg.info.status import *
388
1af04bfbb1d0 moved test file to test main dir
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
19 from treepkg.report import get_packager_group
1af04bfbb1d0 moved test file to test main dir
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
20 from filesupport import FileTestMixin
1af04bfbb1d0 moved test file to test main dir
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
21
413
94a6ae627b31 implemented CacheDb to store copied Packages from build host
Bjoern Ricks <bricks@intevation.de>
parents: 392
diff changeset
22 from publishdebianpackages import get_binary_arch
94a6ae627b31 implemented CacheDb to store copied Packages from build host
Bjoern Ricks <bricks@intevation.de>
parents: 392
diff changeset
23 from publishdebianpackages import Package
94a6ae627b31 implemented CacheDb to store copied Packages from build host
Bjoern Ricks <bricks@intevation.de>
parents: 392
diff changeset
24 from publishdebianpackages import CacheDb
94a6ae627b31 implemented CacheDb to store copied Packages from build host
Bjoern Ricks <bricks@intevation.de>
parents: 392
diff changeset
25
392
e2afbd3c2bf1 write first info about tracks
Bjoern Ricks <bricks@intevation.de>
parents: 388
diff changeset
26 class TreepkgInfoTest(unittest.TestCase, FileTestMixin):
388
1af04bfbb1d0 moved test file to test main dir
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
27 config_contents = """\
1af04bfbb1d0 moved test file to test main dir
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
28 [DEFAULT]
392
e2afbd3c2bf1 write first info about tracks
Bjoern Ricks <bricks@intevation.de>
parents: 388
diff changeset
29 #treepkg_dir: /home/builder/mill
e2afbd3c2bf1 write first info about tracks
Bjoern Ricks <bricks@intevation.de>
parents: 388
diff changeset
30 #tracks_dir: %(treepkg_dir)s/tracks
e2afbd3c2bf1 write first info about tracks
Bjoern Ricks <bricks@intevation.de>
parents: 388
diff changeset
31 tracks_dir: /home/builder/mill/tracks
388
1af04bfbb1d0 moved test file to test main dir
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
32 root_cmd: sudo
392
e2afbd3c2bf1 write first info about tracks
Bjoern Ricks <bricks@intevation.de>
parents: 388
diff changeset
33 pbuilder_dir: %(tracks_dir)s/pbuilder
388
1af04bfbb1d0 moved test file to test main dir
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
34 builderconfig: %(pbuilder_dir)s/pbuilderrc
1af04bfbb1d0 moved test file to test main dir
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
35 deb_email: treepkg@example.com
1af04bfbb1d0 moved test file to test main dir
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
36 deb_fullname: TreePKG
1af04bfbb1d0 moved test file to test main dir
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
37 pkg_revision_template: treepkg%%(pkg_revision)s
1af04bfbb1d0 moved test file to test main dir
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
38 handle_dependencies: False
1af04bfbb1d0 moved test file to test main dir
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
39
1af04bfbb1d0 moved test file to test main dir
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
40 [treepkg]
392
e2afbd3c2bf1 write first info about tracks
Bjoern Ricks <bricks@intevation.de>
parents: 388
diff changeset
41 instructions_file: %(tracks_dir)s/instructions
388
1af04bfbb1d0 moved test file to test main dir
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
42 check_interval: 3600
1af04bfbb1d0 moved test file to test main dir
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
43 name: testtreepkginfo
1af04bfbb1d0 moved test file to test main dir
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
44
1af04bfbb1d0 moved test file to test main dir
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
45 [pkg_simple]
1af04bfbb1d0 moved test file to test main dir
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
46 pkg_basename: simple1
1af04bfbb1d0 moved test file to test main dir
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
47 svn_url: svn://example.com/%(name)s/trunk
1af04bfbb1d0 moved test file to test main dir
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
48 base_dir: %(tracks_dir)s/%(name)s
1af04bfbb1d0 moved test file to test main dir
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
49 packager_class: treepkginfo_test.%(name)s
1af04bfbb1d0 moved test file to test main dir
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
50 handle_dependencies: True
1af04bfbb1d0 moved test file to test main dir
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
51 signing_key_id: abcd1234
1af04bfbb1d0 moved test file to test main dir
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
52 changelog_msg_template: Update to feature branch r%%(revision)s
1af04bfbb1d0 moved test file to test main dir
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
53 version_template: 1.0.svn%%(revision)s
1af04bfbb1d0 moved test file to test main dir
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
54
1af04bfbb1d0 moved test file to test main dir
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
55 """
1af04bfbb1d0 moved test file to test main dir
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
56
1af04bfbb1d0 moved test file to test main dir
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
57 files = [("treepkg.cfg", config_contents),
1af04bfbb1d0 moved test file to test main dir
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
58 ("treepkginfo_test",
1af04bfbb1d0 moved test file to test main dir
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
59 [("__init__.py", ""),
1af04bfbb1d0 moved test file to test main dir
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
60 ("simple.py",
1af04bfbb1d0 moved test file to test main dir
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
61 "\n".join(["class SourcePackager:",
1af04bfbb1d0 moved test file to test main dir
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
62 " pass",
1af04bfbb1d0 moved test file to test main dir
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
63 ""])),
1af04bfbb1d0 moved test file to test main dir
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
64 ])]
1af04bfbb1d0 moved test file to test main dir
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
65
1af04bfbb1d0 moved test file to test main dir
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
66 def setUp(self):
1af04bfbb1d0 moved test file to test main dir
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
67 self.directory = self.create_files("treepkg", self.files)
1af04bfbb1d0 moved test file to test main dir
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
68 self.old_path = sys.path
1af04bfbb1d0 moved test file to test main dir
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
69 sys.path = [self.directory] + sys.path
1af04bfbb1d0 moved test file to test main dir
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
70
1af04bfbb1d0 moved test file to test main dir
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
71 def tearDown(self):
1af04bfbb1d0 moved test file to test main dir
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
72 sys.path = self.old_path
1af04bfbb1d0 moved test file to test main dir
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
73
1af04bfbb1d0 moved test file to test main dir
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
74 def test_createinfo(self):
1af04bfbb1d0 moved test file to test main dir
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
75 config_file = os.path.join(self.directory, "treepkg.cfg")
392
e2afbd3c2bf1 write first info about tracks
Bjoern Ricks <bricks@intevation.de>
parents: 388
diff changeset
76 tpkginfo = TreepkgInfo(config_file)
413
94a6ae627b31 implemented CacheDb to store copied Packages from build host
Bjoern Ricks <bricks@intevation.de>
parents: 392
diff changeset
77 tpkgrootinfo = tpkginfo.tpkgroot.info
94a6ae627b31 implemented CacheDb to store copied Packages from build host
Bjoern Ricks <bricks@intevation.de>
parents: 392
diff changeset
78 self.assertEquals("testtreepkginfo", tpkgrootinfo.name)
388
1af04bfbb1d0 moved test file to test main dir
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
79
1af04bfbb1d0 moved test file to test main dir
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
80
392
e2afbd3c2bf1 write first info about tracks
Bjoern Ricks <bricks@intevation.de>
parents: 388
diff changeset
81 class TreepkgRootInfoTest(unittest.TestCase):
388
1af04bfbb1d0 moved test file to test main dir
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
82
1af04bfbb1d0 moved test file to test main dir
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
83 def test_toxml(self):
392
e2afbd3c2bf1 write first info about tracks
Bjoern Ricks <bricks@intevation.de>
parents: 388
diff changeset
84 status = TreepkgRootInfo("testtreepkg")
388
1af04bfbb1d0 moved test file to test main dir
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
85 dom = status.toxml()
1af04bfbb1d0 moved test file to test main dir
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
86 xml = dom.toxml()
413
94a6ae627b31 implemented CacheDb to store copied Packages from build host
Bjoern Ricks <bricks@intevation.de>
parents: 392
diff changeset
87 self.assertEquals("<info><name>testtreepkg</name></info>", xml)
94a6ae627b31 implemented CacheDb to store copied Packages from build host
Bjoern Ricks <bricks@intevation.de>
parents: 392
diff changeset
88
94a6ae627b31 implemented CacheDb to store copied Packages from build host
Bjoern Ricks <bricks@intevation.de>
parents: 392
diff changeset
89 class TestPublishDebianPackages(unittest.TestCase, FileTestMixin):
94a6ae627b31 implemented CacheDb to store copied Packages from build host
Bjoern Ricks <bricks@intevation.de>
parents: 392
diff changeset
90
94a6ae627b31 implemented CacheDb to store copied Packages from build host
Bjoern Ricks <bricks@intevation.de>
parents: 392
diff changeset
91 def test_get_binary_arch(self):
94a6ae627b31 implemented CacheDb to store copied Packages from build host
Bjoern Ricks <bricks@intevation.de>
parents: 392
diff changeset
92 source = get_binary_arch("source")
94a6ae627b31 implemented CacheDb to store copied Packages from build host
Bjoern Ricks <bricks@intevation.de>
parents: 392
diff changeset
93 self.assertEquals("source", source)
94a6ae627b31 implemented CacheDb to store copied Packages from build host
Bjoern Ricks <bricks@intevation.de>
parents: 392
diff changeset
94 binary_armel = get_binary_arch("armel")
94a6ae627b31 implemented CacheDb to store copied Packages from build host
Bjoern Ricks <bricks@intevation.de>
parents: 392
diff changeset
95 self.assertEquals("binary-armel", binary_armel)
94a6ae627b31 implemented CacheDb to store copied Packages from build host
Bjoern Ricks <bricks@intevation.de>
parents: 392
diff changeset
96 binary_armel = get_binary_arch("binary-armel")
94a6ae627b31 implemented CacheDb to store copied Packages from build host
Bjoern Ricks <bricks@intevation.de>
parents: 392
diff changeset
97 self.assertEquals("binary-armel", binary_armel)
94a6ae627b31 implemented CacheDb to store copied Packages from build host
Bjoern Ricks <bricks@intevation.de>
parents: 392
diff changeset
98
94a6ae627b31 implemented CacheDb to store copied Packages from build host
Bjoern Ricks <bricks@intevation.de>
parents: 392
diff changeset
99 def test_cache_db(self):
94a6ae627b31 implemented CacheDb to store copied Packages from build host
Bjoern Ricks <bricks@intevation.de>
parents: 392
diff changeset
100 tmpdir = self.create_test_specific_temp_dir()
94a6ae627b31 implemented CacheDb to store copied Packages from build host
Bjoern Ricks <bricks@intevation.de>
parents: 392
diff changeset
101 package = Package("/tmp/abc/abc_0.1_i386.deb", "abc",
94a6ae627b31 implemented CacheDb to store copied Packages from build host
Bjoern Ricks <bricks@intevation.de>
parents: 392
diff changeset
102 "abc_0.1_i386.deb", "/source/abc/abc_0.1_i386.deb",
94a6ae627b31 implemented CacheDb to store copied Packages from build host
Bjoern Ricks <bricks@intevation.de>
parents: 392
diff changeset
103 "binary-i386", "1234567")
94a6ae627b31 implemented CacheDb to store copied Packages from build host
Bjoern Ricks <bricks@intevation.de>
parents: 392
diff changeset
104 # tmpfile = self.create_temp_file("cachedb1", "abc")
94a6ae627b31 implemented CacheDb to store copied Packages from build host
Bjoern Ricks <bricks@intevation.de>
parents: 392
diff changeset
105 # with self.assertRaises(Exception):
94a6ae627b31 implemented CacheDb to store copied Packages from build host
Bjoern Ricks <bricks@intevation.de>
parents: 392
diff changeset
106 # db = CacheDb(tmpfile)
94a6ae627b31 implemented CacheDb to store copied Packages from build host
Bjoern Ricks <bricks@intevation.de>
parents: 392
diff changeset
107
94a6ae627b31 implemented CacheDb to store copied Packages from build host
Bjoern Ricks <bricks@intevation.de>
parents: 392
diff changeset
108 dbfile = os.path.join(tmpdir, "cachedb2")
94a6ae627b31 implemented CacheDb to store copied Packages from build host
Bjoern Ricks <bricks@intevation.de>
parents: 392
diff changeset
109 db = CacheDb(dbfile)
94a6ae627b31 implemented CacheDb to store copied Packages from build host
Bjoern Ricks <bricks@intevation.de>
parents: 392
diff changeset
110 db.add_package(package)
94a6ae627b31 implemented CacheDb to store copied Packages from build host
Bjoern Ricks <bricks@intevation.de>
parents: 392
diff changeset
111
94a6ae627b31 implemented CacheDb to store copied Packages from build host
Bjoern Ricks <bricks@intevation.de>
parents: 392
diff changeset
112 # test get_package and get_timestamp
94a6ae627b31 implemented CacheDb to store copied Packages from build host
Bjoern Ricks <bricks@intevation.de>
parents: 392
diff changeset
113 package2 = db.get_package(package.filename)
94a6ae627b31 implemented CacheDb to store copied Packages from build host
Bjoern Ricks <bricks@intevation.de>
parents: 392
diff changeset
114 self.assertNotEquals(None, package2)
94a6ae627b31 implemented CacheDb to store copied Packages from build host
Bjoern Ricks <bricks@intevation.de>
parents: 392
diff changeset
115 self.assertEquals(package.filename, package2.filename)
94a6ae627b31 implemented CacheDb to store copied Packages from build host
Bjoern Ricks <bricks@intevation.de>
parents: 392
diff changeset
116 self.assertEquals(package.name, package2.name)
94a6ae627b31 implemented CacheDb to store copied Packages from build host
Bjoern Ricks <bricks@intevation.de>
parents: 392
diff changeset
117 self.assertEquals(package.sourcepath, package2.sourcepath)
94a6ae627b31 implemented CacheDb to store copied Packages from build host
Bjoern Ricks <bricks@intevation.de>
parents: 392
diff changeset
118 self.assertEquals(package.arch, package2.arch)
94a6ae627b31 implemented CacheDb to store copied Packages from build host
Bjoern Ricks <bricks@intevation.de>
parents: 392
diff changeset
119 self.assertEquals(package.md5sum, package2.md5sum)
94a6ae627b31 implemented CacheDb to store copied Packages from build host
Bjoern Ricks <bricks@intevation.de>
parents: 392
diff changeset
120
94a6ae627b31 implemented CacheDb to store copied Packages from build host
Bjoern Ricks <bricks@intevation.de>
parents: 392
diff changeset
121 # test get_old_packages
94a6ae627b31 implemented CacheDb to store copied Packages from build host
Bjoern Ricks <bricks@intevation.de>
parents: 392
diff changeset
122 package3 = Package("/tmp/foo/foo_0.2.i386.deb", "foo",
94a6ae627b31 implemented CacheDb to store copied Packages from build host
Bjoern Ricks <bricks@intevation.de>
parents: 392
diff changeset
123 "foo_0.2_i386.deb", "/tmp/foo/foo_0.2.i386.deb",
94a6ae627b31 implemented CacheDb to store copied Packages from build host
Bjoern Ricks <bricks@intevation.de>
parents: 392
diff changeset
124 "binary-i386", "987654321")
94a6ae627b31 implemented CacheDb to store copied Packages from build host
Bjoern Ricks <bricks@intevation.de>
parents: 392
diff changeset
125 db.add_package(package3)
94a6ae627b31 implemented CacheDb to store copied Packages from build host
Bjoern Ricks <bricks@intevation.de>
parents: 392
diff changeset
126 oldpackages = db.get_old_packages([package.filename])
94a6ae627b31 implemented CacheDb to store copied Packages from build host
Bjoern Ricks <bricks@intevation.de>
parents: 392
diff changeset
127 self.assertEquals(1, len(oldpackages))
94a6ae627b31 implemented CacheDb to store copied Packages from build host
Bjoern Ricks <bricks@intevation.de>
parents: 392
diff changeset
128 packages = db.get_packages()
94a6ae627b31 implemented CacheDb to store copied Packages from build host
Bjoern Ricks <bricks@intevation.de>
parents: 392
diff changeset
129 self.assertEquals(2, len(packages))
94a6ae627b31 implemented CacheDb to store copied Packages from build host
Bjoern Ricks <bricks@intevation.de>
parents: 392
diff changeset
130 db.remove_packages([package.filename for package in oldpackages])
94a6ae627b31 implemented CacheDb to store copied Packages from build host
Bjoern Ricks <bricks@intevation.de>
parents: 392
diff changeset
131 packages = db.get_packages()
94a6ae627b31 implemented CacheDb to store copied Packages from build host
Bjoern Ricks <bricks@intevation.de>
parents: 392
diff changeset
132 self.assertEquals(1, len(packages))
388
1af04bfbb1d0 moved test file to test main dir
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
133
1af04bfbb1d0 moved test file to test main dir
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
134 if __name__ == '__main__':
1af04bfbb1d0 moved test file to test main dir
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
135 unittest.main()
1af04bfbb1d0 moved test file to test main dir
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
136
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)