~rharding/charms/precise/juju-gui/update-nagios

« back to all changes in this revision

Viewing changes to tests/test_helpers.py

  • Committer: Rick Harding
  • Date: 2014-01-15 14:50:46 UTC
  • mfrom: (147.1.8 remove-pyjuju)
  • Revision ID: rick.harding@canonical.com-20140115145046-lyh9879k9x8hwb8i
Remove support for PyJuju and rapi from charm.

- Removes the support for running rapi/pyjuju.
- Removes the agent used to communicate with zookeeper.
- Removes anything pertaining to zookeeper.
- Attempts to clean up docs and such to make sense with pure juju-core.

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
import json
21
21
import os
22
22
import shutil
23
 
import subprocess
24
23
import tempfile
25
24
import unittest
26
25
 
34
33
    juju_destroy_service,
35
34
    juju_env,
36
35
    juju_status,
37
 
    juju_version,
38
36
    ProcessError,
39
37
    retry,
40
38
    stop_services,
41
 
    Version,
42
39
    wait_for_unit,
43
40
    WebSocketClient,
44
41
)
203
200
        mock_juju.assert_called_once_with('status', '--format', 'json')
204
201
 
205
202
 
206
 
@mock.patch('subprocess.check_output')
207
 
class TestJujuVersion(unittest.TestCase):
208
 
 
209
 
    error = subprocess.CalledProcessError(2, 'invalid flag', 'output')
210
 
 
211
 
    def test_pyjuju(self, mock_check_output):
212
 
        # The pyJuju version is correctly retrieved.
213
 
        mock_check_output.return_value = '0.7.2'
214
 
        version = juju_version()
215
 
        self.assertEqual(Version(0, 7, 2), version)
216
 
        mock_check_output.assert_called_once_with(
217
 
            ['juju', '--version'], stderr=subprocess.STDOUT,
218
 
        )
219
 
 
220
 
    def test_juju_core(self, mock_check_output):
221
 
        # The juju-core version is correctly retrieved.
222
 
        mock_check_output.side_effect = (self.error, '1.12.3')
223
 
        version = juju_version()
224
 
        self.assertEqual(Version(1, 12, 3), version)
225
 
        self.assertEqual(2, mock_check_output.call_count)
226
 
        first_call, second_call = mock_check_output.call_args_list
227
 
        self.assertEqual(
228
 
            mock.call(['juju', '--version'], stderr=subprocess.STDOUT),
229
 
            first_call,
230
 
        )
231
 
        self.assertEqual(mock.call(['juju', 'version']), second_call)
232
 
 
233
 
    def test_not_semantic_versioning(self, mock_check_output):
234
 
        # If the patch number is missing, it is set to zero.
235
 
        mock_check_output.return_value = '0.7'
236
 
        version = juju_version()
237
 
        self.assertEqual(Version(0, 7, 0), version)
238
 
 
239
 
    def test_prefix(self, mock_check_output):
240
 
        # The function handles versions returned as "juju x.y.z".
241
 
        mock_check_output.return_value = 'juju 0.8.3'
242
 
        version = juju_version()
243
 
        self.assertEqual(Version(0, 8, 3), version)
244
 
 
245
 
    def test_suffix(self, mock_check_output):
246
 
        # The function handles versions returned as "x.y.z-series-arch".
247
 
        mock_check_output.return_value = '1.10.3-raring-amd64'
248
 
        version = juju_version()
249
 
        self.assertEqual(Version(1, 10, 3), version)
250
 
 
251
 
    def test_all(self, mock_check_output):
252
 
        # Additional information is correctly handled.
253
 
        mock_check_output.side_effect = (self.error, 'juju 1.234-precise-i386')
254
 
        version = juju_version()
255
 
        self.assertEqual(Version(1, 234, 0), version)
256
 
        self.assertEqual(2, mock_check_output.call_count)
257
 
 
258
 
    def test_invalid_version(self, mock_check_output):
259
 
        # A ValueError is raised if the returned version is not valid.
260
 
        mock_check_output.return_value = '42'
261
 
        with self.assertRaises(ValueError) as info:
262
 
            juju_version()
263
 
        self.assertEqual("invalid juju version: '42'", str(info.exception))
264
 
 
265
 
    def test_failure(self, mock_check_output):
266
 
        # A CalledProcessError is raised if the Juju version cannot be found.
267
 
        mock_check_output.side_effect = (self.error, self.error)
268
 
        with self.assertRaises(subprocess.CalledProcessError) as info:
269
 
            juju_version()
270
 
        self.assertIs(self.error, info.exception)
271
 
        self.assertEqual(2, mock_check_output.call_count)
272
 
 
273
 
 
274
203
class TestProcessError(unittest.TestCase):
275
204
 
276
205
    def test_str(self):