"Fossies" - the Fresh Open Source Software Archive

Member "salt-3002.2/tests/unit/returners/test_elasticsearch_return.py" (18 Nov 2020, 1357 Bytes) of package /linux/misc/salt-3002.2.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

    1 """
    2 Test the elasticsearch returner
    3 """
    4 import salt.returners.elasticsearch_return as elasticsearch_return
    5 from tests.support.mixins import LoaderModuleMockMixin
    6 from tests.support.mock import MagicMock, patch
    7 from tests.support.unit import TestCase
    8 
    9 
   10 class ElasticSearchReturnerTestCase(TestCase, LoaderModuleMockMixin):
   11     """
   12     Test the functions in the elasticsearch returner
   13     """
   14 
   15     def setup_loader_modules(self):
   16         return {elasticsearch_return: {}}
   17 
   18     def test__virtual_no_elasticsearch(self):
   19         """
   20         Test __virtual__ function when elasticsearch is not installed
   21         and the elasticsearch module is not available
   22         """
   23         result = elasticsearch_return.__virtual__()
   24         expected = (
   25             False,
   26             "Elasticsearch module not availble.  Check that the elasticsearch library is installed.",
   27         )
   28         self.assertEqual(expected, result)
   29 
   30     def test__virtual_with_elasticsearch(self):
   31         """
   32         Test __virtual__ function when elasticsearch
   33         and the elasticsearch module is not available
   34         """
   35         with patch.dict(
   36             elasticsearch_return.__salt__, {"elasticsearch.index_exists": MagicMock()}
   37         ):
   38             result = elasticsearch_return.__virtual__()
   39             expected = "elasticsearch"
   40             self.assertEqual(expected, result)