<commit_before># This file is part of the GOsa framework.
#
#  http://gosa-project.org
#
# Copyright:
#  (C) 2016 GONICUS GmbH, Germany, http://www.gonicus.de
#
# See the LICENSE file in the project's top-level directory for details.

import pytest
from unittest import mock
from tests.GosaTestCase import *
from gosa.backend.objects.index import *


@slow
class ObjectBackendTestCase(GosaTestCase):

    def setUp(self):
        super(ObjectBackendTestCase, self).setUp()
        self.obj = PluginRegistry.getInstance("ObjectIndex")

    def test_insert(self):
        test = mock.MagicMock()
        test.uuid = '78475884-c7f2-1035-8262-f535be14d43a'
        test.asJSON.return_value = {'uuid': test.uuid}
        with pytest.raises(IndexException),\
                mock.patch.object(self.obj, "_ObjectIndex__save") as m:
            self.obj.insert(test)
            assert not m.called

        with mock.patch.object(self.obj, "_ObjectIndex__save") as m:
            test.uuid = '78475884-c7f2-1035-8262-f535be14d43b'
            test.asJSON.return_value = {'uuid': test.uuid}
            self.obj.insert(test)<commit_msg>rename<commit_after># This file is part of the GOsa framework.
#
#  http://gosa-project.org
#
# Copyright:
#  (C) 2016 GONICUS GmbH, Germany, http://www.gonicus.de
#
# See the LICENSE file in the project's top-level directory for details.

import pytest
from unittest import mock
from tests.GosaTestCase import *
from gosa.backend.objects.index import *


@slow
class ObjectIndexTestCase(GosaTestCase):

    def setUp(self):
        super(ObjectIndexTestCase, self).setUp()
        self.obj = PluginRegistry.getInstance("ObjectIndex")

    def test_insert(self):
        test = mock.MagicMock()
        test.uuid = '78475884-c7f2-1035-8262-f535be14d43a'
        test.asJSON.return_value = {'uuid': test.uuid}
        with pytest.raises(IndexException),\
                mock.patch.object(self.obj, "_ObjectIndex__save") as m:
            self.obj.insert(test)
            assert not m.called

        with mock.patch.object(self.obj, "_ObjectIndex__save") as m:
            test.uuid = '78475884-c7f2-1035-8262-f535be14d43b'
            test.asJSON.return_value = {'uuid': test.uuid}
            self.obj.insert(test)
{'fraction_non_alphanumeric': 0.11492204899777284, 'fraction_numerical': 0.048106904231625836, 'mean_word_length': 2.8791018998272886, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4661601', 'n_tokens_mistral': 799, 'n_tokens_neox': 726, 'n_words': 157}