Skip to content

Commit

Permalink
Edinting the default documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
darcivieira committed Nov 6, 2023
1 parent ae69a21 commit 0fc721b
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 4 deletions.
3 changes: 3 additions & 0 deletions kanbanize_sdk/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,7 @@
BoardsListParams,
BoardSettingsUpdateBody,
BoardHistoryListParams,
WorkflowsUpdateBody,
WorkflowsInsetBody,
WorkflowsCopyBody,
)
17 changes: 17 additions & 0 deletions kanbanize_sdk/dataclasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,23 @@ def to_dict(self):
}


@dataclass
class WorkflowsCopyBody:
"""
Set here a documentation
"""
name: str
to_board_id: int
copy_service_level_expectations: int
copy_column_checklist_items: int

def to_dict(self):
return {
key.strip('_'): list(map(str, value)) if isinstance(value, list) else value
for key, value in self.__dict__.items() if value is not None
}


@dataclass
class WorkflowsUpdateBody:
"""
Expand Down
7 changes: 4 additions & 3 deletions kanbanize_sdk/workflows.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from .generics import GenericRequestMethod
from .dataclasses import WorkflowsInsetBody, WorkflowsUpdateBody
from .dataclasses import WorkflowsInsetBody, WorkflowsUpdateBody, WorkflowsCopyBody


class Workflows(GenericRequestMethod):
Expand Down Expand Up @@ -71,15 +71,16 @@ def delete(self, board_id: int, workflow_id: int) -> None:
"""
return self.service.delete(self.endpoint + f'/{board_id}/workflows/{workflow_id}')

def copy(self, board_id: int, workflow_id: int) -> dict:
def copy(self, board_id: int, workflow_id: int, body: WorkflowsCopyBody) -> dict:
"""
This method is responsible to make a copy of one workflow from the board into the platform.
Parameters:
board_id: An integer parameter that represents the board identification.
workflow_id: An integer parameter that represents the workflow identification.
body: It's a dataclass object that represent the body option to be coped.
Returns:
A workflow object with the basic information data
"""
return self.service.post(self.endpoint + f'/{board_id}/workflows/{workflow_id}/copy')
return self.service.post(self.endpoint + f'/{board_id}/workflows/{workflow_id}/copy', data=body.to_dict())
88 changes: 87 additions & 1 deletion tests/test_workflows.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from pytest import mark
from kanbanize_sdk import Kanbanize
from kanbanize_sdk import Kanbanize, WorkflowsInsetBody, WorkflowsUpdateBody, WorkflowsCopyBody


@mark.workflows
Expand All @@ -17,3 +17,89 @@ def test_list_workflows(requests_mock):
requests_mock.get('https://teste.kanbanize.com/api/v2/boards/1/workflows', json=test_json)
service = Kanbanize({'subdomain': 'teste', 'api_key': 'teste_key'})
assert service.workflows().list(board_id=1) == test_json.get('data')


@mark.workflows
def test_insert_workflow(requests_mock):
test_json = {
'data': {
'workflow_id': 0,
'type': 0,
'position': 0,
'is_enabled': 0,
'is_collapsible': 0,
'name': 'Test',
}
}
requests_mock.post('https://teste.kanbanize.com/api/v2/boards/1/workflows', json=test_json)
body = WorkflowsInsetBody(position=0, is_enabled=0, is_collapsible=0, name='Teste', _type=0)
service = Kanbanize({'subdomain': 'teste', 'api_key': 'teste_key'})
assert service.workflows().insert(board_id=1, body=body) == test_json.get('data')


@mark.workflows
def test_get_workflow(requests_mock):
test_json = {
'data': {
'type': 0,
'position': 0,
'is_enabled': 0,
'is_collapsible': 0,
'name': 'Test',
}
}
requests_mock.get('https://teste.kanbanize.com/api/v2/boards/1/workflows/1', json=test_json)
service = Kanbanize({'subdomain': 'teste', 'api_key': 'teste_key'})
assert service.workflows().get(board_id=1, workflow_id=1) == test_json.get('data')


@mark.workflows
def test_update_workflow(requests_mock):
test_json = {
'data': {
'type': 0,
'position': 0,
'is_enabled': 0,
'is_collapsible': 0,
'name': 'Test',
}
}
requests_mock.patch('https://teste.kanbanize.com/api/v2/boards/1/workflows/1', json=test_json)
body = WorkflowsUpdateBody(position=1)
service = Kanbanize({'subdomain': 'teste', 'api_key': 'teste_key'})
assert service.workflows().update(board_id=1, workflow_id=1, body=body) == test_json.get('data')


@mark.workflows
def test_delete_workflow(requests_mock):
requests_mock.delete('https://teste.kanbanize.com/api/v2/boards/1/workflows/1', status_code=204)
service = Kanbanize({'subdomain': 'teste', 'api_key': 'teste_key'})
assert service.workflows().delete(board_id=1, workflow_id=1) is None


@mark.workflows
def test_copy_workflow(requests_mock):
test_json = {
'data': {
'board_structure': {},
'cycle_time_column_ids': [
0
],
'initiative_workflow_settings': [
{
"workflow_id": 1,
"built_in_rules_can_start_initiatives": 0,
"built_in_rules_can_finish_initiatives": 0,
"built_in_rules_can_move_to_requested": 0,
"built_in_rules_can_move_back_from_done": 0,
"built_in_rules_can_move_from_backlog_to_requested": 0,
}
]
}
}
requests_mock.post('https://teste.kanbanize.com/api/v2/boards/1/workflows/1/copy', json=test_json)
body = WorkflowsCopyBody(
name="Test", to_board_id=0, copy_service_level_expectations=1, copy_column_checklist_items=1
)
service = Kanbanize({'subdomain': 'teste', 'api_key': 'teste_key'})
assert service.workflows().copy(board_id=1, workflow_id=1, body=body) == test_json.get('data')

0 comments on commit 0fc721b

Please sign in to comment.