def test_help(self): fake_stdout = StringIO.StringIO() with parse_error(self) as fake_stderr: with patch("sys.stdout", fake_stdout): amm.parse_args(["--help"]) self.assertEqual("", fake_stderr.getvalue()) self.assertIn("Test model migration feature", fake_stdout.getvalue())
def test_help(self): fake_stdout = StringIO.StringIO() with parse_error(self) as fake_stderr: with patch("sys.stdout", fake_stdout): amm.parse_args(["--help"]) self.assertEqual("", fake_stderr.getvalue()) self.assertIn( "Test model migration feature", fake_stdout.getvalue())
def test_main(self): argv = ["an-env", "/bin/juju", "/tmp/logs", "an-env-mod", "--verbose"] bs_1 = Mock() bs_2 = Mock() with patch.object(amm, "configure_logging", autospec=True) as mock_cl: with patch.object(amm, "assess_model_migration", autospec=True) as mock_assess: with patch.object(amm, "get_bootstrap_managers", return_value=[bs_1, bs_2]): amm.main(argv) mock_cl.assert_called_once_with(logging.DEBUG) mock_assess.assert_called_once_with(bs_1, bs_2, amm.parse_args(argv))
def test_runs_develop_tests_when_requested(self): argv = [ 'an-env', '/bin/juju', '/tmp/logs', 'an-env-mod', '--use-develop'] args = amm.parse_args(argv) bs1 = Mock() bs2 = Mock() bs1.booted_context.return_value = noop_context() bs2.existing_booted_context.return_value = noop_context() patch_user_tests = patch_amm('assess_user_permission_model_migrations') patch_dev_tests = patch_amm('assess_development_branch_migrations') patch_between = patch_amm( 'ensure_migration_with_resources_succeeds') patch_rollback = patch_amm('ensure_migration_rolls_back_on_failure') patch_logs = patch_amm('ensure_model_logs_are_migrated') patch_assert_migrated = patch_amm('assert_model_migrated_successfully') patch_21_client = patch_amm('client_is_at_least_2_1') mig_client = Mock() app = 'application' resource_string = 'resource' with patch_user_tests as m_user: with patch_between as m_between: m_between.return_value = mig_client, app, resource_string with patch_rollback as m_rollback: with patch_logs as m_logs: with patch_assert_migrated as m_am: with patch_dev_tests as m_dev_tests: with patch_21_client as m_21: m_21.return_value = True amm.assess_model_migration(bs1, bs2, args) source_client = bs2.client dest_client = bs1.client m_user.assert_called_once_with(source_client, dest_client) m_between.assert_called_once_with(source_client, dest_client) m_logs.assert_called_once_with(source_client, dest_client) m_am.assert_called_once_with(mig_client, app, resource_string) m_dev_tests.assert_called_once_with(source_client, dest_client) self.assertEqual(m_rollback.call_count, 0)
def test_runs_develop_tests_when_requested(self): argv = [ 'an-env', '/bin/juju', '/tmp/logs', 'an-env-mod', '--use-develop' ] args = amm.parse_args(argv) bs1 = Mock() bs2 = Mock() bs1.booted_context.return_value = noop_context() bs2.existing_booted_context.return_value = noop_context() patch_user_tests = patch_amm('assess_user_permission_model_migrations') patch_dev_tests = patch_amm('assess_development_branch_migrations') patch_between = patch_amm('ensure_migration_with_resources_succeeds') patch_rollback = patch_amm('ensure_migration_rolls_back_on_failure') patch_logs = patch_amm('ensure_model_logs_are_migrated') patch_assert_migrated = patch_amm('assert_model_migrated_successfully') patch_21_client = patch_amm('client_is_at_least_2_1') mig_client = Mock() app = 'application' resource_string = 'resource' with patch_user_tests as m_user: with patch_between as m_between: m_between.return_value = mig_client, app, resource_string with patch_rollback as m_rollback: with patch_logs as m_logs: with patch_assert_migrated as m_am: with patch_dev_tests as m_dev_tests: with patch_21_client as m_21: m_21.return_value = True amm.assess_model_migration(bs1, bs2, args) source_client = bs2.client dest_client = bs1.client m_user.assert_called_once_with(source_client, dest_client) m_between.assert_called_once_with(source_client, dest_client) m_logs.assert_called_once_with(source_client, dest_client) m_am.assert_called_once_with(mig_client, app, resource_string) m_dev_tests.assert_called_once_with(source_client, dest_client) self.assertEqual(m_rollback.call_count, 0)
def test_default_args(self): args = amm.parse_args( ["an-env", "/bin/juju", "/tmp/logs", "an-env-mod"]) self.assertEqual( args, argparse.Namespace( env="an-env", juju_bin='/bin/juju', logs='/tmp/logs', temp_env_name='an-env-mod', use_develop=False, debug=False, agent_stream=None, agent_url=None, bootstrap_host=None, keep_env=False, machine=[], region=None, series=None, to=None, upload_tools=False, verbose=20, deadline=None, ))