You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@fluo.apache.org by GitBox <gi...@apache.org> on 2020/02/11 18:02:10 UTC

[GitHub] [fluo-muchos] arvindshmicrosoft commented on a change in pull request #296: added unit tests for decorator and validators

arvindshmicrosoft commented on a change in pull request #296: added unit tests for decorator and validators
URL: https://github.com/apache/fluo-muchos/pull/296#discussion_r377803599
 
 

 ##########
 File path: lib/tests/test_decorators.py
 ##########
 @@ -0,0 +1,114 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#    http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+from unittest import TestCase
+
+from muchos.config import decorators
+
+
+class DecoratedThing(object):
+    @property
+    @decorators.ansible_host_var
+    def host_var1(self):
+        return 'host_var1'
+
+    @property
+    @decorators.ansible_host_var(name='named_host_var2')
+    def host_var2(self):
+        return 'named_host_var2'
+
+    @property
+    @decorators.ansible_play_var
+    def play_var1(self):
+        return 'play_var1'
+
+    @property
+    @decorators.ansible_play_var(name='named_play_var2')
+    def play_var2(self):
+        return 'named_play_var2'
+
+    @property
+    @decorators.ansible_extra_var
+    def extra_var1(self):
+        return 'extra_var1'
+
+    @property
+    @decorators.ansible_extra_var(name='named_extra_var2')
+    def extra_var2(self):
+        return 'named_extra_var2'
+
+    @property
+    @decorators.default('default_val')
+    def default_val(self):
+        return None
+
+    @property
+    @decorators.required
+    def required_val(self):
+        return 'required_val'
+
+    @property
+    @decorators.required
+    def missing_required_val(self):
+        return None
+
+
+class DecoratorTests(TestCase):
+    def _flatten_dict(d):
+        return {(k, v) for k, v in d.items()}
+
+    def test_decorators(self):
+        thing = DecoratedThing()
+
+        all_host_vars = decorators.get_ansible_vars('host')
+        all_play_vars = decorators.get_ansible_vars('play')
+        all_extra_vars = decorators.get_ansible_vars('extra')
+
+        expected_host_vars = [
+            decorators._ansible_var('host_var1', 'DecoratedThing', 'host_var1'),
+            decorators._ansible_var('named_host_var2', 'DecoratedThing', 'host_var2')
+        ]
+
+        expected_play_vars = [
+            decorators._ansible_var('play_var1', 'DecoratedThing', 'play_var1'),
+            decorators._ansible_var('named_play_var2', 'DecoratedThing', 'play_var2')
+        ]
+
+        expected_extra_vars = [
+            decorators._ansible_var('extra_var1', 'DecoratedThing', 'extra_var1'),
+            decorators._ansible_var('named_extra_var2', 'DecoratedThing', 'extra_var2')
+        ]
+
+        self.assertEquals(
+            set([str(v) for v in expected_host_vars]) - set([str(v) for v in all_host_vars]),
 
 Review comment:
   I'm picking this PR up on behalf of @sputnik13 - to respond to the last question, I checked and the unit tests as they stand right now will not pickup the case wherein the same variable was added to multiple variable groups. I can think through if / how we can catch that kind of fundamental issue with the code.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services