1 #!/usr/bin/python 2 3 import unittest 4 5 import elasticsearch_mock as elasticsearch 6 7 class statsd_mock_test(unittest.TestCase): 8 """Test statsd_mock""" 9 def setUp(self): 10 self.es = elasticsearch.Elasticsearch(host='host', 11 port=1, 12 timeout=10) 13 14 15 def test_index_call_mock(self): 16 """Test mock Elasticsearch.index method""" 17 self.es.index(index='blah', doc_type='blah blah', body='random') 18 19 20 def test_index_exists_mock(self): 21 """Test mock Elasticsearch.indices.exists method""" 22 self.es.indices.exists(index='random index') 23 24 25 def test_index_delete_mock(self): 26 """Test mock Elasticsearch.indices.delete method""" 27 self.es.indices.delete(index='random index') 28 29 30 def test_search_mock(self): 31 """Test mock Elasticsearch.search method""" 32 self.es.search(index='index', body='query') 33 34 35 def test_exception_mock(self): 36 """Test mock elasticsearch.ElasticsearchException method""" 37 try: 38 raise elasticsearch.ElasticsearchException('error message') 39 except elasticsearch.ElasticsearchException as e: 40 pass 41 42 43 if __name__ == '__main__': 44 unittest.main()