Пример #1
0
    def test_handler_exception(self):
        logger = logging.getLogger('_bilor_testing')
        handler = BilorHandler(self.live_server_url)
        logger.addHandler(handler)
        logger.setLevel(logging.ERROR)

        try:
            1 / 0
        except Exception:
            logger.exception('this is an exception message')

        es = connect_elasticsearch()
        es.indices.refresh()

        result = es.search(
            index=settings.ELASTICSEARCH_CONNECTION['index_name'],
            body={'query': {'match_all': {}}}
        )

        hit = result['hits']['hits'][0]
        assert hit['_type'] == 'message'
        source = hit['_source']

        assert source['level'] == logging.ERROR
        assert source['traceback']['title'] == 'ZeroDivisionError: division by zero'
        assert source['traceback']['exception_type'] == 'builtins.ZeroDivisionError'
Пример #2
0
    def _check(self, expected):
        es = connect_elasticsearch()
        es.indices.refresh()

        result = es.search(
            index=settings.ELASTICSEARCH_CONNECTION['index_name'],
            body={'query': {'match_all': {}}}
        )

        hit = result['hits']['hits'][0]
        assert hit['_type'] == 'message'
        assert hit['_source'] == expected
Пример #3
0
    def test_create_new_message(self):
        url = reverse('api-v1:message')

        # We do not yet actually validate the data. So check that
        # we simply save it in elastic search.
        data = {'test': 'test'}
        response = self.client.post(url, data, format='json')
        self.assertEqual(response.status_code, status.HTTP_201_CREATED)
        self.assertEqual(response.content, b'success')

        es = connect_elasticsearch()
        es.indices.refresh()

        result = es.search(
            index=settings.ELASTICSEARCH_CONNECTION['index_name'],
            body={'query': {'match_all': {}}}
        )

        hit = result['hits']['hits'][0]
        assert hit['_type'] == 'message'
        assert hit['_source'] == {'test': 'test'}
Пример #4
0
def clear_elasticsearch_index():
    es = connect_elasticsearch()
    es.indices.delete(index=settings.ELASTICSEARCH_CONNECTION['index_name'])
    es.indices.refresh()