~oddbloke/cloud-init/fix-gce-az

« back to all changes in this revision

Viewing changes to tests/unittests/test_handler/test_handler_apt_configure.py

  • Committer: Daniel Watkins
  • Date: 2015-07-22 12:06:34 UTC
  • Revision ID: daniel.watkins@canonical.com-20150722120634-wsg8rwzcaanhc2pn
Make full data source available to code that handles mirror selection.

Show diffs side-by-side

added added

removed removed

Lines of Context:
9
9
import tempfile
10
10
 
11
11
 
 
12
def load_tfile_or_url(*args, **kwargs):
 
13
    return(util.decode_binary(util.read_file_or_url(*args, **kwargs).contents))
 
14
 
 
15
 
12
16
class TestAptProxyConfig(TestCase):
13
17
    def setUp(self):
14
18
        super(TestAptProxyConfig, self).setUp()
29
33
        self.assertTrue(os.path.isfile(self.pfile))
30
34
        self.assertFalse(os.path.isfile(self.cfile))
31
35
 
32
 
        contents = util.load_tfile_or_url(self.pfile)
 
36
        contents = load_tfile_or_url(self.pfile)
33
37
        self.assertTrue(self._search_apt_config(contents, "http", "myproxy"))
34
38
 
35
39
    def test_apt_http_proxy_written(self):
39
43
        self.assertTrue(os.path.isfile(self.pfile))
40
44
        self.assertFalse(os.path.isfile(self.cfile))
41
45
 
42
 
        contents = util.load_tfile_or_url(self.pfile)
 
46
        contents = load_tfile_or_url(self.pfile)
43
47
        self.assertTrue(self._search_apt_config(contents, "http", "myproxy"))
44
48
 
45
49
    def test_apt_all_proxy_written(self):
57
61
        self.assertTrue(os.path.isfile(self.pfile))
58
62
        self.assertFalse(os.path.isfile(self.cfile))
59
63
 
60
 
        contents = util.load_tfile_or_url(self.pfile)
 
64
        contents = load_tfile_or_url(self.pfile)
61
65
 
62
66
        for ptype, pval in values.items():
63
67
            self.assertTrue(self._search_apt_config(contents, ptype, pval))
73
77
        cc_apt_configure.apply_apt_config({'apt_proxy': "foo"},
74
78
                                          self.pfile, self.cfile)
75
79
        self.assertTrue(os.path.isfile(self.pfile))
76
 
        contents = util.load_tfile_or_url(self.pfile)
 
80
        contents = load_tfile_or_url(self.pfile)
77
81
        self.assertTrue(self._search_apt_config(contents, "http", "foo"))
78
82
 
79
83
    def test_config_written(self):
85
89
        self.assertTrue(os.path.isfile(self.cfile))
86
90
        self.assertFalse(os.path.isfile(self.pfile))
87
91
 
88
 
        self.assertEqual(util.load_tfile_or_url(self.cfile), payload)
 
92
        self.assertEqual(load_tfile_or_url(self.cfile), payload)
89
93
 
90
94
    def test_config_replaced(self):
91
95
        util.write_file(self.pfile, "content doesnt matter")
92
96
        cc_apt_configure.apply_apt_config({'apt_config': "foo"},
93
97
                                          self.pfile, self.cfile)
94
98
        self.assertTrue(os.path.isfile(self.cfile))
95
 
        self.assertEqual(util.load_tfile_or_url(self.cfile), "foo")
 
99
        self.assertEqual(load_tfile_or_url(self.cfile), "foo")
96
100
 
97
101
    def test_config_deleted(self):
98
102
        # if no 'apt_config' is provided, delete any previously written file