def test_wrap_up_noop(self, config_mock): config_mock().command = None config_mock().console = None keyman = Keyman(['foo', '-o', 'foo', '-u', 'bar', '-a', 'baz']) keyman.log = mock.MagicMock() keyman.wrap_up(None) keyman.log.assert_has_calls([mock.call.info('All done! 👍')])
def test_wrap_up_with_command(self, config_mock, os_mock): config_mock().command = 'echo w00t' keyman = Keyman(['foo', '-o', 'foo', '-u', 'bar', '-a', 'baz']) fake_session = mock.MagicMock() fake_session.export_creds_to_var_string.return_value = 'foo' keyman.wrap_up(fake_session) fake_session.assert_has_calls([mock.call.export_creds_to_var_string()]) os_mock.assert_has_calls([mock.call.system('foo echo w00t')])
def test_wrap_up_with_console(self, config_mock): config_mock().command = None config_mock().console = True config_mock().full_app_url.return_value = 'url' keyman = Keyman(['foo', '-o', 'foo', '-u', 'bar', '-a', 'baz']) session = mock.MagicMock() keyman.wrap_up(session) session.assert_has_calls([mock.call.generate_aws_console_url('url')]) config_mock.assert_has_calls([mock.call().full_app_url()])
def test_wrap_up_noop(self, config_mock): config_mock().command = None config_mock().console = None keyman = Keyman(["foo", "-o", "foo", "-u", "bar", "-a", "baz"]) keyman.log = mock.MagicMock() keyman.wrap_up(None) keyman.log.assert_has_calls( [ mock.call.info("All done! 👍"), ], )
def test_wrap_up_with_command(self, config_mock, os_mock): config_mock().command = "echo w00t" keyman = Keyman(["foo", "-o", "foo", "-u", "bar", "-a", "baz"]) fake_session = mock.MagicMock() fake_session.export_creds_to_var_string.return_value = "foo" keyman.wrap_up(fake_session) fake_session.assert_has_calls( [ mock.call.export_creds_to_var_string(), ], ) os_mock.assert_has_calls( [ mock.call.system("foo echo w00t"), ], )
def test_wrap_up_with_console(self, config_mock): config_mock().command = None config_mock().console = True config_mock().full_app_url.return_value = "url" keyman = Keyman(["foo", "-o", "foo", "-u", "bar", "-a", "baz"]) session = mock.MagicMock() keyman.wrap_up(session) session.assert_has_calls( [ mock.call.generate_aws_console_url("url"), ], ) config_mock.assert_has_calls( [ mock.call().full_app_url(), ], )
def test_aws_auth_loop(self, config_mock): config_mock().reup = False keyman = Keyman(['foo', '-o', 'foo', '-u', 'bar', '-a', 'baz']) keyman.start_session = mock.MagicMock() keyman.wrap_up = mock.MagicMock() keyman.aws_auth_loop() keyman.start_session.assert_has_calls( [mock.call(), mock.call().assume_role(mock.ANY)]) assert keyman.wrap_up.called
def test_aws_auth_loop(self, config_mock): config_mock().reup = False keyman = Keyman(["foo", "-o", "foo", "-u", "bar", "-a", "baz"]) keyman.start_session = mock.MagicMock() keyman.wrap_up = mock.MagicMock() keyman.handle_multiple_roles = mock.MagicMock() keyman.handle_multiple_roles.return_value = True keyman.aws_auth_loop() keyman.start_session.assert_has_calls( [ mock.call(), mock.call().assume_role(mock.ANY), ], ) assert keyman.wrap_up.called assert keyman.handle_multiple_roles.called