예제 #1
0
 def test_if_all_methods_catch_exception(self):
     data = self.set_default_args()
     data.update({'role_name': 'test'})
     set_module_args(data)
     my_obj = my_module()
     if not self.onbox:
         my_obj.server = MockONTAPConnection('user_fail')
     with pytest.raises(AnsibleFailJson) as exc:
         my_obj.get_user()
     assert 'Error getting user ' in exc.value.args[0]['msg']
     with pytest.raises(AnsibleFailJson) as exc:
         my_obj.create_user(data['applications'])
     assert 'Error creating user ' in exc.value.args[0]['msg']
     with pytest.raises(AnsibleFailJson) as exc:
         my_obj.lock_given_user()
     assert 'Error locking user ' in exc.value.args[0]['msg']
     with pytest.raises(AnsibleFailJson) as exc:
         my_obj.unlock_given_user()
     assert 'Error unlocking user ' in exc.value.args[0]['msg']
     with pytest.raises(AnsibleFailJson) as exc:
         my_obj.delete_user(data['applications'])
     assert 'Error removing user ' in exc.value.args[0]['msg']
     with pytest.raises(AnsibleFailJson) as exc:
         my_obj.change_password()
     assert 'Error setting password for user ' in exc.value.args[0]['msg']
     with pytest.raises(AnsibleFailJson) as exc:
         my_obj.modify_user(data['applications'])
     assert 'Error modifying user ' in exc.value.args[0]['msg']
예제 #2
0
 def test_ensure_user_get_called(self):
     ''' a more interesting test '''
     module_args = {}
     module_args.update(self.set_default_args())
     module_args.update({'role_name': 'test'})
     set_module_args(module_args)
     my_obj = my_module()
     my_obj.server = self.server
     user_info = my_obj.get_user()
     print('Info: test_user_get: %s' % repr(user_info))
     assert user_info is None
예제 #3
0
 def test_ensure_user_apply_for_delete_called(self):
     ''' deleting user and checking idempotency '''
     module_args = {}
     module_args.update(self.set_default_args())
     module_args.update({'name': 'create'})
     module_args.update({'role_name': 'test'})
     set_module_args(module_args)
     my_obj = my_module()
     if not self.onbox:
         my_obj.server = MockONTAPConnection('user', 'false', 'test')
     with pytest.raises(AnsibleExitJson) as exc:
         my_obj.apply()
     print('Info: test_user_apply: %s' % repr(exc.value))
     assert not exc.value.args[0]['changed']
     module_args.update({'state': 'absent'})
     set_module_args(module_args)
     my_obj = my_module()
     if not self.onbox:
         my_obj.server = MockONTAPConnection('user', 'false', 'test')
     with pytest.raises(AnsibleExitJson) as exc:
         my_obj.apply()
     print('Info: test_user_delete: %s' % repr(exc.value))
     assert exc.value.args[0]['changed']
예제 #4
0
 def test_ensure_user_role_update_called(self):
     ''' set password '''
     module_args = {}
     module_args.update(self.set_default_args())
     module_args.update({'name': 'create'})
     module_args.update({'role_name': 'test123'})
     module_args.update({'set_password': '******'})
     set_module_args(module_args)
     my_obj = my_module()
     if not self.onbox:
         my_obj.server = MockONTAPConnection('user', 'true')
     with pytest.raises(AnsibleExitJson) as exc:
         my_obj.apply()
     print('Info: test_user_apply: %s' % repr(exc.value))
     assert exc.value.args[0]['changed']
예제 #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'])