mirror of
https://github.com/Security-Onion-Solutions/securityonion.git
synced 2025-12-06 09:12:45 +01:00
Fix unit test issues
This commit is contained in:
@@ -15,8 +15,9 @@ function ci() {
|
||||
exit 1
|
||||
fi
|
||||
|
||||
pip install pytest pytest-cov
|
||||
flake8 "$TARGET_DIR" "--config=${HOME_DIR}/pytest.ini"
|
||||
pytest "$TARGET_DIR" "--cov-config=${HOME_DIR}/pytest.ini" "--cov=$TARGET_DIR" --doctest-modules --cov-report=term --cov-fail-under=100
|
||||
python3 -m pytest "--cov-config=${HOME_DIR}/pytest.ini" "--cov=$TARGET_DIR" --doctest-modules --cov-report=term --cov-fail-under=100 "$TARGET_DIR"
|
||||
}
|
||||
|
||||
function download() {
|
||||
|
||||
@@ -17,13 +17,16 @@ class TestLocalfileMethods(unittest.TestCase):
|
||||
|
||||
def test_main_success(self):
|
||||
output = {"foo": "bar"}
|
||||
conf = {"file_path": ["somefile.csv"]}
|
||||
with patch('sys.stdout', new=StringIO()) as mock_stdout:
|
||||
with patch('localfile.localfile.analyze', new=MagicMock(return_value=output)) as mock:
|
||||
sys.argv = ["cmd", "input"]
|
||||
localfile.main()
|
||||
expected = '{"foo": "bar"}\n'
|
||||
self.assertEqual(mock_stdout.getvalue(), expected)
|
||||
mock.assert_called_once()
|
||||
with patch('helpers.loadConfig', new=MagicMock(return_value=conf)) as lcmock:
|
||||
sys.argv = ["cmd", "input"]
|
||||
localfile.main()
|
||||
expected = '{"foo": "bar"}\n'
|
||||
self.assertEqual(mock_stdout.getvalue(), expected)
|
||||
mock.assert_called_once()
|
||||
lcmock.assert_called_once()
|
||||
|
||||
def test_checkConfigRequirements_present(self):
|
||||
conf = {"file_path": "['intel.csv']"}
|
||||
|
||||
@@ -35,7 +35,9 @@ class TestMalwareHashRegistryMethods(unittest.TestCase):
|
||||
response = malwarehashregistry.sendReq(hash)
|
||||
mock.assert_called_once_with(options, hash, flags)
|
||||
self.assertIsNotNone(response)
|
||||
self.assertEqual(response, {"hash": "84af04b8e69682782607a0c5796ca56999eda6b3", "last_seen": "2019-15-07 03:30:33", "av_detection_percentage": 35})
|
||||
self.assertEqual(response["hash"], "84af04b8e69682782607a0c5796ca56999eda6b3")
|
||||
self.assertRegex(response["last_seen"], r'2019-..-07 ..:..:33') # host running this test won't always use UTC
|
||||
self.assertEqual(response["av_detection_percentage"], 35)
|
||||
|
||||
def test_sendReqNoData(self):
|
||||
output = "84af04b8e69682782607a0c5796ca5696b3 NO_DATA"
|
||||
|
||||
Reference in New Issue
Block a user