~jani/ubuntu-system-image/http-auth

« back to all changes in this revision

Viewing changes to systemimage/tests/test_config.py

  • Committer: Barry Warsaw
  • Date: 2014-02-26 19:22:13 UTC
  • mfrom: (240.2.4 lp1278589)
  • Revision ID: barry@python.org-20140226192213-uooc2f52ibfog635
 * Support disabling either the HTTP or HTTPS services for update (but not
   both).  The ``[service]http_port`` or ``[service]https_port`` may be set to
   the string ``disabled`` and the disabled protocol will fall back to the
   enabled protocol.  Implementation given by Vojtech Bocek.  (LP: #1278589)
 * Allow the channel.ini file to override the ``[service]`` section.

Show diffs side-by-side

added added

removed removed

Lines of Context:
136
136
        self.assertEqual(config.service.https_base,
137
137
                         'https://phablet.example.com:80443')
138
138
 
 
139
    def test_disabled_http_port(self):
 
140
        # config_05.ini has http port disabled and non-standard https port.
 
141
        ini_file = data_path('config_05.ini')
 
142
        config = Configuration()
 
143
        config.load(ini_file)
 
144
        self.assertEqual(config.service.base, 'phablet.example.com')
 
145
        self.assertEqual(config.service.http_base,
 
146
                         'https://phablet.example.com:80443')
 
147
        self.assertEqual(config.service.https_base,
 
148
                         'https://phablet.example.com:80443')
 
149
 
 
150
    def test_disabled_https_port(self):
 
151
        # config_06.ini has https port disabled and standard http port.
 
152
        ini_file = data_path('config_06.ini')
 
153
        config = Configuration()
 
154
        config.load(ini_file)
 
155
        self.assertEqual(config.service.base, 'phablet.example.com')
 
156
        self.assertEqual(config.service.http_base,
 
157
                         'http://phablet.example.com')
 
158
        self.assertEqual(config.service.https_base,
 
159
                         'http://phablet.example.com')
 
160
 
 
161
    def test_both_ports_disabled(self):
 
162
        # config_07.ini has both http and https ports disabled.
 
163
        ini_file = data_path('config_07.ini')
 
164
        config = Configuration()
 
165
        with self.assertRaises(ValueError) as cm:
 
166
            config.load(ini_file)
 
167
        self.assertEqual(cm.exception.args[0],
 
168
                         'Cannot disable both http and https ports')
 
169
 
 
170
    def test_negative_port_number(self):
 
171
        # config_08.ini has a negative port number.
 
172
        ini_file = data_path('config_08.ini')
 
173
        config = Configuration()
 
174
        with self.assertRaises(ValueError) as cm:
 
175
            config.load(ini_file)
 
176
        self.assertEqual(cm.exception.args[0], '-1')
 
177
 
139
178
    @configuration
140
179
    def test_get_build_number(self, ini_file):
141
180
        # The current build number is stored in a file specified in the
233
272
        self.assertEqual(config.service.channel, 'proposed')
234
273
        self.assertEqual(config.service.build_number, 1833)
235
274
 
 
275
    def test_channel_ini_may_override_system_section(self):
 
276
        # Overrides may include the [system] section.
 
277
        default_ini = resource_filename('systemimage.data', 'client.ini')
 
278
        config = Configuration()
 
279
        config.load(default_ini)
 
280
        channel_ini = data_path('channel_02.ini')
 
281
        config.load(channel_ini, override=True)
 
282
        self.assertEqual(config.system.build_file,
 
283
                         '/etc/path/to/alternative/build-file')
 
284
        # But other [system] settings which come from client.ini are unchanged.
 
285
        self.assertEqual(config.system.settings_db,
 
286
                         '/var/lib/system-image/settings.db')
 
287
 
236
288
    def test_channel_ini_ignored_sections(self):
237
 
        # Only the [service] section in channel.ini is used.
 
289
        # Only the [service] and [system] section in channel.ini is used.
238
290
        default_ini = resource_filename('systemimage.data', 'client.ini')
239
291
        config = Configuration()
240
292
        config.load(default_ini)
241
 
        channel_ini = resource_filename(
242
 
            'systemimage.tests.data', 'channel_02.ini')
 
293
        channel_ini = data_path('channel_02.ini')
243
294
        config.load(channel_ini, override=True)
244
 
        self.assertEqual(config.system.build_file, '/etc/ubuntu-build')
 
295
        # channel_02.ini sets this to 1h, but it's not overridden.
 
296
        self.assertEqual(config.dbus.lifetime, timedelta(minutes=10))
245
297
 
246
298
    def test_tempdir(self):
247
299
        # config.tempdir is randomly created.