From e3ae177b05764a7258601248b1544b7faf654faa Mon Sep 17 00:00:00 2001 From: Shyam Dwaraknath Date: Wed, 29 Jan 2020 18:40:22 -0800 Subject: [PATCH 1/4] add mongo_uri to config --- optimade/server/config.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/optimade/server/config.py b/optimade/server/config.py index b2d6bf270..c2e9021c0 100644 --- a/optimade/server/config.py +++ b/optimade/server/config.py @@ -100,6 +100,7 @@ def _DEFAULTS(field: str) -> Any: res = { "use_real_mongo": False, "mongo_database": "optimade", + "mongo_uri": "localhost:27017", "links_collection": "links", "references_collection": "references", "structures_collection": "structures", @@ -136,6 +137,9 @@ def load_from_ini(self): self.mongo_database = config.get( "BACKEND", "MONGO_DATABASE", fallback=self._DEFAULTS("mongo_database") ) + self.mongo_uri = config.get( + "BACKEND", "MONGO_URI", fallback=self._DEFAULTS("mongo_uri") + ) self.page_limit = config.getint( "SERVER", "PAGE_LIMIT", fallback=self._DEFAULTS("page_limit") @@ -195,6 +199,7 @@ def load_from_json(self): self.mongo_database = config.get( "mongo_database", self._DEFAULTS("mongo_database") ) + self.mongo_uri = config.get("mongo_uri", self._DEFAULTS("mongo_uri")) for endpoint in {"links", "references", "structures"}: setattr( self, From 78c735ca1e2380aa39b31c9b1d99479c30fda851 Mon Sep 17 00:00:00 2001 From: Shyam Dwaraknath Date: Wed, 29 Jan 2020 18:40:34 -0800 Subject: [PATCH 2/4] load new uri in entry_collections --- optimade/server/entry_collections.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/optimade/server/entry_collections.py b/optimade/server/entry_collections.py index e05451555..ab275d4e2 100644 --- a/optimade/server/entry_collections.py +++ b/optimade/server/entry_collections.py @@ -16,10 +16,10 @@ if CONFIG.use_real_mongo: from pymongo import MongoClient + client = MongoClient(CONFIG.mongo_uri) else: from mongomock import MongoClient - -client = MongoClient() + client = MongoClient() class EntryCollection(Collection): # pylint: disable=inherit-non-class From c3c244914677f040e521d689b4b5f18d196c48e8 Mon Sep 17 00:00:00 2001 From: Shyam Dwaraknath Date: Wed, 29 Jan 2020 18:42:52 -0800 Subject: [PATCH 3/4] update config files --- optimade/server/config.ini | 1 + tests/server/config_test.ini | 1 + tests/server/config_test.json | 1 + 3 files changed, 3 insertions(+) diff --git a/optimade/server/config.ini b/optimade/server/config.ini index 3c38f685b..02e2bb3ff 100644 --- a/optimade/server/config.ini +++ b/optimade/server/config.ini @@ -1,6 +1,7 @@ [BACKEND] USE_REAL_MONGO = no MONGO_DATABASE = optimade +MONGO_URI = localhost:27017 LINKS_COLLECTION = links REFERENCES_COLLECTION = references STRUCTURES_COLLECTION = structures diff --git a/tests/server/config_test.ini b/tests/server/config_test.ini index 17ece366d..fc5c660f5 100644 --- a/tests/server/config_test.ini +++ b/tests/server/config_test.ini @@ -1,6 +1,7 @@ [BACKEND] USE_REAL_MONGO = no MONGO_DATABASE = optimade +MONGO_URI = localhost:27017 LINKS_COLLECTION = links REFERENCES_COLLECTION = references STRUCTURES_COLLECTION = structures diff --git a/tests/server/config_test.json b/tests/server/config_test.json index a1ab885c0..f3542e296 100644 --- a/tests/server/config_test.json +++ b/tests/server/config_test.json @@ -1,6 +1,7 @@ { "use_real_mongo": false, "mongo_database": "optimade", + "mongo_uri": "localhost:27017", "links_collection": "links", "references_collection": "references", "structures_collection": "structures", From 74333a29f3a408b3b9a00de344d6b209b8daaedd Mon Sep 17 00:00:00 2001 From: Shyam Dwaraknath Date: Thu, 30 Jan 2020 07:48:43 -0800 Subject: [PATCH 4/4] fix linting errors --- optimade/server/entry_collections.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/optimade/server/entry_collections.py b/optimade/server/entry_collections.py index ab275d4e2..e49367d37 100644 --- a/optimade/server/entry_collections.py +++ b/optimade/server/entry_collections.py @@ -16,9 +16,11 @@ if CONFIG.use_real_mongo: from pymongo import MongoClient + client = MongoClient(CONFIG.mongo_uri) else: from mongomock import MongoClient + client = MongoClient()