sputnik13 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_r357882620
 
 

 ##########
 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:
   You are correct it is doing a set subtraction, however, this test is just 
validating that the things that were added are present, not that they're the 
only things present, e.g. expected_host_vars should be a subset of 
all_host_vars rather than the reverse.  It could be argued that given we have 
complete control that expected_host_vars should equal all_host_vars, but 
all_host_vars being a subset of expected_host_vars shouldn't be the check.

----------------------------------------------------------------
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:
[email protected]


With regards,
Apache Git Services

Reply via email to