~techalchemy/mojo/python3-fixes

« back to all changes in this revision

Viewing changes to mojo/tests/test_phase.py

  • Committer: Dan Ryan
  • Date: 2020-02-03 23:44:35 UTC
  • mfrom: (514.2.10 mojo)
  • Revision ID: dan.ryan@canonical.com-20200203234435-294dc1iv5frgv7ep
* [mthaddon] If series is focal, juju deploy needs --force option
* [mthaddon] Deal with charm lines that include quotes for charmstore locations
* [mthaddon] Disable debug-logs by default - tends to simply clutter logs
* [mthaddon] Update supported series for PPAs and remove need to create MOJO_ROOT
* [mthaddon] Only check for charm repo if we're using non-Charmstore charms

Show diffs side-by-side

added added

removed removed

Lines of Context:
40
40
 
41
41
    @mock.patch('mojo.phase.bicommand')
42
42
    @mock.patch('mojo.phase.DeployerPhase._confirm_charm_repo')
 
43
    @mock.patch('mojo.phase.DeployerPhase._only_charmstore_charms')
43
44
    @mock.patch('mojo.phase.DeployerPhase._get_target')
44
45
    @mock.patch('mojo.juju.Status.check_and_wait')
45
46
    @mock.patch('mojo.phase.DeployerPhase._get_command')
46
47
    def get_deployer_command_for_run(self, phase, workspace, stage, _get_command, _check_wait,
47
 
                                     _get_target, _confirm_charm_repo, _bicommand):
 
48
                                     _get_target, _only_charmstore_charms, _confirm_charm_repo, _bicommand):
 
49
        _only_charmstore_charms.return_value = False
48
50
        _get_target.return_value = "testTarget"
49
51
        _bicommand.return_value = (0, u'fake-output')
50
52
        _get_command.return_value = "juju-deployer"
56
58
 
57
59
    @mock.patch('subprocess.call')
58
60
    @mock.patch('mojo.phase.DeployerPhase._confirm_charm_repo')
 
61
    @mock.patch('mojo.phase.DeployerPhase._only_charmstore_charms')
59
62
    @mock.patch('mojo.phase.DeployerPhase._get_target')
60
63
    @mock.patch('mojo.juju.Status.check_and_wait')
61
64
    @mock.patch('mojo.phase.DeployerPhase._get_command')
62
65
    def get_deployer_command_for_diff(self, phase, workspace, stage, _get_command, _check_wait,
63
 
                                      _get_target, _confirm_charm_repo, _call):
 
66
                                      _get_target, _only_charmstore_charms, _confirm_charm_repo, _call):
 
67
        _only_charmstore_charms.return_value = False
64
68
        _get_target.return_value = "testTarget"
65
69
        _call.return_value = (0)
66
70
        _get_command.return_value = "juju-deployer"
76
80
 
77
81
    @mock.patch('subprocess.call')
78
82
    @mock.patch('mojo.phase.DeployerPhase._confirm_charm_repo')
 
83
    @mock.patch('mojo.phase.DeployerPhase._only_charmstore_charms')
79
84
    @mock.patch('mojo.phase.DeployerPhase._get_target')
80
85
    @mock.patch('mojo.juju.Status.check_and_wait')
81
86
    @mock.patch('mojo.phase.DeployerPhase._get_command')
82
87
    def get_deployer_output_for_show(self, phase, workspace, stage, target, _get_command, _check_wait,
83
 
                                     _get_target, _confirm_charm_repo, _call):
 
88
                                     _get_target, _only_charmstore_charms, _confirm_charm_repo, _call):
 
89
        _only_charmstore_charms.return_value = False
84
90
        _get_target.return_value = target
85
91
        _call.return_value = (0)
86
92
        _get_command.return_value = "juju-deployer"
313
319
        called_methods = [c[0] for c in secrets.mock_calls]
314
320
        assert ('().run' in called_methods)
315
321
 
 
322
    @mock.patch('mojo.phase.SecretsPhase')
 
323
    def test_only_charmstore_charms(self, _secrets):
 
324
        phase = DeployerPhase(config='services.cfg', target='test')
 
325
        self.assertFalse(phase._only_charmstore_charms(['mojo/tests/testdata/deploy-config-local-charms.yaml']))
 
326
        self.assertTrue(phase._only_charmstore_charms(['mojo/tests/testdata/deploy-config-charmstore-charms.yaml']))
 
327
        # We should return false (i.e. not *only* charmstore charms) if
 
328
        # there's a mix of local and charmstore charms.
 
329
        self.assertFalse(phase._only_charmstore_charms(['mojo/tests/testdata/deploy-config-mixed-charms.yaml']))
 
330
 
 
331
    @mock.patch('mojo.phase.get_dep_prog')
 
332
    def test_get_command(self, _get_dep_prog):
 
333
        def mock_get_prog(value):
 
334
            return value
 
335
 
 
336
        _get_dep_prog.side_effect = mock_get_prog
 
337
        phase = DeployerPhase(config='services.cfg', target='test')
 
338
        self.assertEqual(phase._get_command('focal'), 'juju-deployer')
 
339
 
316
340
 
317
341
class BundlePhaseTestCase(TestCase, utils.MojoTestCaseMixin):
318
342
 
452
476
        called_methods = [c[0] for c in secrets.mock_calls]
453
477
        assert ('().run' in called_methods)
454
478
 
 
479
    @mock.patch('distro_info.UbuntuDistroInfo.devel')
 
480
    @mock.patch('mojo.phase.get_dep_prog')
 
481
    def test_get_command(self, _get_dep_prog, _devel):
 
482
        def mock_get_prog(value):
 
483
            return value
 
484
 
 
485
        _get_dep_prog.side_effect = mock_get_prog
 
486
        _devel.return_value = "focal"
 
487
        phase = BundlePhase(config='services.cfg', target='test')
 
488
 
 
489
        self.assertEqual(phase._get_command('focal'), 'juju deploy --force')
 
490
        self.assertEqual(phase._get_command('bionic'), 'juju deploy')
 
491
 
 
492
 
455
493
 
456
494
class CollectPhaseTestCase(TestCase, utils.MojoTestCaseMixin):
457
495