<commit_before># Copyright 2017 Nokia
#
#    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 datetime import datetime
from oslo_log import log as logging
from oslotest import base

from vitrage.common.constants import DatasourceProperties as DSProps
from vitrage.common.constants import EntityCategory
from vitrage.common.constants import EventProperties as EventProps
from vitrage.common.constants import VertexProperties as VProps
from vitrage import keystone_client
from vitrage import service
from vitrageclient import client as v_client

LOG = logging.getLogger(__name__)


class TestEvents(base.BaseTestCase):
    """Test class for Vitrage event API"""

    # noinspection PyPep8Naming
    @classmethod
    def setUpClass(cls):
        cls.conf = service.prepare_service([])
        cls.vitrage_client = \
            v_client.Client('1', session=keystone_client.get_session(cls.conf))

    def test_send_doctor_event(self):
        """Sending an event in Doctor format should result in an alarm"""
        try:
            # post an event to the message bus
            event_time = datetime.now().isoformat()
            event_type = 'compute.host.down'
            details = {
                'hostname': 'host123',
                'source': 'sample_monitor',
                'cause': 'another alarm',
                'severity': 'critical',
                'status': 'down',
                'monitor_id': 'sample monitor',
                'monitor_event_id': '456',
            }

            self.vitrage_client.event.post(event_time, event_type, details)

            # list all alarms
            api_alarms = self.vitrage_client.alarm.list(vitrage_id=None,
                                                        all_tenants=False)

            # expect to get a 'host down alarm', generated by Doctor datasource
            self.assertIsNotNone(api_alarms, 'Expected host down alarm')
            self.assertEqual(1, len(api_alarms), 'Expected host down alarm')
            alarm = api_alarms[0]

            self._wait_for_status(2,
                                  self._check_alarm,
                                  alarm=alarm,
                                  event_time=event_time,
                                  event_type=event_type,
                                  details=details)

        except Exception as e:
            LOG.exception(e)
            raise<commit_msg>fix the vitrage id in test<commit_after># Copyright 2017 Nokia
#
#    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 datetime import datetime
from oslo_log import log as logging
from oslotest import base

from vitrage.common.constants import DatasourceProperties as DSProps
from vitrage.common.constants import EntityCategory
from vitrage.common.constants import EventProperties as EventProps
from vitrage.common.constants import VertexProperties as VProps
from vitrage import keystone_client
from vitrage import service
from vitrageclient import client as v_client

LOG = logging.getLogger(__name__)


class TestEvents(base.BaseTestCase):
    """Test class for Vitrage event API"""

    # noinspection PyPep8Naming
    @classmethod
    def setUpClass(cls):
        cls.conf = service.prepare_service([])
        cls.vitrage_client = \
            v_client.Client('1', session=keystone_client.get_session(cls.conf))

    def test_send_doctor_event(self):
        """Sending an event in Doctor format should result in an alarm"""
        try:
            # post an event to the message bus
            event_time = datetime.now().isoformat()
            event_type = 'compute.host.down'
            details = {
                'hostname': 'host123',
                'source': 'sample_monitor',
                'cause': 'another alarm',
                'severity': 'critical',
                'status': 'down',
                'monitor_id': 'sample monitor',
                'monitor_event_id': '456',
            }

            self.vitrage_client.event.post(event_time, event_type, details)

            # list all alarms
            api_alarms = self.vitrage_client.alarm.list(vitrage_id='all',
                                                        all_tenants=False)

            # expect to get a 'host down alarm', generated by Doctor datasource
            self.assertIsNotNone(api_alarms, 'Expected host down alarm')
            self.assertEqual(1, len(api_alarms), 'Expected host down alarm')
            alarm = api_alarms[0]

            self._wait_for_status(2,
                                  self._check_alarm,
                                  alarm=alarm,
                                  event_time=event_time,
                                  event_type=event_type,
                                  details=details)

        except Exception as e:
            LOG.exception(e)
            raise
{'fraction_non_alphanumeric': 0.07252298263534218, 'fraction_numerical': 0.006469186244467144, 'mean_word_length': 2.1019007391763465, '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': 14, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3396799', 'n_tokens_mistral': 1533, 'n_tokens_neox': 1468, 'n_words': 482}