diff --git a/salt/sensoroni/files/analyzers/build.sh b/salt/sensoroni/files/analyzers/build.sh index cb7dcbc52..386cc92d5 100755 --- a/salt/sensoroni/files/analyzers/build.sh +++ b/salt/sensoroni/files/analyzers/build.sh @@ -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() { diff --git a/salt/sensoroni/files/analyzers/localfile/localfile_test.py b/salt/sensoroni/files/analyzers/localfile/localfile_test.py index 30b171f86..154b74cd7 100644 --- a/salt/sensoroni/files/analyzers/localfile/localfile_test.py +++ b/salt/sensoroni/files/analyzers/localfile/localfile_test.py @@ -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']"} diff --git a/salt/sensoroni/files/analyzers/malwarehashregistry/malwarehashregistry_test.py b/salt/sensoroni/files/analyzers/malwarehashregistry/malwarehashregistry_test.py index 824949d8b..a4a7d2340 100644 --- a/salt/sensoroni/files/analyzers/malwarehashregistry/malwarehashregistry_test.py +++ b/salt/sensoroni/files/analyzers/malwarehashregistry/malwarehashregistry_test.py @@ -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"