From bb31eba28a98c95cdbe9cee01eb1002027ff9a91 Mon Sep 17 00:00:00 2001 From: 3c7 Date: Fri, 7 Apr 2017 08:02:37 +0200 Subject: [PATCH 1/2] Use StringIO.StringIO() with python2 --- contrib/tests/suite.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/contrib/tests/suite.py b/contrib/tests/suite.py index 3ae582116..364a47d14 100644 --- a/contrib/tests/suite.py +++ b/contrib/tests/suite.py @@ -5,11 +5,17 @@ import sys import json import unittest -from io import StringIO -from io import open +from io import open from cortexutils.analyzer import Analyzer +# Different lib when using python3 or 2 +if sys.version_info > (2, 8): + from io import StringIO +else: + from StringIO import StringIO + + def load_test_fixture(fixture_path): path = os.path.dirname(os.path.abspath(__file__)) From 99f61474c0136a40f24b232abe8ec9d87ea04823 Mon Sep 17 00:00:00 2001 From: 3c7 Date: Fri, 7 Apr 2017 09:15:08 +0200 Subject: [PATCH 2/2] Small change + make pep8 happy + rename suite->test_suite for pytest compatibility. --- contrib/tests/{suite.py => test_suite.py} | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) rename contrib/tests/{suite.py => test_suite.py} (99%) diff --git a/contrib/tests/suite.py b/contrib/tests/test_suite.py similarity index 99% rename from contrib/tests/suite.py rename to contrib/tests/test_suite.py index 364a47d14..b171afb36 100644 --- a/contrib/tests/suite.py +++ b/contrib/tests/test_suite.py @@ -10,13 +10,12 @@ from cortexutils.analyzer import Analyzer # Different lib when using python3 or 2 -if sys.version_info > (2, 8): +if sys.version_info >= (3, 0): from io import StringIO else: from StringIO import StringIO - def load_test_fixture(fixture_path): path = os.path.dirname(os.path.abspath(__file__)) fixture_file = open(path + '/' + fixture_path) @@ -25,6 +24,7 @@ def load_test_fixture(fixture_path): sys.stdin = StringIO(input) sys.stdout = StringIO() + class TestMinimalConfig(unittest.TestCase): def setUp(self): @@ -47,6 +47,7 @@ def test_params_data(self): self.assertEqual(self.analyzer.getParam('data'), "1.1.1.1") self.assertEqual(self.analyzer.get_param('data'), "1.1.1.1") + class TestProxyConfig(unittest.TestCase): def setUp(self): @@ -62,6 +63,7 @@ def test_proxy_config(self): self.assertEqual(os.environ['http_proxy'], proxy_url) self.assertEqual(os.environ['https_proxy'], proxy_url) + class TestTlpConfig(unittest.TestCase): def setUp(self): @@ -93,6 +95,7 @@ def test_check_tlp_ok(self): # __check_tlp self.assertEqual(self.analyzer._Analyzer__check_tlp(), True) + class TestErrorResponse(unittest.TestCase): def setUp(self): @@ -122,6 +125,7 @@ def test_error_response(self): self.assertEqual(json_output['input']['config']['apikey'], 'REMOVED') self.assertEqual(json_output['input']['config']['api_key'], 'REMOVED') + class TestReportResponse(unittest.TestCase): def setUp(self):