~nskaggs/juju-ci-tools/add-grant-to-rep-tests

« back to all changes in this revision

Viewing changes to tests/test_jujupy.py

  • Committer: Andrew Beach
  • Date: 2016-11-28 14:35:49 UTC
  • mfrom: (1757.3.3 rm-sudo-rest)
  • Revision ID: andrew.beach@canonical.com-20161128143549-ovvg9nzivta0m679
Merge: Removed needs_sudo and the sudo parameter from _full_args.

Show diffs side-by-side

added added

removed removed

Lines of Context:
601
601
    def test_full_args(self):
602
602
        env = JujuData('foo')
603
603
        client = EnvJujuClient(env, None, 'my/juju/bin')
604
 
        full = client._full_args('bar', False, ('baz', 'qux'))
 
604
        full = client._full_args('bar', ('baz', 'qux'))
605
605
        self.assertEqual(('bin', '--show-log', 'bar', '-m', 'foo:foo', 'baz',
606
606
                          'qux'), full)
607
 
        full = client._full_args('bar', True, ('baz', 'qux'))
 
607
        full = client._full_args('bar', ('baz', 'qux'))
608
608
        self.assertEqual((
609
609
            'bin', '--show-log', 'bar', '-m', 'foo:foo', 'baz', 'qux'), full)
610
 
        full = client._full_args('bar', True, ('baz', 'qux'), controller=True)
 
610
        full = client._full_args('bar',  ('baz', 'qux'), controller=True)
611
611
        self.assertEqual(
612
612
            ('bin', '--show-log', 'bar', '-m', 'foo:controller', 'baz', 'qux'),
613
613
            full)
614
614
        client.env = None
615
 
        full = client._full_args('bar', False, ('baz', 'qux'))
 
615
        full = client._full_args('bar', ('baz', 'qux'))
616
616
        self.assertEqual(('bin', '--show-log', 'bar', 'baz', 'qux'), full)
617
617
 
618
618
    def test_full_args_debug(self):
619
619
        env = JujuData('foo')
620
620
        client = EnvJujuClient(env, None, 'my/juju/bin', debug=True)
621
 
        full = client._full_args('bar', False, ('baz', 'qux'))
 
621
        full = client._full_args('bar', ('baz', 'qux'))
622
622
        self.assertEqual((
623
623
            'bin', '--debug', 'bar', '-m', 'foo:foo', 'baz', 'qux'), full)
624
624
 
625
625
    def test_full_args_action(self):
626
626
        env = JujuData('foo')
627
627
        client = EnvJujuClient(env, None, 'my/juju/bin')
628
 
        full = client._full_args('action bar', False, ('baz', 'qux'))
 
628
        full = client._full_args('action bar', ('baz', 'qux'))
629
629
        self.assertEqual(
630
630
            ('bin', '--show-log', 'action', 'bar', '-m', 'foo:foo',
631
631
             'baz', 'qux'),
636
636
        client = EnvJujuClient(env, None, 'my/juju/bin')
637
637
        with patch.object(client, 'get_controller_model_name',
638
638
                          return_value='controller') as gamn_mock:
639
 
            full = client._full_args('bar', False, ('baz', 'qux'),
640
 
                                     controller=True)
 
639
            full = client._full_args('bar', ('baz', 'qux'), controller=True)
641
640
        self.assertEqual((
642
641
            'bin', '--show-log', 'bar', '-m', 'foo:controller', 'baz', 'qux'),
643
642
            full)
794
793
    def test_bootstrap_upload_tools(self):
795
794
        env = JujuData('foo', {'type': 'foo', 'region': 'baz'})
796
795
        client = EnvJujuClient(env, '2.0-zeta1', None)
797
 
        with patch.object(client.env, 'needs_sudo', lambda: True):
798
 
            with observable_temp_file() as config_file:
799
 
                with patch.object(client, 'juju') as mock:
800
 
                    client.bootstrap(upload_tools=True)
801
 
            mock.assert_called_with(
802
 
                'bootstrap', (
803
 
                    '--upload-tools', '--constraints', 'mem=2G',
804
 
                    'foo/baz', 'foo',
805
 
                    '--config', config_file.name,
806
 
                    '--default-model', 'foo'), include_e=False)
 
796
        with observable_temp_file() as config_file:
 
797
            with patch.object(client, 'juju') as mock:
 
798
                client.bootstrap(upload_tools=True)
 
799
        mock.assert_called_with(
 
800
            'bootstrap', (
 
801
                '--upload-tools', '--constraints', 'mem=2G',
 
802
                'foo/baz', 'foo',
 
803
                '--config', config_file.name,
 
804
                '--default-model', 'foo'), include_e=False)
807
805
 
808
806
    def test_bootstrap_credential(self):
809
807
        env = JujuData('foo', {'type': 'foo', 'region': 'baz'})
3614
3612
    def test_full_args(self):
3615
3613
        env = SimpleEnvironment('foo')
3616
3614
        client = EnvJujuClient1X(env, None, 'my/juju/bin')
3617
 
        full = client._full_args('bar', False, ('baz', 'qux'))
 
3615
        full = client._full_args('bar', ('baz', 'qux'))
3618
3616
        self.assertEqual(('bin', '--show-log', 'bar', '-e', 'foo', 'baz',
3619
3617
                          'qux'), full)
3620
 
        full = client._full_args('bar', True, ('baz', 'qux'))
 
3618
        full = client._full_args('bar', ('baz', 'qux'))
3621
3619
        self.assertEqual((
3622
3620
            'bin', '--show-log', 'bar', '-e', 'foo',
3623
3621
            'baz', 'qux'), full)
3624
3622
        client.env = None
3625
 
        full = client._full_args('bar', False, ('baz', 'qux'))
 
3623
        full = client._full_args('bar', ('baz', 'qux'))
3626
3624
        self.assertEqual(('bin', '--show-log', 'bar', 'baz', 'qux'), full)
3627
3625
 
3628
3626
    def test_full_args_debug(self):
3629
3627
        env = SimpleEnvironment('foo')
3630
3628
        client = EnvJujuClient1X(env, None, 'my/juju/bin', debug=True)
3631
 
        full = client._full_args('bar', False, ('baz', 'qux'))
 
3629
        full = client._full_args('bar', ('baz', 'qux'))
3632
3630
        self.assertEqual((
3633
3631
            'bin', '--debug', 'bar', '-e', 'foo', 'baz', 'qux'), full)
3634
3632
 
3635
3633
    def test_full_args_controller(self):
3636
3634
        env = SimpleEnvironment('foo')
3637
3635
        client = EnvJujuClient1X(env, None, 'my/juju/bin')
3638
 
        full = client._full_args('bar', False, ('baz', 'qux'), controller=True)
 
3636
        full = client._full_args('bar', ('baz', 'qux'), controller=True)
3639
3637
        self.assertEqual((
3640
3638
            'bin', '--show-log', 'bar', '-e', 'foo', 'baz', 'qux'), full)
3641
3639
 
3642
3640
    def test_full_args_action(self):
3643
3641
        env = SimpleEnvironment('foo')
3644
3642
        client = EnvJujuClient1X(env, None, 'my/juju/bin')
3645
 
        full = client._full_args('action bar', False, ('baz', 'qux'))
 
3643
        full = client._full_args('action bar', ('baz', 'qux'))
3646
3644
        self.assertEqual((
3647
3645
            'bin', '--show-log', 'action', 'bar', '-e', 'foo', 'baz', 'qux'),
3648
3646
            full)
3674
3672
    def test_bootstrap_upload_tools(self):
3675
3673
        env = SimpleEnvironment('foo')
3676
3674
        client = EnvJujuClient1X(env, None, None)
3677
 
        with patch.object(client.env, 'needs_sudo', lambda: True):
3678
 
            with patch.object(client, 'juju') as mock:
3679
 
                client.bootstrap(upload_tools=True)
 
3675
        with patch.object(client, 'juju') as mock:
 
3676
            client.bootstrap(upload_tools=True)
3680
3677
        mock.assert_called_with(
3681
3678
            'bootstrap', ('--upload-tools', '--constraints', 'mem=2G'))
3682
3679
 
3753
3750
            create_cmd, controller_option + (
3754
3751
                'bar', '--config', config_file.name), include_e=False)
3755
3752
 
3756
 
    def test_destroy_environment_non_sudo(self):
3757
 
        env = SimpleEnvironment('foo', {'type': 'ec2'})
3758
 
        client = EnvJujuClient1X(env, None, None)
3759
 
        with patch.object(client.env, 'needs_sudo', lambda: False):
3760
 
            with patch.object(client, 'juju') as mock:
3761
 
                client.destroy_environment()
3762
 
            mock.assert_called_with(
3763
 
                'destroy-environment', ('foo', '--force', '-y'),
3764
 
                check=False, include_e=False, timeout=600)
3765
 
 
3766
 
    def test_destroy_environment_sudo(self):
3767
 
        env = SimpleEnvironment('foo', {'type': 'ec2'})
3768
 
        client = EnvJujuClient1X(env, None, None)
3769
 
        with patch.object(client.env, 'needs_sudo', lambda: True):
3770
 
            with patch.object(client, 'juju') as mock:
3771
 
                client.destroy_environment()
3772
 
            mock.assert_called_with(
3773
 
                'destroy-environment', ('foo', '--force', '-y'),
3774
 
                check=False, include_e=False, timeout=600)
 
3753
    def test_destroy_environment(self):
 
3754
        env = SimpleEnvironment('foo', {'type': 'ec2'})
 
3755
        client = EnvJujuClient1X(env, None, None)
 
3756
        with patch.object(client, 'juju') as mock:
 
3757
            client.destroy_environment()
 
3758
        mock.assert_called_with(
 
3759
            'destroy-environment', ('foo', '--force', '-y'),
 
3760
            check=False, include_e=False, timeout=600)
3775
3761
 
3776
3762
    def test_destroy_environment_no_force(self):
3777
3763
        env = SimpleEnvironment('foo', {'type': 'ec2'})