Exemplo n.º 1
0
 def test_rest_error_applications_snmp(self, mock_request):
     data = self.set_default_args(rest=True)
     data.update({'applications': 'snmp'})
     data.update({'name': 'create'})
     data.update({'role_name': 'test123'})
     data.update({'set_password': '******'})
     set_module_args(data)
     mock_request.side_effect = [SRR['is_rest'], SRR['end_of_sequence']]
     with pytest.raises(AnsibleFailJson) as exc:
         my_module()
     assert exc.value.args[0][
         'msg'] == "Snmp as application is not supported in REST."
Exemplo n.º 2
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']
Exemplo n.º 3
0
def test_ensure_user_get_rest_called(mock_request, mock_fail):
    mock_fail.side_effect = fail_json
    mock_request.side_effect = [
        SRR['is_rest'], SRR['get_user_rest'], SRR['end_of_sequence']
    ]
    set_module_args(set_default_args_rest())
    my_obj = my_module()
    assert my_obj.get_user_rest() is not None
Exemplo n.º 4
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
Exemplo n.º 5
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']
Exemplo n.º 6
0
def test_ensure_create_user_rest_called(mock_request, mock_fail, mock_exit):
    mock_fail.side_effect = fail_json
    mock_exit.side_effect = exit_json
    mock_request.side_effect = [
        SRR['is_rest'],
        SRR['get_user_rest'],
        SRR['get_user_details_rest'],
        SRR['get_user_rest'],
    ]
    set_module_args(set_default_args_rest())
    my_obj = my_module()
    with pytest.raises(AnsibleExitJson) as exc:
        my_obj.apply()
    assert exc.value.args[0]['changed']
Exemplo n.º 7
0
 def test_ensure_user_sp_apply_called(self):
     ''' creating user with service_processor application and idempotency '''
     module_args = {}
     module_args.update(self.set_default_args())
     module_args.update({'name': 'create'})
     module_args.update({'role_name': 'test'})
     module_args.update({'application': 'service-processor'})
     set_module_args(module_args)
     my_obj = my_module()
     if not self.onbox:
         my_obj.server = self.server
     with pytest.raises(AnsibleExitJson) as exc:
         my_obj.apply()
     print('Info: test_user_sp: %s' % repr(exc.value))
     assert exc.value.args[0]['changed']
     if not self.onbox:
         my_obj.server = MockONTAPConnection('user', 'false')
     with pytest.raises(AnsibleExitJson) as exc:
         my_obj.apply()
     print('Info: test_user_sp: %s' % repr(exc.value))
     assert exc.value.args[0]['changed']
     ''' creating user with service_processor application and idempotency '''
     module_args.update({'application': 'service_processor'})
     set_module_args(module_args)
     my_obj = my_module()
     if not self.onbox:
         my_obj.server = self.server
     with pytest.raises(AnsibleExitJson) as exc:
         my_obj.apply()
     print('Info: test_user_sp: %s' % repr(exc.value))
     assert exc.value.args[0]['changed']
     if not self.onbox:
         my_obj.server = MockONTAPConnection('user', 'false')
     with pytest.raises(AnsibleExitJson) as exc:
         my_obj.apply()
     print('Info: test_user_sp: %s' % repr(exc.value))
     assert exc.value.args[0]['changed']
Exemplo n.º 8
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']
Exemplo n.º 9
0
def test_ensure_modify_user_rest_called(mock_request, mock_fail, mock_exit):
    mock_fail.side_effect = fail_json
    mock_exit.side_effect = exit_json
    mock_request.side_effect = [
        SRR['is_rest'], SRR['get_user_rest'], SRR['get_user_details_rest'],
        SRR['get_user_rest'], SRR['empty_good'], SRR['end_of_sequence']
    ]
    data = {
        'application': 'ssh',
    }
    data.update(set_default_args_rest())
    set_module_args(data)
    my_obj = my_module()
    with pytest.raises(AnsibleExitJson) as exc:
        my_obj.apply()
    assert exc.value.args[0]['changed']
Exemplo n.º 10
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'])