2
# Copyright (C) 2005 Robert Collins <robertc@squid-cache.org>
5
# This program is free software; you can redistribute it and/or modify
6
# it under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 2 of the License, or
8
# (at your option) any later version.
10
# This program is distributed in the hope that it will be useful,
11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
15
# You should have received a copy of the GNU General Public License
16
# along with this program; if not, write to the Free Software
17
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22
# if this fails to import, then the config_manager module is bust
23
# and this test script will never be reached to be imported
25
from config_manager.tests import FunctionalTestCase
29
class TestConfigEntry(unittest.TestCase):
31
def test_imports(self):
32
from config_manager import ConfigEntry
34
def test_cannot_default_init(self):
35
self.assertRaises(TypeError, config_manager.ConfigEntry)
37
def test_init_abs(self):
38
"""We should be able to create an entry with a path and url."""
39
entry = config_manager.ConfigEntry("./foo", "svn:///bar")
40
self.assertEqual(entry.path, "./foo")
41
self.assertEqual(entry.url, "svn:///bar")
44
entry1 = config_manager.ConfigEntry("./foo", "svn:///bar")
45
entry2 = config_manager.ConfigEntry("./foo", "svn:///bar")
46
self.assertEqual(entry1, entry2)
48
class FunctionalConfigEntryTest(FunctionalTestCase):
50
def test_build_arch_version(self):
51
"""Test that doing an arch version based build works."""
52
entry = config_manager.ConfigEntry("nested", "arch://anarchive@example.com/foo--0")
53
entry.build(os.path.join(self.tempdir, "build1"))
54
self.assertEqual(open(
55
os.path.join(self.tempdir, "build1", "nested", "proof"), "r").read(),
58
def test_build_arch_revision(self):
59
entry = config_manager.ConfigEntry("nested",
60
"arch://anarchive@example.com/foo--0--base-0")
61
entry.build(os.path.join(self.tempdir, "build1"))
62
self.failIf(os.path.exists(
63
os.path.join(self.tempdir, "build1", "nested", "proof")))
65
def test_update_arch_version(self):
66
entry = config_manager.ConfigEntry("nested",
67
"arch://anarchive@example.com/foo--0--base-0")
68
entry.build(os.path.join(self.tempdir, "build1"))
69
entry = config_manager.ConfigEntry("nested",
70
"arch://anarchive@example.com/foo--0")
71
entry.update(os.path.join(self.tempdir, "build1"))
73
def test_build_fake_version(self):
74
"""Test doing a fake:// based build works."""
75
entry = config_manager.ConfigEntry("nested",
76
"fake://anarchive@example.com")
77
entry.build(os.path.join(self.tempdir, "build1"))
78
from config_manager import fake_builds
79
self.assertEqual(fake_builds, [("fake://anarchive@example.com",
80
os.path.join(self.tempdir,
81
"build1", "nested"))])
83
def test_update_fake_version(self):
84
"""Test doing a fake:// based update works."""
85
entry = config_manager.ConfigEntry("nested",
86
"fake://anarchive@example.com")
87
entry.build(os.path.join(self.tempdir, "build1"))
88
entry.update(os.path.join(self.tempdir, "build1"))
89
from config_manager import fake_updates
90
self.assertEqual(fake_updates, [("fake://anarchive@example.com",
91
os.path.join(self.tempdir,
92
"build1", "nested"))])
94
def test_update_fake_missing_dir(self):
95
"""Test doing a fake:// based update falls back to a build."""
96
entry = config_manager.ConfigEntry("nested",
97
"fake://anarchive@example.com")
98
entry.update(os.path.join(self.tempdir, "build1"))
99
from config_manager import fake_builds, fake_updates
100
self.assertEqual(fake_builds, [("fake://anarchive@example.com",
101
os.path.join(self.tempdir,
102
"build1", "nested"))])
103
self.assertEqual(fake_updates, [])
105
def test_file_url_with_arch(self):
106
"""Test building a file url that is actually an arch version."""
107
basepath = self.tempdir.replace('\\', '/')
108
entry = config_manager.ConfigEntry("nested",
109
"file://" + basepath + "/archive/foo--0")
110
entry.build(os.path.join(self.tempdir, "build1"))
111
self.assertEqual(open(
112
os.path.join(self.tempdir, "build1", "nested", "proof"), "r").read(),
115
def disabled_test_file_url_with_baz2(self):
116
"""Test building a file url that is actually a baz2 branch."""
117
basepath = self.tempdir.replace('\\', '/')
118
entry = config_manager.ConfigEntry("nested",
119
"file://" + basepath + "/bzr")
120
entry.build(os.path.join(self.tempdir, "build1"))
121
self.assertEqual(open(
122
os.path.join(self.tempdir, "build1", "nested", "broom"), "r").read(),
125
def test_build_absent_path(self):
126
"""Test that building fails when a path component is missing."""
127
entry = config_manager.ConfigEntry("missing/nested",
128
"arch://anarchive@example.com/foo--0")
129
self.assertRaises(KeyError,
131
os.path.join(self.tempdir, "build1"))
136
loader = tests.TestLoader()
137
result = loader.loadTestsFromName(__name__)