forked from openml-labs/server-demo
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixing unittests by making sure Elasticsearch instance can also be cr…
…eated when ES_USER and ES_PASSWORD env vars are empty; used the style of PR #199
- Loading branch information
1 parent
120f97a
commit 3e5c446
Showing
5 changed files
with
94 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import os | ||
|
||
from elasticsearch import Elasticsearch | ||
|
||
|
||
class ElasticsearchSingleton: | ||
""" | ||
Making sure the Elasticsearch client is created only once, and easy to patch for | ||
unittests. | ||
""" | ||
|
||
__monostate = None | ||
|
||
def __init__(self): | ||
if not ElasticsearchSingleton.__monostate: | ||
ElasticsearchSingleton.__monostate = self.__dict__ | ||
user = os.getenv("ES_USER", "") | ||
pw = os.getenv("ES_PASSWORD", "") | ||
self.client = Elasticsearch("http://elasticsearch:9200", basic_auth=(user, pw)) | ||
else: | ||
self.__dict__ = ElasticsearchSingleton.__monostate | ||
|
||
def patch(self, elasticsearch: Elasticsearch): | ||
self.__monostate["client"] = elasticsearch # type:ignore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters