Esempio n. 1
0
def test_print_db_search(isfile_mock, r_glob_mock, u_glob_mock, agent_mock,
                         test_data, query, totalItems):
    """
    Tests print_db function with search parameter
    """
    with patch('sqlite3.connect') as mock_db:
        mock_db.return_value = test_data

        rootcheck_data = rootcheck.print_db('001', q=query)
        assert rootcheck_data['totalItems'] == totalItems
Esempio n. 2
0
def test_print_db_sort(isfile_mock, r_glob_mock, u_glob_mock, agent_mock, sort,
                       first_event, test_data):
    """
    Tests print_db function with sort parameter
    """
    with patch('sqlite3.connect') as mock_db:
        mock_db.return_value = test_data

        rootcheck_data = rootcheck.print_db('001', sort=sort)
        assert rootcheck_data['items'][0]['event'] == first_event
Esempio n. 3
0
def test_print_db_select(isfile_mock, r_glob_mock, u_glob_mock, agent_mock,
                         select, test_data):
    """
    Tests print_db function with select parameter
    """
    with patch('sqlite3.connect') as mock_db:
        mock_db.return_value = test_data

        rootcheck_data = rootcheck.print_db('001', select=select)
        for r in rootcheck_data['items']:
            # check expected keys are returned
            assert set(select['fields']) - r.keys() == set()
Esempio n. 4
0
def test_print_db(isfile_mock, r_glob_mock, u_glob_mock, agent_mock,
                  test_data):
    """
    Tests print_db function with default parameters
    """
    with patch('sqlite3.connect') as mock_db:
        mock_db.return_value = test_data

        rootcheck_data = rootcheck.print_db('001')

        # check number of returned items
        assert rootcheck_data['totalItems'] == 5

        for r in rootcheck_data['items']:
            # check no null values were returned
            assert all(map(lambda x: x is not None, r.values()))
            # check expected keys are returned
            assert rootcheck.fields.keys() - r.keys() == set()