From f135cc2f354e6a40676e88803fa088b2ab1b1163 Mon Sep 17 00:00:00 2001 From: Rico Date: Tue, 3 Mar 2020 01:33:57 +0100 Subject: [PATCH] test(analyzers): fixed several analyzer tests Those tests used a wrong way to check if the action was being set correctly. Now that I added a check for subclasses of BasicAction in the code itself, this code throws an error. --- .../analyzers/logicalanalyzers/tests/andanalyzer_test.py | 6 ++++-- .../logicalanalyzers/tests/logicalbaseanalyzer_test.py | 6 ++++-- .../analyzers/logicalanalyzers/tests/oranalyzer_test.py | 6 ++++-- pastepwn/analyzers/tests/alwaystrueanalyzer_test.py | 6 ++++-- pastepwn/analyzers/tests/bcrypthashanalyzer_test.py | 6 ++++-- pastepwn/analyzers/tests/genericanalyzer_test.py | 5 +++-- pastepwn/analyzers/tests/wordanalyzer_test.py | 6 ++++-- 7 files changed, 27 insertions(+), 14 deletions(-) diff --git a/pastepwn/analyzers/logicalanalyzers/tests/andanalyzer_test.py b/pastepwn/analyzers/logicalanalyzers/tests/andanalyzer_test.py index a047616..18b6e98 100644 --- a/pastepwn/analyzers/logicalanalyzers/tests/andanalyzer_test.py +++ b/pastepwn/analyzers/logicalanalyzers/tests/andanalyzer_test.py @@ -2,6 +2,7 @@ import unittest from unittest import mock +from pastepwn.actions.basicaction import BasicAction from pastepwn.analyzers import AndAnalyzer @@ -42,8 +43,9 @@ def test_negative(self): self.assertFalse(analyzer.match(self.paste)) def test_actions_present(self): - analyzer = AndAnalyzer(self.paste, None) - self.assertEqual([self.paste], analyzer.actions) + action = mock.MagicMock(spec=BasicAction) + analyzer = AndAnalyzer(action, None) + self.assertEqual([action], analyzer.actions) def test_analyzers_present(self): analyzer = AndAnalyzer(None, self.paste) diff --git a/pastepwn/analyzers/logicalanalyzers/tests/logicalbaseanalyzer_test.py b/pastepwn/analyzers/logicalanalyzers/tests/logicalbaseanalyzer_test.py index 3d0dbd2..7c266bd 100644 --- a/pastepwn/analyzers/logicalanalyzers/tests/logicalbaseanalyzer_test.py +++ b/pastepwn/analyzers/logicalanalyzers/tests/logicalbaseanalyzer_test.py @@ -2,6 +2,7 @@ import unittest from unittest import mock +from pastepwn.actions.basicaction import BasicAction from pastepwn.analyzers.logicalanalyzers import LogicalBaseAnalyzer @@ -14,8 +15,9 @@ def test_exception(self): self.assertRaises(NotImplementedError, analyzer.match, mock.Mock()) def test_actions_present(self): - analyzer = LogicalBaseAnalyzer(self.paste, None) - self.assertEqual([self.paste], analyzer.actions) + action = mock.MagicMock(spec=BasicAction) + analyzer = LogicalBaseAnalyzer(action, None) + self.assertEqual([action], analyzer.actions) def test_analyzers_present(self): analyzer = LogicalBaseAnalyzer(None, self.paste) diff --git a/pastepwn/analyzers/logicalanalyzers/tests/oranalyzer_test.py b/pastepwn/analyzers/logicalanalyzers/tests/oranalyzer_test.py index 9c91e2c..73a2073 100644 --- a/pastepwn/analyzers/logicalanalyzers/tests/oranalyzer_test.py +++ b/pastepwn/analyzers/logicalanalyzers/tests/oranalyzer_test.py @@ -2,6 +2,7 @@ import unittest from unittest import mock +from pastepwn.actions.basicaction import BasicAction from pastepwn.analyzers.logicalanalyzers import OrAnalyzer @@ -41,8 +42,9 @@ def test_negative(self): self.assertFalse(analyzer.match(self.paste)) def test_actions_present(self): - analyzer = OrAnalyzer(self.paste, None) - self.assertEqual([self.paste], analyzer.actions) + action = mock.MagicMock(spec=BasicAction) + analyzer = OrAnalyzer(action, None) + self.assertEqual([action], analyzer.actions) def test_analyzers_present(self): analyzer = OrAnalyzer(None, self.paste) diff --git a/pastepwn/analyzers/tests/alwaystrueanalyzer_test.py b/pastepwn/analyzers/tests/alwaystrueanalyzer_test.py index cce86ab..0973040 100644 --- a/pastepwn/analyzers/tests/alwaystrueanalyzer_test.py +++ b/pastepwn/analyzers/tests/alwaystrueanalyzer_test.py @@ -2,6 +2,7 @@ import unittest from unittest import mock +from pastepwn.actions.basicaction import BasicAction from pastepwn.analyzers.alwaystrueanalyzer import AlwaysTrueAnalyzer @@ -24,8 +25,9 @@ def test_match(self): self.assertTrue(self.analyzer.match(self.paste)) def test_actions_present(self): - analyzer = AlwaysTrueAnalyzer(self.paste) - self.assertEqual([self.paste], analyzer.actions) + action = mock.MagicMock(spec=BasicAction) + analyzer = AlwaysTrueAnalyzer(action) + self.assertEqual([action], analyzer.actions) if __name__ == '__main__': diff --git a/pastepwn/analyzers/tests/bcrypthashanalyzer_test.py b/pastepwn/analyzers/tests/bcrypthashanalyzer_test.py index 523f248..aacca42 100644 --- a/pastepwn/analyzers/tests/bcrypthashanalyzer_test.py +++ b/pastepwn/analyzers/tests/bcrypthashanalyzer_test.py @@ -2,6 +2,7 @@ import unittest from unittest import mock +from pastepwn.actions.basicaction import BasicAction from pastepwn.analyzers.bcrypthashanalyzer import BcryptHashAnalyzer @@ -65,8 +66,9 @@ def test_match_empty(self): self.assertFalse(self.analyzer.match(self.paste)) def test_actions_present(self): - analyzer = BcryptHashAnalyzer(self.paste) - self.assertEqual([self.paste], analyzer.actions) + action = mock.MagicMock(spec=BasicAction) + analyzer = BcryptHashAnalyzer(action) + self.assertEqual([action], analyzer.actions) if __name__ == '__main__': diff --git a/pastepwn/analyzers/tests/genericanalyzer_test.py b/pastepwn/analyzers/tests/genericanalyzer_test.py index bf894bb..00cf4fc 100644 --- a/pastepwn/analyzers/tests/genericanalyzer_test.py +++ b/pastepwn/analyzers/tests/genericanalyzer_test.py @@ -1,13 +1,14 @@ # -*- coding: utf-8 -*- import unittest -from unittest.mock import Mock +from unittest.mock import Mock, MagicMock +from pastepwn.actions.basicaction import BasicAction from pastepwn.analyzers import GenericAnalyzer class TestGenericAnalyzer(unittest.TestCase): def setUp(self): - self.mock_action = Mock() + self.mock_action = MagicMock(spec=BasicAction) def test_empty_match_func(self): """Check if a ValueError rises on empty match_func""" diff --git a/pastepwn/analyzers/tests/wordanalyzer_test.py b/pastepwn/analyzers/tests/wordanalyzer_test.py index b43f69f..985baed 100644 --- a/pastepwn/analyzers/tests/wordanalyzer_test.py +++ b/pastepwn/analyzers/tests/wordanalyzer_test.py @@ -2,6 +2,7 @@ import unittest from unittest import mock +from pastepwn.actions.basicaction import BasicAction from pastepwn.analyzers.wordanalyzer import WordAnalyzer @@ -134,8 +135,9 @@ def test_match_empty(self): self.assertFalse(analyzer.match(self.paste)) def test_actions_present(self): - analyzer = WordAnalyzer(self.paste, "Test") - self.assertEqual([self.paste], analyzer.actions) + action = mock.MagicMock(spec=BasicAction) + analyzer = WordAnalyzer(action, "Test") + self.assertEqual([action], analyzer.actions) if __name__ == '__main__':