Пример #1
0
 def test_should_abort_if_waiting_for_long_time(self):
     es = Elasticlog(hosts=['172.17.0.254'], index='loggo', timeout=1, max_retries=0)
     try:
         es.insert(filename='views.py', level='error', created_at='invalid', message='object not found')
         fail()
     except:
         pass
Пример #2
0
 def test_should_abort_if_waiting_for_long_time(self):
     es = Elasticlog(hosts=['172.17.0.254'],
                     index='loggo',
                     timeout=1,
                     max_retries=0)
     try:
         es.insert(filename='views.py',
                   level='error',
                   created_at='invalid',
                   message='object not found')
         fail()
     except:
         pass
Пример #3
0
 def setUp(self):
     self.es = Elasticlog(hosts=[HOST], index=INDEX_NAME)
Пример #4
0
class TestElasticlog(unittest.TestCase):
    def setUp(self):
        self.es = Elasticlog(hosts=[HOST], index=INDEX_NAME)

    def tearDown(self):
        Index(INDEX_NAME).delete()

    def test_should_insert_data(self):
        inserted = self.es.insert(filename='views.py',
                                  level='error',
                                  created_at='2015-07-18',
                                  message='object not found')
        self.assertTrue(inserted)

    def test_should_insert_empty_date_if_it_is_invalid(self):
        inserted = self.es.insert(filename='views.py',
                                  level='error',
                                  created_at='invalid',
                                  message='object not found')
        self.assertTrue(inserted)

    def test_should_list_the_first_ten(self):
        fixtures()

        logs = self.es.search()
        self.assertEquals(6, len(logs))

        log = logs[0]
        self.assertTrue(len(log.id) > 0)
        self.assertEquals(log.level, 'ERROR')
        self.assertEquals(log.filename, 'views')
        self.assertEquals(
            log.message,
            'elasticsearch.exceptions.ConnectionError: ConnectionError')

    def test_should_paginate_the_result(self):
        fixtures()

        logs = self.es.search(page=1, per_page=2)
        self.assertEquals(2, len(logs))

        log = logs[0]
        self.assertTrue(len(log.id) > 0)
        self.assertEquals(log.level, 'ERROR')
        self.assertEquals(log.filename, 'views')
        self.assertEquals(
            log.message,
            'elasticsearch.exceptions.ConnectionError: ConnectionError')

    def test_should_sort_asc(self):
        fixtures()
        logs = self.es.search(sort='created_at')
        log = logs[0]
        self.assertEquals(str(log.created_at), '2015-01-02 00:00:00')
        self.assertEquals(log.level, 'ERROR')
        self.assertEquals(log.filename, 'custom_views')
        self.assertEquals(log.message,
                          'NameError: name "request" is not defined')

    def test_should_sort_desc(self):
        fixtures()
        logs = self.es.search(sort='-created_at')
        log = logs[0]
        self.assertEquals(str(log.created_at), '2015-04-04 00:00:00')
        self.assertEquals(log.level, 'DEBUG')
        self.assertEquals(log.filename, 'models')
        self.assertEquals(
            log.message,
            'AttributeError: "str" object has no attribute "xpto"')

    def test_should_filter_by_date_interval(self):
        fixtures()
        logs = self.es.search(start='2015-01-01T00:00:00',
                              end='2015-02-21T00:00:00')
        self.assertEquals(4, len(logs))

        log = logs[0]
        self.assertEquals(str(log.created_at), '2015-01-10 00:00:00')
        self.assertEquals(log.level, 'ERROR')
        self.assertEquals(log.filename, 'views')
        self.assertEquals(
            log.message,
            'elasticsearch.exceptions.ConnectionError: ConnectionError')

    def test_should_raises_exception_if_pass_an_invalid_date_interval(self):
        fixtures()
        try:
            logs = self.es.search(start='invalid', end='2015-02-21')
            fail()
        except:
            pass

    def test_should_count_the_total_of_logs(self):
        fixtures()
        response = self.es.count()
        self.assertEquals(response.get('count'), 6)
Пример #5
0
 def setUp(self):
     self.es = Elasticlog(hosts=[HOST], index=INDEX_NAME)
Пример #6
0
class TestElasticlog(unittest.TestCase):

    def setUp(self):
        self.es = Elasticlog(hosts=[HOST], index=INDEX_NAME)

    def tearDown(self):
        Index(INDEX_NAME).delete()

    def test_should_insert_data(self):
        inserted = self.es.insert(filename='views.py', level='error', created_at='2015-07-18', message='object not found')
        self.assertTrue(inserted)

    def test_should_insert_empty_date_if_it_is_invalid(self):
        inserted = self.es.insert(filename='views.py', level='error', created_at='invalid', message='object not found')
        self.assertTrue(inserted)

    def test_should_list_the_first_ten(self):
        fixtures()

        logs = self.es.search()
        self.assertEquals(6, len(logs))

        log = logs[0]
        self.assertTrue(len(log.id) > 0)
        self.assertEquals(log.level, 'ERROR')
        self.assertEquals(log.filename, 'views')
        self.assertEquals(log.message, 'elasticsearch.exceptions.ConnectionError: ConnectionError')

    def test_should_paginate_the_result(self):
        fixtures()

        logs = self.es.search(page=1, per_page=2)
        self.assertEquals(2, len(logs))

        log = logs[0]
        self.assertTrue(len(log.id) > 0)
        self.assertEquals(log.level, 'ERROR')
        self.assertEquals(log.filename, 'views')
        self.assertEquals(log.message, 'elasticsearch.exceptions.ConnectionError: ConnectionError')

    def test_should_sort_asc(self):
        fixtures()
        logs = self.es.search(sort='created_at')
        log = logs[0]
        self.assertEquals(str(log.created_at), '2015-01-02 00:00:00')
        self.assertEquals(log.level, 'ERROR')
        self.assertEquals(log.filename, 'custom_views')
        self.assertEquals(log.message, 'NameError: name "request" is not defined')

    def test_should_sort_desc(self):
        fixtures()
        logs = self.es.search(sort='-created_at')
        log = logs[0]
        self.assertEquals(str(log.created_at), '2015-04-04 00:00:00')
        self.assertEquals(log.level, 'DEBUG')
        self.assertEquals(log.filename, 'models')
        self.assertEquals(log.message, 'AttributeError: "str" object has no attribute "xpto"')

    def test_should_filter_by_date_interval(self):
        fixtures()
        logs = self.es.search(start='2015-01-01T00:00:00', end='2015-02-21T00:00:00')
        self.assertEquals(4, len(logs))

        log = logs[0]
        self.assertEquals(str(log.created_at), '2015-01-10 00:00:00')
        self.assertEquals(log.level, 'ERROR')
        self.assertEquals(log.filename, 'views')
        self.assertEquals(log.message, 'elasticsearch.exceptions.ConnectionError: ConnectionError')

    def test_should_raises_exception_if_pass_an_invalid_date_interval(self):
        fixtures()
        try:
            logs = self.es.search(start='invalid', end='2015-02-21')
            fail()
        except:
            pass

    def test_should_count_the_total_of_logs(self):
        fixtures()
        response = self.es.count()
        self.assertEquals(response.get('count'), 6)