Exemplo n.º 1
0
    def test_positive_report_help(self):
        """hammer level of help included in test:
         Base level hammer help includes report-templates,
         Command level hammer help contains usage details,
         Subcommand level hammer help contains usage details

        :id: ec395f47-a55f-441a-9cc6-e49400c83e8e

        :setup: Any satellite user

        :steps:

            1. hammer --help
            2. hammer report-template --help
            3. hammer report-template create --help

        :expectedresults: report-templates command is included in help,
                          report-templates command details are displayed,
                          report-templates create command details are displayed

        :CaseImportance: High
        """
        base = Base().execute('--help')
        self.assertGreater(len([i for i in base if 'report-template' in i]), 0)
        base = Base().execute('report-template --help')
        self.assertGreater(len([i for i in base if 'hammer report-template' in i]), 0)
        self.assertGreater(len([i for i in base if 'info' and 'report template' in i]), 0)
        self.assertGreater(len([i for i in base if 'generate' and 'report' in i]), 0)
        base = Base().execute('report-template create --help')
        self.assertGreater(len([i for i in base if 'hammer report-template create' in i]), 0)
        self.assertGreater(len([i for i in base if '--audit-comment' in i]), 0)
        self.assertGreater(len([i for i in base if '--interactive' in i]), 0)
Exemplo n.º 2
0
 def test_handle_response_success(self):
     """Check handle_response returns stdout when the is no problem on ssh
     execution
     """
     base = Base()
     response = mock.Mock()
     response.return_code = 0
     response.stderr = []
     self.assertEqual(response.stdout, base._handle_response(response))
Exemplo n.º 3
0
 def test_handle_response_success(self):
     """Check handle_response returns stdout when the is no problem on ssh
     execution
     """
     base = Base()
     response = mock.Mock()
     response.status = 0
     response.stderr = []
     assert response.stdout == base._handle_response(response)
Exemplo n.º 4
0
 def test_add_create_with_result_dct_id_required_org_error(self, construct, execute):
     """Check command create when result has dct id key and organization
     is required but is not present
     """
     execute.return_value = [{'id': 'foo', 'bar': 'bas'}]
     Base.command_requires_org = True
     with pytest.raises(CLIError):
         Base.create()
     assert 'create' == Base.command_sub
     construct.called_once_with({})
     execute.called_once_with(construct.return_value, output_format='csv')
Exemplo n.º 5
0
 def test_handle_response_logging_when_stderr_not_empty(self, warning):
     """Check handle_response log stderr when it is not empty"""
     base = Base()
     response = mock.Mock()
     response.status = 0
     response.stderr = ['not empty']
     assert response.stdout == base._handle_response(response)
     warning.assert_called_once_with(f'stderr contains following message:\n{response.stderr}')
     warning.reset_mock()
     assert response.stdout == base._handle_response(response, True)
     assert not warning.called, 'Should not be called when ignore_stderr is True'
Exemplo n.º 6
0
 def assert_response_error(self, expected_error, stderr='some error'):
     """Check error is raised when handling cli response
     :param expected_error: expected error (class)
     :param stderr: error present on stderr (str)
     :return:
     """
     base = Base()
     response = mock.Mock()
     response.status = 1
     response.stderr = [stderr]
     with pytest.raises(expected_error):
         base._handle_response(response)
Exemplo n.º 7
0
 def test_handle_response_logging_when_stderr_not_empty(self, warning):
     """Check handle_response log stderr when it is not empty"""
     base = Base()
     response = mock.Mock()
     response.return_code = 0
     response.stderr = [u'not empty']
     self.assertEqual(response.stdout, base._handle_response(response))
     warning.assert_called_once_with(
         u'stderr contains following message:\n{}'.format(response.stderr))
     warning.reset_mock()
     self.assertEqual(response.stdout,
                      base._handle_response(response, True))
     self.assertFalse(warning.called,
                      u'Should not be called when ignore_stderr is True')
Exemplo n.º 8
0
    def test_with_user(self):
        """Check if ``with_user`` method returns a right wrapper class"""
        new_class = Base.with_user('auser', 'apass')

        self.assertEqual(new_class.foreman_admin_username, 'auser')
        self.assertEqual(new_class.foreman_admin_password, 'apass')
        self.assertIn(Base, new_class.__bases__)
Exemplo n.º 9
0
 def test_add_create_with_empty_result(self, construct, execute):
     """Check command create when result is empty"""
     execute.return_value = []
     assert execute.return_value == Base.create()
     assert 'create' == Base.command_sub
     construct.called_once_with({})
     execute.called_once_with(construct.return_value, output_format='csv')
Exemplo n.º 10
0
 def test_exists_with_option_and_no_empty_return(self, lst_method):
     """Check exists method with options and no empty return"""
     lst_method.return_value = [1, 2]
     my_options = {'search': 'foo=bar'}
     response = Base.exists(my_options, search=['id', 1])
     lst_method.assert_called_once_with(my_options)
     assert 1 == response
Exemplo n.º 11
0
 def test_list_with_default_per_page(self, construct, execute):
     """Check list method set per_page as 1000 by default"""
     assert execute.return_value == Base.list(
         options={'organization-id': 1})
     assert 'list' == Base.command_sub
     construct.called_once_with({'per-page': 1000})
     execute.called_once_with(construct.return_value, output_format='csv')
Exemplo n.º 12
0
 def test_exists_with_option_and_no_empty_return(self, lst_method):
     """Check exists method with options and no empty return"""
     lst_method.return_value = [1, 2]
     my_options = {u'search': u'foo=bar'}
     response = Base.exists(my_options, search=['id', 1])
     lst_method.assert_called_once_with(my_options)
     self.assertEqual(1, response)
Exemplo n.º 13
0
    def test_with_user(self):
        """Check if ``with_user`` method returns a right wrapper class"""
        new_class = Base.with_user('auser', 'apass')

        assert new_class.foreman_admin_username == 'auser'
        assert new_class.foreman_admin_password == 'apass'
        assert Base in new_class.__bases__
Exemplo n.º 14
0
 def test_handle_response_error(self):
     """Check handle_response raise ``CLIReturnCodeError`` when
     return_code is not 0
     """
     base = Base()
     response = mock.Mock()
     response.return_code = 1
     self.assertRaises(CLIReturnCodeError, base._handle_response, response)
Exemplo n.º 15
0
 def test_add_create_with_result_dct_without_id(self, construct, execute, info):
     """Check command create when result has dct but dct hasn't id key"""
     execute.return_value = [{'not_id': 'foo'}]
     assert execute.return_value == Base.create()
     assert 'create' == Base.command_sub
     construct.called_once_with({})
     execute.called_once_with(construct.return_value, output_format='csv')
     assert not info.called
Exemplo n.º 16
0
def get_configure_command(config_id, org=DEFAULT_ORG):
    """Return the deploy command line based on configure id.
    :param str config_id: the unique id of the configure file you have created.
    :param str org: the satellite organization name.
    """
    username, password = Base._get_username_password()
    return "hammer -u {} -p {} virt-who-config deploy --id {} --organization '{}' ".format(
        username, password, config_id, org)
Exemplo n.º 17
0
 def test_add_operating_system(self, construct, execute):
     """Check command_sub edited when executing add_operating_system"""
     options = {'foo': 'bar'}
     assert 'add-operatingsystem' != Base.command_sub
     assert execute.return_value == Base.add_operating_system(options)
     assert 'add-operatingsystem' == Base.command_sub
     construct.called_once_with(options)
     execute.called_once_with(construct.return_value)
Exemplo n.º 18
0
    def test_username_password_config_lookup(self, settings):
        """Username and password returned are from configuration"""
        settings.server.admin_username = '******'
        settings.server.admin_password = '******'
        username, password = Base._get_username_password()

        self.assertEqual(username, settings.server.admin_username)
        self.assertEqual(password, settings.server.admin_password)
Exemplo n.º 19
0
    def test_username_password_config_lookup(self, settings):
        """Username and password returned are from configuration"""
        settings.server.admin_username = '******'
        settings.server.admin_password = '******'
        username, password = Base._get_username_password()

        assert username == settings.server.admin_username
        assert password == settings.server.admin_password
Exemplo n.º 20
0
 def test_add_operating_system(self, construct, execute):
     """Check command_sub edited when executing add_operating_system"""
     options = {u'foo': u'bar'}
     self.assertNotEqual('add-operatingsystem', Base.command_sub)
     self.assertEqual(execute.return_value,
                      Base.add_operating_system(options))
     self.assertEqual('add-operatingsystem', Base.command_sub)
     construct.called_once_with(options)
     execute.called_once_with(construct.return_value)
Exemplo n.º 21
0
 def test_add_create_with_result_dct_without_id(self, construct, execute,
                                                info):
     """Check command create when result has dct but dct hasn't id key"""
     execute.return_value = [{'not_id': 'foo'}]
     self.assertEqual(execute.return_value, Base.create())
     self.assertEqual('create', Base.command_sub)
     construct.called_once_with({})
     execute.called_once_with(construct.return_value, output_format='csv')
     self.assertFalse(info.called)
Exemplo n.º 22
0
 def test_list_with_default_per_page(self, construct, execute):
     """Check list method set per_page as 1000 by default"""
     self.assertEquals(
         execute.return_value,
         Base.list(options={'organization-id': 1})
     )
     self.assertEqual('list', Base.command_sub)
     construct.called_once_with({'per-page': 1000})
     execute.called_once_with(construct.return_value, output_format='csv')
Exemplo n.º 23
0
 def test_add_create_with_empty_result(self, construct, execute):
     """Check command create when result is empty"""
     execute.return_value = []
     self.assertEqual(
         execute.return_value,
         Base.create()
     )
     self.assertEqual('create', Base.command_sub)
     construct.called_once_with({})
     execute.called_once_with(construct.return_value, output_format='csv')
Exemplo n.º 24
0
 def test_handle_response_logging_when_stderr_not_empty(self, warning):
     """Check handle_response log stderr when it is not empty"""
     base = Base()
     response = mock.Mock()
     response.return_code = 0
     response.stderr = [u'not empty']
     self.assertEqual(response.stdout, base._handle_response(response))
     warning.assert_called_once_with(
         u'stderr contains following message:\n{}'.format(response.stderr)
     )
     warning.reset_mock()
     self.assertEqual(
         response.stdout,
         base._handle_response(response, True)
     )
     self.assertFalse(
         warning.called,
         u'Should not be called when ignore_stderr is True'
     )
Exemplo n.º 25
0
 def test_add_create_with_result_dct_with_id_required_org(self, construct, execute, info):
     """Check command create when result has dct id key and organization
     is required
     """
     execute.return_value = [{'id': 'foo', 'bar': 'bas'}]
     Base.command_requires_org = True
     assert execute.return_value == Base.create({'organization-id': 'org-id'})
     assert 'create' == Base.command_sub
     construct.called_once_with({})
     execute.called_once_with(construct.return_value, output_format='csv')
     info.called_once_with({'id': 'foo', 'organization-id': 'org-id'})
Exemplo n.º 26
0
 def assert_response_error(self, expected_error, stderr=u'some error'):
     """Check error is raised when handling cli response
     :param expected_error: expected error (class)
     :param stderr: error present on stderr (str)
     :return:
     """
     base = Base()
     response = mock.Mock()
     response.return_code = 1
     response.stderr = [stderr]
     self.assertRaises(expected_error, base._handle_response, response)
Exemplo n.º 27
0
 def test_add_operating_system(self, construct, execute):
     """Check command_sub edited when executing add_operating_system"""
     options = {u'foo': u'bar'}
     self.assertNotEqual('add-operatingsystem', Base.command_sub)
     self.assertEqual(
         execute.return_value,
         Base.add_operating_system(options)
     )
     self.assertEqual('add-operatingsystem', Base.command_sub)
     construct.called_once_with(options)
     execute.called_once_with(construct.return_value)
Exemplo n.º 28
0
 def test_add_create_with_result_dct_with_id_not_required_org(
         self, construct, execute, info):
     """Check command create when result has dct id key and organization
     is not required
     """
     execute.return_value = [{'id': 'foo', 'bar': 'bas'}]
     Base.command_requires_org = False
     self.assertEqual(execute.return_value, Base.create())
     self.assertEqual('create', Base.command_sub)
     construct.called_once_with({})
     execute.called_once_with(construct.return_value, output_format='csv')
     info.called_once_with({'id': 'foo'})
Exemplo n.º 29
0
 def test_execute_with_raw_response(self, settings, command):
     """Check excuted build ssh method and returns raw response"""
     settings.locale = 'en_US'
     settings.performance = False
     settings.server.admin_username = '******'
     settings.server.admin_password = '******'
     response = Base.execute('some_cmd', return_raw_response=True)
     ssh_cmd = u'LANG=en_US  hammer -v -u admin -p password  some_cmd'
     command.assert_called_once_with(ssh_cmd.encode('utf-8'),
                                     output_format=None,
                                     timeout=None)
     self.assertIs(response, command.return_value)
Exemplo n.º 30
0
 def test_add_create_with_result_dct_without_id(
         self, construct, execute, info):
     """Check command create when result has dct but dct hasn't id key"""
     execute.return_value = [{'not_id': 'foo'}]
     self.assertEqual(
         execute.return_value,
         Base.create()
     )
     self.assertEqual('create', Base.command_sub)
     construct.called_once_with({})
     execute.called_once_with(construct.return_value, output_format='csv')
     self.assertFalse(info.called)
Exemplo n.º 31
0
 def test_execute_with_performance(self, settings, command, handle_resp):
     """Check excuted build ssh method and delegate response handling"""
     settings.locale = 'en_US'
     settings.performance.timer_hammer = True
     settings.server.admin_username = '******'
     settings.server.admin_password = '******'
     response = Base.execute('some_cmd', output_format='json')
     ssh_cmd = 'LANG=en_US time -p hammer -v -u admin -p password --output=json some_cmd'
     command.assert_called_once_with(
         ssh_cmd.encode('utf-8'), output_format='json', timeout=None, connection_timeout=None
     )
     handle_resp.assert_called_once_with(command.return_value, ignore_stderr=None)
     assert response is handle_resp.return_value
Exemplo n.º 32
0
def test_positive_report_help():
    """hammer level of help included in test:
     Base level hammer help includes report-templates,
     Command level hammer help contains usage details,
     Subcommand level hammer help contains usage details

    :id: ec395f47-a55f-441a-9cc6-e49400c83e8e

    :setup: Any satellite user

    :steps:

        1. hammer --help
        2. hammer report-template --help
        3. hammer report-template create --help

    :expectedresults: report-templates command is included in help,
                      report-templates command details are displayed,
                      report-templates create command details are displayed

    """
    command_output = '\n'.join(Base().execute('--help'))
    assert 'report-template' in command_output
    command_output = '\n'.join(Base().execute('report-template --help'))
    assert all([
        phrase in command_output for phrase in [
            'hammer report-template',
            'info',
            'report template',
            'generate',
            'report',
        ]
    ])
    command_output = '\n'.join(Base().execute('report-template create --help'))
    assert all([
        phrase in command_output for phrase in
        ['hammer report-template create', '--audit-comment', '--interactive']
    ])
Exemplo n.º 33
0
    def test_construct_command(self):
        """_construct_command builds a command using flags and arguments"""
        Base.command_base = 'basecommand'
        Base.command_sub = 'subcommand'
        command_parts = Base._construct_command(
            {'flag-one': True, 'flag-two': False, 'argument': 'value', 'ommited-arg': None}
        ).split()

        assert 'basecommand' in command_parts
        assert 'subcommand' in command_parts
        assert '--flag-one' in command_parts
        assert '--argument="value"' in command_parts
        assert '--flag-two' not in command_parts
        assert len(command_parts) == 4
Exemplo n.º 34
0
 def test_add_create_with_result_dct_with_id_required_org(
         self, construct, execute, info):
     """Check command create when result has dct id key and organization
     is required
     """
     execute.return_value = [{'id': 'foo', 'bar': 'bas'}]
     Base.command_requires_org = True
     self.assertEqual(
         execute.return_value,
         Base.create({'organization-id': 'org-id'})
     )
     self.assertEqual('create', Base.command_sub)
     construct.called_once_with({})
     execute.called_once_with(construct.return_value, output_format='csv')
     info.called_once_with({'id': 'foo', 'organization-id': 'org-id'})
Exemplo n.º 35
0
 def test_execute_with_raw_response(self, settings, command):
     """Check excuted build ssh method and returns raw response"""
     settings.locale = 'en_US'
     settings.performance = False
     settings.server.admin_username = '******'
     settings.server.admin_password = '******'
     response = Base.execute('some_cmd', return_raw_response=True)
     ssh_cmd = u'LANG=en_US  hammer -v -u admin -p password  some_cmd'
     command.assert_called_once_with(
         ssh_cmd.encode('utf-8'),
         output_format=None,
         timeout=None,
         connection_timeout=None
     )
     self.assertIs(response, command.return_value)
Exemplo n.º 36
0
    def test_construct_command(self):
        """_construct_command builds a command using flags and arguments"""
        Base.command_base = 'basecommand'
        Base.command_sub = 'subcommand'
        command_parts = Base._construct_command({
            u'flag-one': True,
            u'flag-two': False,
            u'argument': u'value',
            u'ommited-arg': None,
        }).split()

        self.assertIn(u'basecommand', command_parts)
        self.assertIn(u'subcommand', command_parts)
        self.assertIn(u'--flag-one', command_parts)
        self.assertIn(u'--argument="value"', command_parts)
        self.assertNotIn(u'--flag-two', command_parts)
        self.assertEqual(len(command_parts), 4)
Exemplo n.º 37
0
 def test_execute_with_performance(self, settings, command, handle_resp):
     """Check excuted build ssh method and delegate response handling"""
     settings.locale = 'en_US'
     settings.performance.timer_hammer = True
     settings.server.admin_username = '******'
     settings.server.admin_password = '******'
     response = Base.execute('some_cmd', output_format='json')
     ssh_cmd = (
         u'LANG=en_US time -p hammer -v -u admin -p password --output=json'
         u' some_cmd'
     )
     command.assert_called_once_with(
         ssh_cmd.encode('utf-8'),
         output_format='json',
         timeout=None,
         connection_timeout=None
     )
     handle_resp.assert_called_once_with(
         command.return_value,
         ignore_stderr=None
     )
     self.assertIs(response, handle_resp.return_value)
Exemplo n.º 38
0
 def __init__(self):
     """
     Sets the base command for class.
     """
     Base.__init__(self)
     self.command_base = "host"
Exemplo n.º 39
0
 def __init__(self):
     """
     Sets the base command for class.
     """
     Base.__init__(self)
     self.command_base = "partition_table"
Exemplo n.º 40
0
 def __init__(self):
     """
     Sets the base command for class.
     """
     Base.__init__(self)
     self.command_base = "compute_resource"
Exemplo n.º 41
0
 def test_exists_without_option_and_empty_return(self, lst_method):
     """Check exists method without options and empty return"""
     lst_method.return_value = []
     response = Base.exists(search=['id', 1])
     lst_method.assert_called_once_with({u'search': u'id=\\"1\\"'})
     self.assertEqual([], response)
Exemplo n.º 42
0
 def test_info_requires_organization_id(self, _):
     """Check info raises CLIError with organization-id is not present in
     options
     """
     with pytest.raises(CLIError):
         Base.info()
Exemplo n.º 43
0
 def __init__(self):
     """
     Sets the base command for class.
     """
     Base.__init__(self)
     self.command_base = "environment"
Exemplo n.º 44
0
 def test_exists_without_option_and_empty_return(self, lst_method):
     """Check exists method without options and empty return"""
     lst_method.return_value = []
     response = Base.exists(search=['id', 1])
     lst_method.assert_called_once_with({'search': 'id=\\"1\\"'})
     assert [] == response
Exemplo n.º 45
0
    def test_username_password_config_lookup(self):
        """Username and password returned are from configuration"""
        username, password = Base._get_username_password()

        self.assertEqual(username, conf.properties['foreman.admin.username'])
        self.assertEqual(password, conf.properties['foreman.admin.password'])
Exemplo n.º 46
0
 def __init__(self):
     """
     Sets the base command for class
     """
     Base.__init__(self)
     self.command_base = "organization"
Exemplo n.º 47
0
 def __init__(self):
     """
     Sets the base command for class.
     """
     Base.__init__(self)
Exemplo n.º 48
0
 def __init__(self):
     """
     Sets the base command for class.
     """
     Base.__init__(self)
     self.command_base = "global_parameter"