コード例 #1
0
 def test_successful_create(self, create_namespace):
     ''' creating namespace and testing idempotency '''
     set_module_args(self.set_default_args())
     my_obj = my_module()
     if not self.onbox:
         my_obj.server = self.server
     with pytest.raises(AnsibleExitJson) as exc:
         my_obj.apply()
     assert exc.value.args[0]['changed']
     create_namespace.assert_called_with()
     # to reset na_helper from remembering the previous 'changed' value
     my_obj = my_module()
     if not self.onbox:
         my_obj.server = MockONTAPConnection('namespace')
     with pytest.raises(AnsibleExitJson) as exc:
         my_obj.apply()
     assert not exc.value.args[0]['changed']
コード例 #2
0
 def test_if_all_methods_catch_exception(self):
     module_args = {}
     module_args.update(self.set_default_args())
     set_module_args(module_args)
     my_obj = my_module()
     if not self.onbox:
         my_obj.server = MockONTAPConnection('quota_fail')
     with pytest.raises(AnsibleFailJson) as exc:
         my_obj.get_namespace()
     assert 'Error fetching namespace info:' in exc.value.args[0]['msg']
     with pytest.raises(AnsibleFailJson) as exc:
         my_obj.create_namespace()
     assert 'Error creating namespace for path' in exc.value.args[0]['msg']
     with pytest.raises(AnsibleFailJson) as exc:
         my_obj.delete_namespace()
     assert 'Error deleting namespace for path' in exc.value.args[0]['msg']
コード例 #3
0
 def test_ensure_get_called(self):
     ''' test get_namespace()  for non-existent namespace'''
     set_module_args(self.set_default_args())
     my_obj = my_module()
     my_obj.server = self.server
     assert my_obj.get_namespace() is None
コード例 #4
0
 def test_ensure_get_called_existing(self):
     ''' test get_namespace()  for existing namespace'''
     set_module_args(self.set_default_args())
     my_obj = my_module()
     my_obj.server = MockONTAPConnection(kind='namespace')
     assert my_obj.get_namespace()
コード例 #5
0
 def test_module_fail_when_required_args_missing(self):
     ''' required arguments are reported as errors '''
     with pytest.raises(AnsibleFailJson) as exc:
         set_module_args({})
         my_module()
     print('Info: %s' % exc.value.args[0]['msg'])