Skip to content

Commit

Permalink
move retryWrites processing outside of test
Browse files Browse the repository at this point in the history
  • Loading branch information
Xiangs18 committed May 30, 2024
1 parent 7dd51c0 commit c68cf7e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
2 changes: 1 addition & 1 deletion lib/AbstractHandle/Utils/MongoUtil.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def __init__(self, config):
self.mongo_user = config['mongo-user']
self.mongo_pass = config['mongo-password']
self.mongo_authmechanism = config['mongo-authmechanism']
self.mongo_retrywrites = config['mongo-retrywrites']
self.mongo_retrywrites = config.get('mongo-retrywrites') == "true"

self.handle_collection = self._get_collection(self.mongo_host, self.mongo_port,
self.mongo_database, MONGO_COLLECTION,
Expand Down
15 changes: 7 additions & 8 deletions test/config_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,10 @@ def test_minimal_config(self):
auth-url=https://ci.kbase.us/services/auth\n
shock-url=https://ci.kbase.us/services/shock-api\n
admin-token=998\n
test-token=998\n
test-token=999\n
admin-roles=HANDLE_ADMIN, KBASE_ADMIN\n
namespace=KBH\n
mongo-database=handle_db\n
mongo-retrywrites=false
mongo-database=handle_db
"""
try:
cfg_path = create_temp_file(data_string)
Expand All @@ -49,13 +48,13 @@ def test_minimal_config(self):
deploy_cfg["shock-url"], "https://ci.kbase.us/services/shock-api"
)
self.assertEqual(deploy_cfg["admin-token"], "998")
self.assertEqual(deploy_cfg["test-token"], "998")
self.assertEqual(deploy_cfg["test-token"], "999")
self.assertEqual(deploy_cfg["admin-roles"], "HANDLE_ADMIN, KBASE_ADMIN")
self.assertEqual(deploy_cfg["namespace"], "KBH")
self.assertEqual(deploy_cfg["mongo-database"], "handle_db")
self.assertEqual(deploy_cfg["mongo-user"], "")
self.assertEqual(deploy_cfg["mongo-password"], "")
self.assertEqual(deploy_cfg["mongo-retrywrites"], False)
self.assertEqual(deploy_cfg["mongo-retrywrites"], "")

# remove temp file
os.remove(cfg_path)
Expand All @@ -70,7 +69,7 @@ def test_maximal_config(self):
auth-url=https://ci.kbase.us/services/auth\n
shock-url=https://ci.kbase.us/services/shock-api\n
admin-token=998\n
test-token=998\n
test-token=999\n
admin-roles=HANDLE_ADMIN, KBASE_ADMIN\n
namespace=KBH\n
mongo-database=handle_db\n
Expand Down Expand Up @@ -101,13 +100,13 @@ def test_maximal_config(self):
deploy_cfg["shock-url"], "https://ci.kbase.us/services/shock-api"
)
self.assertEqual(deploy_cfg["admin-token"], "998")
self.assertEqual(deploy_cfg["test-token"], "998")
self.assertEqual(deploy_cfg["test-token"], "999")
self.assertEqual(deploy_cfg["admin-roles"], "HANDLE_ADMIN, KBASE_ADMIN")
self.assertEqual(deploy_cfg["namespace"], "KBH")
self.assertEqual(deploy_cfg["mongo-database"], "handle_db")
self.assertEqual(deploy_cfg["mongo-user"], "mongouser")
self.assertEqual(deploy_cfg["mongo-password"], "mongopassword")
self.assertEqual(deploy_cfg["mongo-retrywrites"], True)
self.assertEqual(deploy_cfg["mongo-retrywrites"], "true")

# remove temp file
os.remove(cfg_path)
4 changes: 2 additions & 2 deletions test/mongo_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def get_config() -> Tuple[MongoConfigTuple, dict[str, str]]:
db_name = _get_value(section, TEST_DATABASE_NAME, config_path, True)
mongo_user = _get_value(section, TEST_DATABASE_USER, config_path, False)
mongo_pwd = _get_value(section, TEST_DATABASE_PWD, config_path, False)
mongo_retrywrites = _get_value(section, TEST_MONGO_RETRYWRITES, config_path, True)
mongo_retrywrites = _get_value(section, TEST_MONGO_RETRYWRITES, config_path, False)

mongo_config = MongoConfigTuple(
Path(mongo_exe_path),
Expand All @@ -84,7 +84,7 @@ def get_config() -> Tuple[MongoConfigTuple, dict[str, str]]:
TEST_DATABASE_NAME: db_name,
TEST_DATABASE_USER: mongo_user,
TEST_DATABASE_PWD: mongo_pwd,
TEST_MONGO_RETRYWRITES: mongo_retrywrites == "true",
TEST_MONGO_RETRYWRITES: mongo_retrywrites,
}

return mongo_config, deploy_config
Expand Down

0 comments on commit c68cf7e

Please sign in to comment.