[SEBA-412] Automated reformat of Python code
Passes of modernize, autopep8, black, then check with flake8
flake8 + manual fixes:
lib/xos-config
lib/xos-kafka
lib/xos-util
xos/coreapi
xos/api
xos/xos_client
Change-Id: Ib23cf84cb13beb3c6381fa0d79594dc9131dc815
diff --git a/lib/xos-genx/xos-genx-tests/test_general_security.py b/lib/xos-genx/xos-genx-tests/test_general_security.py
index 1a7b7ca..c675b16 100644
--- a/lib/xos-genx/xos-genx-tests/test_general_security.py
+++ b/lib/xos-genx/xos-genx-tests/test_general_security.py
@@ -1,4 +1,3 @@
-
# Copyright 2017-present Open Networking Foundation
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -21,33 +20,38 @@
"""The function below is for eliminating warnings arising due to the missing output_security_check,
which is generated and loaded dynamically.
"""
+
+
def output_security_check(x, y):
raise Exception("Security enforcer not generated. Test failed.")
return False
+
"""
-The tests below use the Python code target to generate
+The tests below use the Python code target to generate
Python security policies, set up an appropriate environment and execute the Python.
"""
+
+
class XProtoSecurityTest(unittest.TestCase):
def setUp(self):
- self.target = XProtoTestHelpers.write_tmp_target("""
+ self.target = XProtoTestHelpers.write_tmp_target(
+ """
{% for name, policy in proto.policies.items() %}
{{ xproto_fol_to_python_test(name, policy, None, '0') }}
{% endfor %}
-""")
+"""
+ )
def test_constant(self):
- xproto = \
-"""
+ xproto = """
policy output < True >
"""
- args = XOSProcessorArgs(inputs = xproto,
- target = self.target)
+ args = XOSProcessorArgs(inputs=xproto, target=self.target)
output = XOSProcessor.process(args)
- exec(output) # This loads the generated function, which should look like this:
+ exec(output) # This loads the generated function, which should look like this:
"""
def output_security_check(obj, ctx):
@@ -59,17 +63,15 @@
self.assertTrue(verdict)
def test_equal(self):
- xproto = \
-"""
+ xproto = """
policy output < ctx.user = obj.user >
"""
- args = XOSProcessorArgs(inputs = xproto,
- target = self.target)
+ args = XOSProcessorArgs(inputs=xproto, target=self.target)
output = XOSProcessor.process(args)
- exec(output) # This loads the generated function, which should look like this:
+ exec(output) # This loads the generated function, which should look like this:
"""
def output_security_check(obj, ctx):
@@ -85,18 +87,18 @@
verdict = output_security_check(obj, ctx)
def test_call_policy(self):
- xproto = \
-"""
+ xproto = """
policy sub_policy < ctx.user = obj.user >
policy output < *sub_policy(child) >
"""
- args = XOSProcessorArgs(inputs = xproto,
- target = self.target)
+ args = XOSProcessorArgs(inputs=xproto, target=self.target)
output = XOSProcessor.process(args)
- exec(output,globals()) # This loads the generated function, which should look like this:
+ exec(
+ output, globals()
+ ) # This loads the generated function, which should look like this:
"""
def sub_policy_security_check(obj, ctx):
@@ -105,10 +107,10 @@
def output_security_check(obj, ctx):
if obj.child:
- i1 = sub_policy_security_check(obj.child, ctx)
- else:
- i1 = True
- return i1
+ i1 = sub_policy_security_check(obj.child, ctx)
+ else:
+ i1 = True
+ return i1
"""
obj = FakeObject()
@@ -122,18 +124,18 @@
self.assertTrue(verdict)
def test_call_policy_child_none(self):
- xproto = \
-"""
+ xproto = """
policy sub_policy < ctx.user = obj.user >
policy output < *sub_policy(child) >
"""
- args = XOSProcessorArgs(inputs = xproto,
- target = self.target)
+ args = XOSProcessorArgs(inputs=xproto, target=self.target)
output = XOSProcessor.process(args)
- exec(output,globals()) # This loads the generated function, which should look like this:
+ exec(
+ output, globals()
+ ) # This loads the generated function, which should look like this:
"""
def sub_policy_security_check(obj, ctx):
@@ -142,10 +144,10 @@
def output_security_check(obj, ctx):
if obj.child:
- i1 = sub_policy_security_check(obj.child, ctx)
- else:
- i1 = True
- return i1
+ i1 = sub_policy_security_check(obj.child, ctx)
+ else:
+ i1 = True
+ return i1
"""
obj = FakeObject()
@@ -158,23 +160,21 @@
self.assertTrue(verdict)
def test_bin(self):
- xproto = \
-"""
+ xproto = """
policy output < ctx.is_admin = True | obj.empty = True>
"""
- args = XOSProcessorArgs(inputs = xproto,
- target = self.target)
+ args = XOSProcessorArgs(inputs=xproto, target=self.target)
output = XOSProcessor.process(args)
- exec(output) # This loads the generated function, which should look like this:
+ exec(output) # This loads the generated function, which should look like this:
"""
- def output_security_check(obj, ctx):
- i2 = (ctx.is_admin == True)
- i3 = (obj.empty == True)
- i1 = (i2 or i3)
- return i1
+ def output_security_check(obj, ctx):
+ i2 = (ctx.is_admin == True)
+ i3 = (obj.empty == True)
+ i1 = (i2 or i3)
+ return i1
"""
obj = FakeObject()
@@ -187,35 +187,30 @@
self.assertTrue(verdict)
-
def test_exists(self):
- xproto = \
-"""
+ xproto = """
policy output < exists Privilege: Privilege.object_id = obj.id >
"""
- args = XOSProcessorArgs(inputs = xproto,
- target = self.target)
+ args = XOSProcessorArgs(inputs=xproto, target=self.target)
output = XOSProcessor.process(args)
- exec(output) # This loads the generated function, which should look like this:
+ exec(output) # This loads the generated function, which should look like this:
"""
- def output_security_check(obj, ctx):
- i1 = Privilege.objects.filter(object_id=obj.id)
- return i1
+ def output_security_check(obj, ctx):
+ i1 = Privilege.objects.filter(object_id=obj.id)
+ return i1
"""
self.assertTrue(output_security_check is not None)
-
+
def test_python(self):
- xproto = \
-"""
+ xproto = """
policy output < {{ "jack" in ["the", "box"] }} = False >
"""
- args = XOSProcessorArgs(inputs = xproto,
- target = self.target)
+ args = XOSProcessorArgs(inputs=xproto, target=self.target)
output = XOSProcessor.process(args)
- exec(output) # This loads the generated function, which should look like this:
+ exec(output) # This loads the generated function, which should look like this:
"""
def output_security_check(obj, ctx):
@@ -228,13 +223,11 @@
def test_forall(self):
# This one we only parse
- xproto = \
-"""
+ xproto = """
policy output < forall Credential: Credential.obj_id = obj_id >
"""
- args = XOSProcessorArgs(inputs = xproto,
- target = self.target)
+ args = XOSProcessorArgs(inputs=xproto, target=self.target)
output = XOSProcessor.process(args)
"""
@@ -245,5 +238,6 @@
"""
exec(output)
-if __name__ == '__main__':
+
+if __name__ == "__main__":
unittest.main()