summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorAlex Shatov <alexs@att.com>2018-06-21 09:19:07 -0400
committerAlex Shatov <alexs@att.com>2018-06-21 09:19:07 -0400
commitd444b320dea07248dc69c81d0ce9ea5fc353e701 (patch)
treecacd244c5e2424faca5e088dc3ca3baf9afd8511 /tests
parentc9ec231483d905f3a391c3985c2c2762344ed5c1 (diff)
3.0.1 policy-handler - cleaning sonar smells
- no change of functionality or API - removed the unused enum34>=1.1.6 from requirements.txt and setup.py - refactored run_policy.sh to redirect the stdout+stderr only once - refactoring to remove smells+vulnerability reported by sonar -- renamed Config.config to Config.settings -- removed the commented out code in customizer.py -- renamed StepTimer.NEXT to StepTimer.STATE_NEXT to avoid the naming confusion with the method StepTimer.next. Also renamed the related StepTimer.STATE_* constants -- refactored several functions by extracting methods to eliminate 4 out of 5 "brain-overload" smells reported by sonar -- moved the literal string for the socket_host "0.0.0.0" to a constant on the web-server to avoid the reported vulnerability Change-Id: I4c7d47d41c6ecd7cb28f6704f5dad2053c1ca7d6 Signed-off-by: Alex Shatov <alexs@att.com> Issue-ID: DCAEGEN2-515
Diffstat (limited to 'tests')
-rw-r--r--tests/mock_settings.py4
-rw-r--r--tests/test_policyhandler.py16
2 files changed, 10 insertions, 10 deletions
diff --git a/tests/mock_settings.py b/tests/mock_settings.py
index dddba7e..28bc6cc 100644
--- a/tests/mock_settings.py
+++ b/tests/mock_settings.py
@@ -45,7 +45,7 @@ class Settings(object):
Config.load_from_file("etc_upload/config.json")
- Config.config["catch_up"] = {"interval": 10, "max_skips": 2}
+ Config.settings["catch_up"] = {"interval": 10, "max_skips": 2}
Settings.logger = logging.getLogger("policy_handler.unit_test")
sys.stdout = LogWriter(Settings.logger.info)
@@ -56,4 +56,4 @@ class Settings(object):
Audit.init(Config.get_system_name(), Config.LOGGER_CONFIG_FILE_PATH)
Settings.logger.info("starting policy_handler with config:")
- Settings.logger.info(Audit.log_json_dumps(Config.config))
+ Settings.logger.info(Audit.log_json_dumps(Config.settings))
diff --git a/tests/test_policyhandler.py b/tests/test_policyhandler.py
index 097a8e1..ec0b030 100644
--- a/tests/test_policyhandler.py
+++ b/tests/test_policyhandler.py
@@ -76,7 +76,7 @@ class MonkeyedResponse(object):
def monkeyed_discovery(full_path):
"""monkeypatch for get from consul"""
res_json = {}
- if full_path == DiscoveryClient.CONSUL_SERVICE_MASK.format(Config.config["deploy_handler"]):
+ if full_path == DiscoveryClient.CONSUL_SERVICE_MASK.format(Config.settings["deploy_handler"]):
res_json = [{
"ServiceAddress": "1.1.1.1",
"ServicePort": "123"
@@ -127,7 +127,7 @@ class MonkeyPolicyBody(object):
class MonkeyPolicyEngine(object):
"""pretend this is the policy-engine"""
- _scope_prefix = Config.config["scope_prefixes"][0]
+ _scope_prefix = Config.settings["scope_prefixes"][0]
LOREM_IPSUM = """Lorem ipsum dolor sit amet consectetur ametist""".split()
LONG_TEXT = "0123456789" * 100
_policies = []
@@ -317,8 +317,8 @@ def fix_deploy_handler_fail(monkeypatch, fix_discovery):
DeployHandler._url = None
Settings.logger.info("setup fix_deploy_handler_fail")
- config_catch_up = Config.config["catch_up"]
- Config.config["catch_up"] = {"interval": 1, "max_skips": 0}
+ config_catch_up = Config.settings["catch_up"]
+ Config.settings["catch_up"] = {"interval": 1, "max_skips": 0}
audit = Audit(req_message="fix_deploy_handler_fail")
DeployHandler._lazy_init(audit, rediscover=True)
@@ -328,7 +328,7 @@ def fix_deploy_handler_fail(monkeypatch, fix_discovery):
monkeyed_deploy_handler_init)
yield fix_deploy_handler_fail
Settings.logger.info("teardown fix_deploy_handler_fail")
- Config.config["catch_up"] = config_catch_up
+ Config.settings["catch_up"] = config_catch_up
def monkeyed_cherrypy_engine_exit():
@@ -481,7 +481,7 @@ class WebServerTest(CPWebCase):
def test_web_policies_latest(self):
"""test POST /policies_latest with policyName"""
- match_to_policy_name = Config.config["scope_prefixes"][0] + "amet.*"
+ match_to_policy_name = Config.settings["scope_prefixes"][0] + "amet.*"
expected_policies = MonkeyPolicyEngine.gen_policies_latest(match_to_policy_name)
expected_policies = expected_policies[LATEST_POLICIES]
@@ -649,7 +649,7 @@ class WebServerPDPBoomTest(CPWebCase):
def test_web_policies_latest(self):
"""test POST /policies_latest with policyName"""
- match_to_policy_name = Config.config["scope_prefixes"][0] + "amet.*"
+ match_to_policy_name = Config.settings["scope_prefixes"][0] + "amet.*"
body = json.dumps({POLICY_NAME: match_to_policy_name})
result = self.getPage("/policies_latest", method='POST',
@@ -809,7 +809,7 @@ class WebServerInternalBoomTest(CPWebCase):
def test_web_policies_latest(self):
"""test POST /policies_latest with policyName"""
- match_to_policy_name = Config.config["scope_prefixes"][0] + "amet.*"
+ match_to_policy_name = Config.settings["scope_prefixes"][0] + "amet.*"
body = json.dumps({POLICY_NAME: match_to_policy_name})
result = self.getPage("/policies_latest", method='POST',