OLD | NEW |
1 # This file is part of the Juju Quickstart Plugin, which lets users set up a | 1 # This file is part of the Juju Quickstart Plugin, which lets users set up a |
2 # Juju environment in very few steps (https://launchpad.net/juju-quickstart). | 2 # Juju environment in very few steps (https://launchpad.net/juju-quickstart). |
3 # Copyright (C) 2013-2014 Canonical Ltd. | 3 # Copyright (C) 2013-2014 Canonical Ltd. |
4 # | 4 # |
5 # This program is free software: you can redistribute it and/or modify it under | 5 # This program is free software: you can redistribute it and/or modify it under |
6 # the terms of the GNU Affero General Public License version 3, as published by | 6 # the terms of the GNU Affero General Public License version 3, as published by |
7 # the Free Software Foundation. | 7 # the Free Software Foundation. |
8 # | 8 # |
9 # This program is distributed in the hope that it will be useful, but WITHOUT | 9 # This program is distributed in the hope that it will be useful, but WITHOUT |
10 # ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, | 10 # ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, |
(...skipping 554 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
565 # calculate the timeout, the second one for the first status check, | 565 # calculate the timeout, the second one for the first status check, |
566 # the third for the second status check, the fourth should fail. | 566 # the third for the second status check, the fourth should fail. |
567 with mock.patch('time.time', mock_time): | 567 with mock.patch('time.time', mock_time): |
568 with self.assert_program_exit(expected): | 568 with self.assert_program_exit(expected): |
569 app.bootstrap(self.env_name) | 569 app.bootstrap(self.env_name) |
570 mock_call.assert_has_calls([ | 570 mock_call.assert_has_calls([ |
571 mock.call(settings.JUJU_CMD, 'bootstrap', '-e', self.env_name), | 571 mock.call(settings.JUJU_CMD, 'bootstrap', '-e', self.env_name), |
572 ] + self.make_status_calls(2)) | 572 ] + self.make_status_calls(2)) |
573 | 573 |
574 | 574 |
575 class TestGetAdminSecret(unittest.TestCase): | 575 class TestGetValueFromJenv(unittest.TestCase): |
576 | 576 |
577 def test_no_admin_secret(self): | 577 def test_no_key(self): |
578 with mock.patch('quickstart.manage.envs.load_generated', | 578 with mock.patch('quickstart.manage.envs.load_generated', |
579 lambda x: {}): | 579 lambda x: {}): |
580 with self.assertRaises(ValueError) as exc: | 580 with self.assertRaises(ValueError) as exc: |
581 app.get_admin_secret('local', '/home/bac/.juju') | 581 app.get_value_from_jenv( |
| 582 'local', '/home/bac/.juju', 'my-key') |
582 expected = ( | 583 expected = ( |
583 u'admin-secret not found in ' | 584 u'my-key not found in ' |
584 '/home/bac/.juju/environments/local.jenv') | 585 '/home/bac/.juju/environments/local.jenv') |
585 self.assertIn(expected, bytes(exc.exception)) | 586 self.assertIn(expected, bytes(exc.exception)) |
586 | 587 |
587 def test_success(self): | 588 def test_success(self): |
588 expected = 'superchunk' | 589 expected = 'superchunk' |
589 with mock.patch('quickstart.manage.envs.load_generated', | 590 with mock.patch('quickstart.manage.envs.load_generated', |
590 lambda x: {'admin-secret': expected}): | 591 lambda x: {'my-key': expected}): |
591 secret = app.get_admin_secret('local', '~bac/.juju') | 592 secret = app.get_value_from_jenv( |
| 593 'local', '~bac/.juju', 'my-key') |
592 self.assertEqual(expected, secret) | 594 self.assertEqual(expected, secret) |
593 | 595 |
594 | 596 |
595 class TestGetApiUrl( | 597 class TestGetApiUrl( |
596 helpers.CallTestsMixin, ProgramExitTestsMixin, unittest.TestCase): | 598 helpers.CallTestsMixin, ProgramExitTestsMixin, unittest.TestCase): |
597 | 599 |
598 env_name = 'ec2' | 600 env_name = 'ec2' |
599 | 601 |
600 def test_success(self): | 602 def test_success(self): |
601 # The API URL is correctly returned. | 603 # The API URL is correctly returned. |
(...skipping 825 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1427 app.deploy_bundle(env, self.yaml, self.name, self.bundle_id) | 1429 app.deploy_bundle(env, self.yaml, self.name, self.bundle_id) |
1428 | 1430 |
1429 def test_other_errors(self): | 1431 def test_other_errors(self): |
1430 # Any other errors occurred during the process are not trapped. | 1432 # Any other errors occurred during the process are not trapped. |
1431 env = mock.Mock() | 1433 env = mock.Mock() |
1432 error = ValueError('explode!') | 1434 error = ValueError('explode!') |
1433 env.deploy_bundle.side_effect = error | 1435 env.deploy_bundle.side_effect = error |
1434 with self.assertRaises(ValueError) as context_manager: | 1436 with self.assertRaises(ValueError) as context_manager: |
1435 app.deploy_bundle(env, self.yaml, self.name, None) | 1437 app.deploy_bundle(env, self.yaml, self.name, None) |
1436 self.assertIs(error, context_manager.exception) | 1438 self.assertIs(error, context_manager.exception) |
OLD | NEW |