Skip to content

Commit

Permalink
Merge pull request #70 from cloudblue/lite-26872_add_manual_transform…
Browse files Browse the repository at this point in the history
…ations

LITE-26872 Add manual transformation decorator
  • Loading branch information
ffaraone authored Mar 20, 2023
2 parents 35d6d9b + c9762b6 commit 1923e09
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 8 deletions.
43 changes: 43 additions & 0 deletions connect/eaas/core/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,10 @@ def split_by_delimiter(self, row):
this transformation.
"""
def wrapper(func):
manual = False
if hasattr(func, TRANSFORMATION_ATTR_NAME):
manual = getattr(func, TRANSFORMATION_ATTR_NAME)['manual']

setattr(
func,
TRANSFORMATION_ATTR_NAME,
Expand All @@ -433,12 +437,51 @@ def wrapper(func):
'name': name,
'description': description,
'edit_dialog_ui': edit_dialog_ui,
'manual': manual,
},
)
return func
return wrapper


def manual_transformation():
"""
Mark a method of an Transformations Application as a manual tranformation.
Usage:
``` py3
from connect.eaas.core.decorators import manual_transformation, transformation
from connect.eaas.core.extension import EventsApplicationBase
class MyTransformationsApplication(TransformationsApplicationBase):
@manual_transformation()
@transformation(
'Split column by delimiter',
'Split a column into multiple columns based on a delimiter',
'/static/configure_split_by_delimiter.html',
)
def manual(self, row):
pass
```
"""
def wrapper(func):
if hasattr(func, TRANSFORMATION_ATTR_NAME):
data = getattr(func, TRANSFORMATION_ATTR_NAME)
data['manual'] = True
else:
data = {'manual': True}

setattr(
func,
TRANSFORMATION_ATTR_NAME,
data,
)
return func
return wrapper


def devops_pages(pages: List[Dict]):
"""
Class decorator for Web Application that declare a list of
Expand Down
1 change: 1 addition & 0 deletions connect/eaas/core/proto.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ class Transformation(BaseModel):
name: str
description: str
edit_dialog_ui: str
manual: bool = False


class Repository(BaseModel):
Expand Down
49 changes: 41 additions & 8 deletions tests/connect/eaas/core/test_extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
devops_pages,
event,
guest,
manual_transformation,
module_pages,
schedulable,
transformation,
Expand Down Expand Up @@ -497,15 +498,47 @@ class MyExtension(TransformationsApplicationBase):
def transform_row(self, row):
pass

@manual_transformation()
@transformation(
name='my manual transformation',
description='The transformation',
edit_dialog_ui='/static/settings.html',
)
def dummy(self, row):
pass

@transformation(
name='another manual transformation',
description='The transformation',
edit_dialog_ui='/static/settings.html',
)
@manual_transformation()
def dummy2(self, row):
pass

transformations = MyExtension.get_transformations()
assert transformations == [
{
'method': 'transform_row',
'name': 'my transformation',
'description': 'The my transformation',
'edit_dialog_ui': '/static/my_settings.html',
},
]
assert len(transformations) == 3
assert {
'method': 'transform_row',
'name': 'my transformation',
'description': 'The my transformation',
'edit_dialog_ui': '/static/my_settings.html',
'manual': False,
} in transformations
assert {
'method': 'dummy',
'name': 'my manual transformation',
'description': 'The transformation',
'edit_dialog_ui': '/static/settings.html',
'manual': True,
} in transformations
assert {
'method': 'dummy2',
'name': 'another manual transformation',
'description': 'The transformation',
'edit_dialog_ui': '/static/settings.html',
'manual': True,
} in transformations


def test_get_installation_admin_client(mocker, client_mocker_factory):
Expand Down
1 change: 1 addition & 0 deletions tests/connect/eaas/core/test_proto.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@
'description': 'Description',
'edit_dialog_ui': '/static/edit.html',
'method': 'my_method',
'manual': False,
}],
'repository': {
'readme_url': 'https://read.me',
Expand Down

0 comments on commit 1923e09

Please sign in to comment.