コード例 #1
0
def test_any_reports_present_yes(config):
    """Does _any_reports_present return True correctly?"""
    state_manager = StateManager(config)
    state_manager.add_report_item(6, ENGINE_NAME, {'keyval': 1})
    sut = AnalysisUtility(None)
    sut.config = config
    assert sut._any_reports_present(state_manager)
コード例 #2
0
def test_report_item_doubling(local_config):
    """Test that, when we add the same data to the report items twice, we get two copies."""
    manager = StateManager(local_config)
    manager.add_report_item(6, 'default', {'keyval': 42})
    manager.add_report_item(6, 'default', {'keyval': 42})
    returned_list = manager.get_current_report_items(6, 'default')
    assert returned_list == [{'keyval': 42}, {'keyval': 42}]
コード例 #3
0
def test_exception_handling(local_config):
    """Tests that OperationalError is handled by all methods without throwing an exception."""
    manager = StateManager(local_config)
    manager._persistor._cursor_factory = BreakingCursor
    manager.set_checkpoint('ABCDEFGH', 'default', 'ALPHA')
    assert manager.get_previous_hashes('default') == []
    manager.prune("2020-01-12T00:00:00")
    manager.add_report_item(6, 'default', {'keyval': 1})
    assert manager.get_current_report_items(6, 'default') == []
    manager.clear_report_items(6, 'default')
コード例 #4
0
def test_add_report_item(local_config):
    """Test the add_report_item() API."""
    manager = StateManager(local_config)
    manager.add_report_item(6, 'default', {'file_name': 'blort.exe'})
    assert getattr(manager._persistor, "_sc", 0) == 0
    assert getattr(manager._persistor, "_gph", 0) == 0
    assert getattr(manager._persistor, "_guh", 0) == 0
    assert getattr(manager._persistor, "_p", 0) == 0
    assert getattr(manager._persistor, "_ari", 0) == 1
    assert getattr(manager._persistor, "_gcri", 0) == 0
    assert getattr(manager._persistor, "_cri", 0) == 0
コード例 #5
0
def test_add_report_item_persistent(local_persistent_config):
    """Tests that add_report_item actually adds stuff to the database file on disk."""
    if os.path.exists(PERSISTENCE_FILE):
        os.remove(PERSISTENCE_FILE)
    manager = StateManager(local_persistent_config)
    manager.add_report_item(6, 'default', {'keyval': 1})
    manager.add_report_item(6, 'default', {'keyval': 4})
    manager.add_report_item(6, 'default', {'keyval': 9})
    manager.add_report_item(2, 'default', {'keyval': 2})
    manager.add_report_item(2, 'default', {'keyval': 3})
    manager.force_close()
    manager2 = StateManager(local_persistent_config)
    _test_check_report_items(manager2.get_current_report_items(6, 'default'), 'keyval', [1, 4, 9])
    _test_check_report_items(manager2.get_current_report_items(2, 'default'), 'keyval', [2, 3])
    _test_check_report_items(manager2.get_current_report_items(9, 'default'), 'keyval', [])
コード例 #6
0
def test_report_items(local_config):
    """Tests the management of report items."""
    manager = StateManager(local_config)
    manager.add_report_item(6, 'default', {'keyval': 1})
    manager.add_report_item(6, 'default', {'keyval': 4})
    manager.add_report_item(6, 'default', {'keyval': 9})
    manager.add_report_item(2, 'default', {'keyval': 2})
    manager.add_report_item(2, 'default', {'keyval': 3})
    _test_check_report_items(manager.get_current_report_items(6, 'default'), 'keyval', [1, 4, 9])
    _test_check_report_items(manager.get_current_report_items(2, 'default'), 'keyval', [2, 3])
    _test_check_report_items(manager.get_current_report_items(9, 'default'), 'keyval', [])
    manager.clear_report_items(6, 'default')
    _test_check_report_items(manager.get_current_report_items(6, 'default'), 'keyval', [])
    _test_check_report_items(manager.get_current_report_items(2, 'default'), 'keyval', [2, 3])
    _test_check_report_items(manager.get_current_report_items(9, 'default'), 'keyval', [])