Ejemplo n.º 1
0
    def test_failure_on_initial_get(self, mocker):
        get_mock = mocker.patch.object(utils, 'get')
        get_mock.side_effect = errors.Error('Bad error')
        set_module_args(name='test_user', password='******')

        with pytest.raises(AnsibleFailJson):
            user.main()
Ejemplo n.º 2
0
    def test_failure(self, mocker):
        get_mock = mocker.patch.object(utils, 'get')
        get_mock.return_value = None
        sync_mock = mocker.patch.object(user, 'sync')
        sync_mock.side_effect = errors.Error('Bad error')
        set_module_args(name='test_user', password='******')

        with pytest.raises(AnsibleFailJson):
            user.main()
Ejemplo n.º 3
0
    def test_failure_on_missing_bcrypt_5_21_0_or_newer(self, mocker):
        mocker.patch.object(
            arguments, 'get_sensu_client').return_value = (mocker.MagicMock(
                version='5.22.3'))
        mocker.patch.object(user, 'HAS_BCRYPT', False)
        set_module_args(name='test_user', password='******')

        with pytest.raises(AnsibleFailJson, match='bcrypt'):
            user.main()
Ejemplo n.º 4
0
    def test_cannot_create_user_without_password(self, mocker):
        get_mock = mocker.patch.object(utils, 'get')
        get_mock.return_value = None
        set_module_args(
            name='test_user',
            state='disabled',
            groups=['dev', 'ops'],
        )

        with pytest.raises(AnsibleFailJson, match='without a password'):
            user.main()
Ejemplo n.º 5
0
    def test_disable_non_existent_user(self, mocker):
        get_mock = mocker.patch.object(utils, 'get')
        get_mock.return_value = None
        set_module_args(
            name='test_user',
            state='disabled',
            groups=['dev', 'ops'],
        )

        with pytest.raises(AnsibleFailJson,
                           match='Cannot disable a non existent user'):
            user.main()
Ejemplo n.º 6
0
    def test_minimal_parameters_on_existing_user(self, mocker):
        get_mock = mocker.patch.object(utils, 'get')
        get_mock.return_value = dict(username='******')
        sync_mock = mocker.patch.object(user, 'sync')
        sync_mock.return_value = True, {}
        set_module_args(name='alice')

        with pytest.raises(AnsibleExitJson):
            user.main()

        result, _client, path, payload, check_mode = sync_mock.call_args[0]
        assert path == '/api/core/v2/users/alice'
        assert payload == dict(username='******', disabled=False)
        assert check_mode is False
Ejemplo n.º 7
0
    def test_minimal_user_parameters(self, mocker):
        get_mock = mocker.patch.object(utils, 'get')
        get_mock.return_value = None
        sync_mock = mocker.patch.object(user, 'sync')
        sync_mock.return_value = True, {}
        set_module_args(
            name='alice',
            password='******',
        )

        with pytest.raises(AnsibleExitJson):
            user.main()

        object, state, _client, path, payload, check_mode = sync_mock.call_args[
            0]
        assert state == 'enabled'
        assert path == '/api/core/v2/users/alice'
        assert payload == dict(username='******',
                               password='******',
                               disabled=False)
        assert check_mode is False
Ejemplo n.º 8
0
    def test_all_user_parameters(self, mocker):
        get_mock = mocker.patch.object(utils, 'get')
        get_mock.return_value = None
        sync_mock = mocker.patch.object(user, 'sync')
        sync_mock.return_value = True, {}
        set_module_args(
            name='test_user',
            state='disabled',
            password='******',
            groups=['dev', 'ops'],
        )

        with pytest.raises(AnsibleExitJson):
            user.main()

        result, _client, path, payload, check_mode = sync_mock.call_args[0]
        assert path == '/api/core/v2/users/test_user'
        assert payload == dict(username='******',
                               password='******',
                               groups=['dev', 'ops'],
                               disabled=True)
        assert check_mode is False