def test_get_sca_list_search_param(self):
        """
        Checks only selected fields are loaded from database
        """
        with patch('wazuh.security_configuration_assessment.WazuhDBConnection'
                   ) as mock_wdb:
            mock_wdb.return_value.execute.side_effect = get_fake_sca_data
            search = {'value': 'debian', 'negation': False}
            result = get_sca_list('000', search=search)
            assert (isinstance(result, dict))
            assert ('totalItems' in result)
            assert (isinstance(result['totalItems'], int))
            assert ('items' in result)
            assert (len(result['items']) > 0)

            search = {'value': 'foo', 'negation': False}
            result = get_sca_list('000', search=search)
            assert (isinstance(result, dict))
            assert ('totalItems' in result)
            assert (isinstance(result['totalItems'], int))
            assert ('items' in result)
            assert (len(result['items']) == 0)

            search = {'value': 'foo', 'negation': True}
            result = get_sca_list('000', search=search)
            assert (isinstance(result, dict))
            assert ('totalItems' in result)
            assert (isinstance(result['totalItems'], int))
            assert ('items' in result)
            assert (len(result['items']) > 0)
    def test_get_sca_list_search_param(self, mock):
        """
        Checks only selected fields are loaded from database
        """
        with patch('wazuh.utils.WazuhDBConnection') as mock_wdb:
            mock_wdb.return_value = InitWDBSocketMock(sql_schema_file='schema_sca_test.sql')
            search = {'value': 'debian', 'negation': False}
            result = get_sca_list('000', search=search)
            assert (isinstance(result, dict))
            assert ('totalItems' in result)
            assert (isinstance(result['totalItems'], int))
            assert ('items' in result)
            assert (len(result['items']) > 0)

            search = {'value': 'foo', 'negation': False}
            result = get_sca_list('000', search=search)
            assert (isinstance(result, dict))
            assert ('totalItems' in result)
            assert (isinstance(result['totalItems'], int))
            assert ('items' in result)
            assert (len(result['items']) == 0)

            search = {'value': 'foo', 'negation': True}
            result = get_sca_list('000', search=search)
            assert (isinstance(result, dict))
            assert ('totalItems' in result)
            assert (isinstance(result['totalItems'], int))
            assert ('items' in result)
            assert (len(result['items']) > 0)
    def test_sca_failed_limit(self):
        """
        Test failing using not correct limits
        """
        with patch('wazuh.security_configuration_assessment.WazuhDBBackend') as mock_wdb:
            mock_wdb.return_value.connect_to_db.return_value.execute.side_effect = get_fake_sca_data
            with pytest.raises(exception.WazuhException, match=".* 1405 .*"):
                get_sca_list(agent_id='000', limit=common.maximum_database_limit+1)

            with pytest.raises(exception.WazuhException, match=".* 1406 .*"):
                get_sca_list(agent_id='000', limit=0)
 def test_get_sca_list(self, mock):
     """
     Checks data are properly loaded from database
     """
     with patch('wazuh.utils.WazuhDBConnection') as mock_wdb:
         mock_wdb.return_value = InitWDBSocketMock(sql_schema_file='schema_sca_test.sql')
         result = get_sca_list('000')
         assert(isinstance(result, dict))
         assert('totalItems' in result)
         assert(isinstance(result['totalItems'], int))
         assert('items' in result)
         assert(len(result['items']) > 0)
         sca = result['items'][0]
         assert(isinstance(sca, dict))
         assert(set(sca.keys()) == set(cols_returned_from_db_sca))
 def test_get_sca_list_select_param(self, mock):
     """
     Checks only selected fields are loaded from database
     """
     with patch('wazuh.utils.WazuhDBConnection') as mock_wdb:
         mock_wdb.return_value = InitWDBSocketMock(sql_schema_file='schema_sca_test.sql')
         fields = {'fields': ['name', 'policy_id']}
         result = get_sca_list('000', select=fields)
         assert (isinstance(result, dict))
         assert ('totalItems' in result)
         assert (isinstance(result['totalItems'], int))
         assert ('items' in result)
         assert (len(result['items']) > 0)
         sca = result['items'][0]
         assert (isinstance(sca, dict))
         assert (set(sca.keys()) == set(fields['fields']))
 def test_get_sca_list(self):
     """
     Checks data are properly loaded from database
     """
     with patch('wazuh.security_configuration_assessment.WazuhDBConnection'
                ) as mock_wdb:
         mock_wdb.return_value.execute.side_effect = get_fake_sca_data
         result = get_sca_list('000')
         assert (isinstance(result, dict))
         assert ('totalItems' in result)
         assert (isinstance(result['totalItems'], int))
         assert ('items' in result)
         assert (len(result['items']) > 0)
         sca = result['items'][0]
         assert (isinstance(sca, dict))
         assert (set(sca.keys()) == set(fields_translation_sca.keys()))
 def test_get_sca_list_select_param(self):
     """
     Checks only selected fields are loaded from database
     """
     with patch('wazuh.security_configuration_assessment.WazuhDBConnection'
                ) as mock_wdb:
         mock_wdb.return_value.execute.side_effect = get_fake_sca_data
         fields = {'fields': ['name', 'policy_id']}
         result = get_sca_list('000', select=fields)
         assert (isinstance(result, dict))
         assert ('totalItems' in result)
         assert (isinstance(result['totalItems'], int))
         assert ('items' in result)
         assert (len(result['items']) > 0)
         sca = result['items'][0]
         assert (isinstance(sca, dict))
         assert (set(sca.keys()) == set(fields['fields']))