Пример #1
0
 def test_host_input_data_rotate_api_key_is_printed_as_dict_properly_when_action_is_empty(
         self):
     EXPECTED_REP_OBJECT = {'host': 'somehost'}
     mock_host_resource_data = HostResourceData(action=None,
                                                host_to_update='somehost')
     rep_obj = mock_host_resource_data.__repr__()
     self.assertEquals(str(EXPECTED_REP_OBJECT), rep_obj)
Пример #2
0
 def test_host_data_constructor(self):
     mock_action = None
     mock_host_to_update = None
     host_resource_data = HostResourceData(
         action=mock_action, host_to_update=mock_host_to_update)
     self.assertEquals(host_resource_data.action, mock_action)
     self.assertEquals(host_resource_data.host_to_update,
                       mock_host_to_update)
 def test_user_does_not_provide_host_id_raises_exception(self):
     mock_client = Client
     mock_host_resource_data = HostResourceData(action='someaction',
                                                host_to_update=None)
     mock_host_controller = HostController(mock_client,
                                           mock_host_resource_data)
     # Raise error that the ID is required
     with self.assertRaises(MissingRequiredParameterException):
         with patch('builtins.input', return_value=''):
             mock_host_controller.prompt_for_host_id_if_needed()
             assert mock_host_resource_data.host_to_update == ''
    def test_rotate_api_key_calls_necessary_functions(self, mock_client):
        mock_host_resource_data = HostResourceData(action='someaction',
                                                   host_to_update='somehost')
        mock_host_controller = HostController(mock_client,
                                              mock_host_resource_data)
        mock_host_controller.prompt_for_host_id_if_needed = MagicMock()
        mock_host_controller.client.rotate_other_api_key = MagicMock()
        mock_host_controller.rotate_api_key()
        mock_host_controller.prompt_for_host_id_if_needed.assert_called_once()

        mock_host_controller.client.rotate_other_api_key.assert_called_once_with(
            Resource(kind='host',
                     identifier=mock_host_resource_data.host_to_update))
class HostControllerTest(unittest.TestCase):
    client = Client
    host_resource_data = HostResourceData(action='someaction',
                                          host_to_update='somehost')
    host_controller = HostController(client, host_resource_data)

    def test_host_controller_constructor(self):
        mock_client = None
        mock_host_resource_data = None
        host_controller = HostController(mock_client, mock_host_resource_data)
        assert host_controller.client == mock_client
        assert host_controller.host_resource_data == mock_host_resource_data

    @patch('conjur_api.Client')
    def test_rotate_api_key_calls_necessary_functions(self, mock_client):
        mock_host_resource_data = HostResourceData(action='someaction',
                                                   host_to_update='somehost')
        mock_host_controller = HostController(mock_client,
                                              mock_host_resource_data)
        mock_host_controller.prompt_for_host_id_if_needed = MagicMock()
        mock_host_controller.client.rotate_other_api_key = MagicMock()
        mock_host_controller.rotate_api_key()
        mock_host_controller.prompt_for_host_id_if_needed.assert_called_once()

        mock_host_controller.client.rotate_other_api_key.assert_called_once_with(
            Resource(kind='host',
                     identifier=mock_host_resource_data.host_to_update))

    def test_user_does_not_provide_host_id_raises_exception(self):
        mock_client = Client
        mock_host_resource_data = HostResourceData(action='someaction',
                                                   host_to_update=None)
        mock_host_controller = HostController(mock_client,
                                              mock_host_resource_data)
        # Raise error that the ID is required
        with self.assertRaises(MissingRequiredParameterException):
            with patch('builtins.input', return_value=''):
                mock_host_controller.prompt_for_host_id_if_needed()
                assert mock_host_resource_data.host_to_update == ''