<commit_before># Copyright 2015 FUJITSU LIMITED
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.

from tempest import test

from monasca_log_api_tempest.tests import base

_RETRY_COUNT = 15
_RETRY_WAIT = 2


class TestSingleLog(base.BaseLogsTestCase):
    def _run_and_wait(self, key, data, version,
                      content_type='application/json', headers=None):

        headers = base._get_headers(headers, content_type)

        def wait():
            return self.logs_search_client.count_search_messages(key, headers) > 0

        self.assertEqual(0, self.logs_search_client.count_search_messages(key, headers),
                         'Find log message in elasticsearch: {0}'.format(key))

        headers = base._get_headers(headers, content_type)
        data = base._get_data(data, content_type, version=version)

        response, _ = self.logs_clients[version].send_single_log(data, headers)
        self.assertEqual(204, response.status)

        test.call_until_true(wait, _RETRY_COUNT * _RETRY_WAIT, _RETRY_WAIT)
        response = self.logs_search_client.search_messages(key, headers)
        self.assertEqual(1, len(response))

        return response

    @test.attr(type="gate")
    def test_small_message(self):
        for ver in self.logs_clients:
            self._run_and_wait(*base.generate_small_message(), version=ver)

    @test.attr(type="gate")
    def test_medium_message(self):
        for ver in self.logs_clients:
            self._run_and_wait(*base.generate_medium_message(), version=ver)

    @test.attr(type="gate")
    def test_big_message(self):
        for ver in self.logs_clients:
            self._run_and_wait(*base.generate_large_message(), version=ver)
<commit_msg>Switch to use test_utils.call_until_true<commit_after># Copyright 2015 FUJITSU LIMITED
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.

from tempest.lib.common.utils import test_utils
from tempest import test

from monasca_log_api_tempest.tests import base

_RETRY_COUNT = 15
_RETRY_WAIT = 2


class TestSingleLog(base.BaseLogsTestCase):
    def _run_and_wait(self, key, data, version,
                      content_type='application/json', headers=None):

        headers = base._get_headers(headers, content_type)

        def wait():
            return self.logs_search_client.count_search_messages(key, headers) > 0

        self.assertEqual(0, self.logs_search_client.count_search_messages(key, headers),
                         'Find log message in elasticsearch: {0}'.format(key))

        headers = base._get_headers(headers, content_type)
        data = base._get_data(data, content_type, version=version)

        response, _ = self.logs_clients[version].send_single_log(data, headers)
        self.assertEqual(204, response.status)

        test_utils.call_until_true(wait, _RETRY_COUNT * _RETRY_WAIT, _RETRY_WAIT)
        response = self.logs_search_client.search_messages(key, headers)
        self.assertEqual(1, len(response))

        return response

    @test.attr(type="gate")
    def test_small_message(self):
        for ver in self.logs_clients:
            self._run_and_wait(*base.generate_small_message(), version=ver)

    @test.attr(type="gate")
    def test_medium_message(self):
        for ver in self.logs_clients:
            self._run_and_wait(*base.generate_medium_message(), version=ver)

    @test.attr(type="gate")
    def test_big_message(self):
        for ver in self.logs_clients:
            self._run_and_wait(*base.generate_large_message(), version=ver)

{'fraction_non_alphanumeric': 0.08903654485049833, 'fraction_numerical': 0.007973421926910298, 'mean_word_length': 3.5250501002004007, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '131000', 'n_tokens_mistral': 1338, 'n_tokens_neox': 1289, 'n_words': 351}