Skip to content
Snippets Groups Projects
Verified Commit bf56045f authored by Yoann Schneider's avatar Yoann Schneider :tennis:
Browse files

fix and add tests

parent eefc89f8
No related branches found
No related tags found
1 merge request!196Avoid attribute error on user_config
Pipeline #79430 passed
This commit is part of merge request !196. Comments created here will be created in the context of that merge request.
......@@ -196,7 +196,7 @@ class BaseWorker(object):
)
# Retrieve initial configuration from API
self.config = worker_version["configuration"]["configuration"]
self.config = worker_version["configuration"].get("configuration")
if "user_configuration" in worker_version["configuration"]:
# Add default values (if set) to user_configuration
for key, value in worker_version["configuration"][
......@@ -210,8 +210,10 @@ class BaseWorker(object):
self.secrets = {name: self.load_secret(name) for name in required_secrets}
# Load worker run configuration when available
worker_configuration = worker_run.get("configuration", {})
self.user_configuration = worker_configuration.get("configuration")
worker_configuration = worker_run.get("configuration")
self.user_configuration = (
worker_configuration.get("configuration") if worker_configuration else None
)
if self.user_configuration:
logger.info("Loaded user configuration from WorkerRun")
# if debug mode is set to true activate debug mode in logger
......
......@@ -372,6 +372,53 @@ def test_configure_worker_run_missing_conf(mocker, monkeypatch, responses):
assert worker.user_configuration is None
def test_configure_worker_run_no_worker_run_conf(mocker, monkeypatch, responses):
"""
No configuration is provided but should not crash
"""
worker = BaseWorker()
mocker.patch.object(sys, "argv", ["worker"])
payload = {
"id": "56785678-5678-5678-5678-567856785678",
"parents": [],
"worker_version_id": "12341234-1234-1234-1234-123412341234",
"model_version_id": None,
"dataimport_id": "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeffff",
"worker": {
"id": "deadbeef-1234-5678-1234-worker",
"name": "Fake worker",
"slug": "fake_worker",
"type": "classifier",
},
"configuration_id": None,
"worker_version": {
"id": "12341234-1234-1234-1234-123412341234",
"worker": {
"id": "deadbeef-1234-5678-1234-worker",
"name": "Fake worker",
"slug": "fake_worker",
"type": "classifier",
},
"revision": {"hash": "deadbeef1234"},
"configuration": {},
},
"configuration": None,
"process": {"id": "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeffff"},
}
responses.add(
responses.GET,
"http://testserver/api/v1/imports/workers/56785678-5678-5678-5678-567856785678/",
status=200,
body=json.dumps(payload),
content_type="application/json",
)
worker.args = worker.parser.parse_args()
worker.configure()
assert worker.user_configuration is None
def test_load_missing_secret():
worker = BaseWorker()
worker.api_client = MockApiClient()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment