Skip to content

Commit

Permalink
Reduce complexity score of map_param function and fix copyright claims
Browse files Browse the repository at this point in the history
  • Loading branch information
pabloge committed Jan 26, 2022
1 parent 890114e commit 4ce0fbc
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 26 deletions.
20 changes: 16 additions & 4 deletions toolium/test/utils/test_dataset_map_param.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
# -*- coding: utf-8 -*-

# Copyright (c) Telefónica Digital.
# QA Team <qacdco@telefonica.com>

"""
Copyright 2022 Telefónica Investigación y Desarrollo, S.A.U.
This file is part of Toolium.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""

import mock
import os
Expand Down
16 changes: 14 additions & 2 deletions toolium/test/utils/test_poeditor.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
# -*- coding: utf-8 -*-
"""
Copyright 2022 Telefónica Investigación y Desarrollo, S.A.U.
This file is part of Toolium.
# Copyright (c) Telefónica Digital.
# QA Team <qacdco@telefonica.com>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""

import mock

Expand Down
65 changes: 47 additions & 18 deletions toolium/utils/dataset.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
"""
Copyright 2021 Telefónica Investigación y Desarrollo, S.A.U.
Copyright 2022 Telefónica Investigación y Desarrollo, S.A.U.
This file is part of Toolium.
Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -322,23 +322,52 @@ def map_one_param(param, context=None):
return param

type, key = _get_mapping_type_and_key(param)
if key:
if type == "CONF" and context and hasattr(context, "project_config"):
return map_json_param(key, context.project_config)
if type == "TOOLIUM" and context:
return map_toolium_param(key, context)
if type == "CONTEXT" and context:
return get_value_from_context(key, context)
if type == "LANG" and context:
return get_message_property(key, context)
if type == "POE" and context:
return get_translation_by_poeditor_reference(key, context)
if type == "ENV":
return os.environ.get(key)
if type == "FILE":
return get_file(key)
if type == "BASE64":
return convert_file_to_base64(key)

mapping_functions = {
"CONF": {
"prerequisites": context and hasattr(context, "project_config"),
"function": map_json_param,
"args": [key, context.project_config if hasattr(context, "project_config") else None]
},
"TOOLIUM": {
"prerequisites": context,
"function": map_toolium_param,
"args": [key, context]
},
"CONTEXT": {
"prerequisites": context,
"function": get_value_from_context,
"args": [key, context]
},
"LANG": {
"prerequisites": context,
"function": get_message_property,
"args": [key, context]
},
"POE": {
"prerequisites": context,
"function": get_translation_by_poeditor_reference,
"args": [key, context]
},
"ENV": {
"prerequisites": True,
"function": os.environ.get,
"args": [key]
},
"FILE": {
"prerequisites": True,
"function": get_file,
"args": [key]
},
"BASE64": {
"prerequisites": True,
"function": convert_file_to_base64,
"args": [key]
}
}

if key and mapping_functions[type]["prerequisites"]:
return mapping_functions[type]["function"](*mapping_functions[type]["args"])
else:
return param

Expand Down
4 changes: 2 additions & 2 deletions toolium/utils/poeditor.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
"""
Copyright 2021 Telefónica Investigación y Desarrollo, S.A.U.
Copyright 2022 Telefónica Investigación y Desarrollo, S.A.U.
This file is part of Toolium.
Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -41,7 +41,7 @@
"poeditor": {
"base_url": "https://api.poeditor.com",
"api_token": "XXXXX",
"project_name": "Aura-Bot",
"project_name": "My-Bot",
"prefixes": [],
"key_field": "reference",
"search_type": "contains",
Expand Down

0 comments on commit 4ce0fbc

Please sign in to comment.