예제 #1
0
    def test_init(self):
        """``ElasticSearch`` does not IO upon __init__ of object"""
        es = elasticsearch.ElasticSearch(server='8.8.8.8',
                                         user='******',
                                         password='******',
                                         doc_type='someLogCategory')

        self.assertTrue(isinstance(es, elasticsearch.ElasticSearch))
예제 #2
0
    def test_index(self):
        """``ElasticSearch`` the 'index' property has the correct daily format"""
        es = elasticsearch.ElasticSearch(server='8.8.8.8',
                                         user='******',
                                         password='******',
                                         doc_type='someLogCategory')

        index = es.index
        expected = time.strftime('logs-%Y.%m.%d')

        self.assertEqual(index, expected)
예제 #3
0
    def test_close(self, fake_Session):
        """``ElasticSearch`` 'close' terminates the TCP socket with the ElasticSearch server"""
        fake_resp = MagicMock()
        fake_session = MagicMock()
        fake_session.post.return_value = fake_resp
        fake_Session.return_value = fake_session
        es = elasticsearch.ElasticSearch(server='8.8.8.8',
                                         user='******',
                                         password='******',
                                         doc_type='someLogCategory')

        es.close()

        self.assertTrue(fake_session.close.called)
예제 #4
0
    def test_write(self, fake_Session):
        """``ElasticSearch`` 'write' checks that the HTTP response was OK automatically"""
        fake_resp = MagicMock()
        fake_session = MagicMock()
        fake_session.post.return_value = fake_resp
        fake_Session.return_value = fake_session
        es = elasticsearch.ElasticSearch(server='8.8.8.8',
                                         user='******',
                                         password='******',
                                         doc_type='someLogCategory')

        es.write(document='{"some":"JSON"}')

        self.assertTrue(fake_resp.raise_for_status.called)
예제 #5
0
    def test_write_url(self, fake_Session):
        """``ElasticSearch`` 'write' constructs the correct URL"""
        fake_resp = MagicMock()
        fake_session = MagicMock()
        fake_session.post.return_value = fake_resp
        fake_Session.return_value = fake_session
        es = elasticsearch.ElasticSearch(server='8.8.8.8',
                                         user='******',
                                         password='******',
                                         doc_type='someLogCategory')

        es.write(document='{"some":"JSON"}')

        the_args, _ = fake_session.post.call_args
        url = the_args[0]
        expected = 'https://8.8.8.8:9200/{}/someLogCategory'.format(
            time.strftime('logs-%Y.%m.%d'))

        self.assertEqual(url, expected)