~simpoir/landscape-charm/charm_push_target

« back to all changes in this revision

Viewing changes to lib/tests/test_apt.py

  • Committer: Adam Collard
  • Date: 2019-01-17 14:18:28 UTC
  • Revision ID: adam.collard@canonical.com-20190117141828-s0md02ozdg4vrab5
Revert r393, r392

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
 
6
6
from lib.apt import (
7
7
    Apt, AptNoSourceConfigError, AptSourceAndKeyDontMatchError,
8
 
    SourceConflictError, INSTALL_PACKAGES, DEFAULT_INSTALL_OPTIONS,
9
 
    SAMPLE_HASHIDS_PPA, SAMPLE_HASHIDS_KEY)
 
8
    INSTALL_PACKAGES, DEFAULT_INSTALL_OPTIONS, SAMPLE_HASHIDS_PPA,
 
9
    SAMPLE_HASHIDS_KEY)
10
10
from lib.tests.stubs import FetchStub, SubprocessStub
11
11
from lib.tests.helpers import HookenvTest
12
12
from lib.tests.rootdir import RootDir
16
16
 
17
17
    def setUp(self):
18
18
        super(AptTest, self).setUp()
19
 
        # charmhelpers.fetch doesn't support dependency injection, so
20
 
        # we pass in our config to be able to inspect what was used
21
 
        self.fetch = FetchStub(self.hookenv.config)
 
19
        self.fetch = FetchStub()
22
20
        self.subprocess = SubprocessStub()
23
21
        self.root_dir = self.useFixture(RootDir())
24
22
        self.paths = self.root_dir.paths
66
64
        self.apt.set_sources()
67
65
        self.assertEqual([("ppa:landscape/14.10", None)], self.fetch.sources)
68
66
        self.assertEqual([True], self.fetch.updates)
69
 
        # With source set, fetch.configure_sources is not called
70
 
        self.assertEqual(self.fetch.configured_sources, [])
71
67
 
72
68
    def test_set_shorthand_sources(self):
73
69
        """
158
154
        self.hookenv.config()["key"] = "xyz"
159
155
        with self.assertRaises(AptSourceAndKeyDontMatchError) as error:
160
156
            self.apt.set_sources()
161
 
        self.assertEqual(
162
 
            "The 'source' and 'key' lists have different lengths",
163
 
            str(error.exception))
164
 
 
165
 
    def test_set_sources_and_install_sources(self):
166
 
        """
167
 
        If sources and install_sources are set set_sources complains.
168
 
        """
169
 
        self.hookenv.config()["source"] = "ppa:landscape/14.10"
170
 
        self.hookenv.config()["install_sources"] = "anything"
171
 
        with self.assertRaises(SourceConflictError) as error:
172
 
            self.apt.set_sources()
173
 
        self.assertEqual(
174
 
            "install_sources: 'anything' and source: 'ppa:landscape/14.10' "
175
 
            "are mutually exclusive.",
176
 
            str(error.exception))
177
 
 
178
 
    def test_install_sources(self):
179
 
        """
180
 
        If install_sources is set, it's passed to fetch.configure_sources.
181
 
        """
182
 
        self.hookenv.config()["install_sources"] = "ppa:landscape/19.01"
183
 
        self.hookenv.config()["install_keys"] = "DEADBEEF"
184
 
        self.apt.set_sources()
185
 
        self.assertEqual(
186
 
            self.fetch.configured_sources,
187
 
            [('ppa:landscape/19.01', 'DEADBEEF')])
 
157
            self.assertEqual(
 
158
                "The 'source' and 'key' lists have different lengths",
 
159
                str(error))
188
160
 
189
161
    def test_local_tarball(self):
190
162
        """