~ubuntu-branches/ubuntu/quantal/config-manager/quantal

« back to all changes in this revision

Viewing changes to lib/config_manager/tests/test_config_entry.py

  • Committer: Bazaar Package Importer
  • Author(s): Anand Kumria
  • Date: 2005-10-24 13:01:11 UTC
  • mto: (3.1.1 dapper)
  • mto: This revision was merged to the branch mainline in revision 4.
  • Revision ID: james.westby@ubuntu.com-20051024130111-3muotu4me5hhhiow
Tags: upstream-0.2
ImportĀ upstreamĀ versionĀ 0.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#
 
2
# Copyright (C) 2005  Robert Collins  <robertc@squid-cache.org>
 
3
 
4
 
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.
 
9
 
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.
 
14
 
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
 
18
 
 
19
import tests
 
20
import unittest
 
21
 
 
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
 
24
import config_manager
 
25
from config_manager.tests import FunctionalTestCase
 
26
 
 
27
import os
 
28
 
 
29
class TestConfigEntry(unittest.TestCase):
 
30
 
 
31
    def test_imports(self):
 
32
        from config_manager import ConfigEntry
 
33
 
 
34
    def test_cannot_default_init(self):
 
35
        self.assertRaises(TypeError, config_manager.ConfigEntry)
 
36
 
 
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")
 
42
 
 
43
    def test_eq(self):
 
44
        entry1 = config_manager.ConfigEntry("./foo", "svn:///bar")
 
45
        entry2 = config_manager.ConfigEntry("./foo", "svn:///bar")
 
46
        self.assertEqual(entry1, entry2)
 
47
 
 
48
class FunctionalConfigEntryTest(FunctionalTestCase):
 
49
 
 
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(), 
 
56
                         "yo\n")
 
57
 
 
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")))
 
64
        
 
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"))
 
72
        
 
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"))])
 
82
        
 
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"))])
 
93
        
 
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, [])
 
104
 
 
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(), 
 
113
                         "yo\n")
 
114
        
 
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(), 
 
123
                         "stick\n")
 
124
 
 
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,
 
130
                          entry.build,
 
131
                          os.path.join(self.tempdir, "build1"))
 
132
 
 
133
 
 
134
def test_suite():
 
135
    result = tests
 
136
    loader = tests.TestLoader()
 
137
    result = loader.loadTestsFromName(__name__)
 
138
    return result