Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CFT-3031, Cft 3031 default header #197

Merged
merged 2 commits into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions python-sync-actions/src/actions/mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ def __init__(self):

def parse_row(self, row: dict[str, Any]):
current_path = []

if isinstance(row, list):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just out of curiosity, how does this even happen?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we encountered this issue in Jira — it is returning tasks in a list of lists

row = row[0]

for name, value in row.items():
self.analyzer.analyze_object(current_path, name, value)

Expand Down
13 changes: 8 additions & 5 deletions python-sync-actions/src/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,10 @@ def search_dict(d):
return results


def _remove_auth_from_dict(dictionary: dict, to_remove: list) -> dict:
def _remove_auth_from_dict(dictionary: dict, to_remove: list, auth_method: str) -> dict:
filtered_dict = {}
for key, value in dictionary.items():
if isinstance(value, dict):
if isinstance(value, dict) and auth_method == 'bearer':
if key != 'Authorization':
filtered_value = _remove_auth_from_dict(value, to_remove)
if filtered_value:
Expand Down Expand Up @@ -189,8 +189,11 @@ def convert_to_v2(configuration: dict) -> list[Configuration]:
default_headers_org = api_json.get('http', {}).get('headers', {})
default_query_parameters_org = api_json.get('http', {}).get('defaultOptions', {}).get('params', {})

default_headers = _remove_auth_from_dict(default_headers_org, _return_ui_params(configuration))
default_query_parameters = _remove_auth_from_dict(default_query_parameters_org, _return_ui_params(configuration))
auth_method = configuration.get('config').get('__AUTH_METHOD')

default_headers = _remove_auth_from_dict(default_headers_org, _return_ui_params(configuration), auth_method)
default_query_parameters = _remove_auth_from_dict(default_query_parameters_org, _return_ui_params(configuration),
auth_method)

pagination = {}
if api_json.get('pagination', {}).get('scrollers'):
Expand Down Expand Up @@ -380,7 +383,7 @@ def convert(cls, config_parameters: dict) -> Authentication | None:
auth_method = config_parameters.get('config', {}).get('__AUTH_METHOD', None)
# or take it form the authentication section
auth_method = auth_method or config_parameters.get('api', {}).get('authentication', {}).get('type')
if not auth_method:
if not auth_method or auth_method == 'custom':
return None

methods = {
Expand Down
57 changes: 57 additions & 0 deletions python-sync-actions/tests/calls/010-default-header/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{
"storage": {},
"parameters": {
"__SELECTED_JOB": "0",

"config": {
"jobs": [
{
"__NAME": "orders",
"endpoint": "010-default-header/orders",
"method": "GET",
"dataType": "",
"dataField": "nested.orders"
}
],
"test": "test-value",
"concat": {
"function": "concat",
"args": [
"hello",
"-world"
]
},
"debug": false,
"outputBucket": "in.c-",
"incrementalOutput": false,
"#BEARER_TOKEN": "token"
},
"api": {
"baseUrl": "http://mock-server:80/",
"http": {
"headers": {
"Authorization": {
"attr": "#BEARER_TOKEN"
}
}
}
},
"http": {
"maxRetries": 10,
"codes": [
500,
502,
503,
504,
408,
420,
429
]
}
},
"action": "test_request",
"image_parameters": {
},
"authorization": {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
GET /010-default-header/orders
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
accept: */*
authorization: Bearer token
82 changes: 82 additions & 0 deletions python-sync-actions/tests/calls/010-default-header/orders.response
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
{
"nested": {
"orders": [
{
"id": 1,
"customer": "John Doe",
"address": "123 Main St",
"items": [
{
"id": 1,
"name": "Widget",
"price": 9.99,
"quantity": 2
},
{
"id": 2,
"name": "Thing",
"price": 5.99,
"quantity": 5
}
]
},
{
"id": 2,
"customer": "Jan Novak",
"address": "123 Main St",
"items": [
{
"id": 1,
"name": "Widget",
"price": 9.99,
"quantity": 2
},
{
"id": 2,
"name": "Thing",
"price": 5.99,
"quantity": 5
}
]
},
{
"id": 3,
"customer": "Jana Novakova",
"address": "123 Main St",
"items": [
{
"id": 1,
"name": "Widget",
"price": 9.99,
"quantity": 2
},
{
"id": 2,
"name": "Thing",
"price": 5.99,
"quantity": 5
}
]
},
{
"id": 4,
"customer": "Bob Smith",
"address": "123 Main St",
"items": [
{
"id": 1,
"name": "Widget",
"price": 9.99,
"quantity": 2
},
{
"id": 2,
"name": "Thing",
"price": 5.99,
"quantity": 5
}
]
}
]
}
}
67 changes: 67 additions & 0 deletions python-sync-actions/tests/test_mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,70 @@ def test_infer_mapping_userdata_child(self):
expected_output = {'id': 'id',
'status': 'status'}
self.assertEqual(output, expected_output)

def test_types(self):
data = [[
{
'id': 'asdf',
'firstWorkingDay': '2024-07-16',
'workingDays': [
{
'day': 'monday'
},
{
'day': 'tuesday'
},
{
'day': 'wednesday'
},
{
'day': 'thursday'
},
{
'day': 'friday'
}
],
'teams': [
{
'name': 'Dream Team',
}
]
},
{
'id': 'asdf2',
'firstWorkingDay': '2024-07-16',
'workingDays': [
{
'day': 'monday'
},
{
'day': 'tuesday'
},
{
'day': 'wednesday'
},
{
'day': 'thursday'
},
{
'day': 'friday'
}
],
'teams': [
{
'name': 'Dream Team',
}
]
}]]

expected = {'firstWorkingDay': 'firstWorkingDay',
'id': 'id',
'teams': {'forceType': True,
'mapping': {'destination': 'teams'},
'type': 'column'},
'workingDays': {'forceType': True,
'mapping': {'destination': 'workingDays'},
'type': 'column'}}
res = infer_mapping(data, max_level_nest_level=1)

self.assertEqual(res, expected)
Loading