Skip to content

Commit

Permalink
Board card types
Browse files Browse the repository at this point in the history
  • Loading branch information
darcivieira committed Nov 13, 2023
1 parent 80e0e53 commit e33d644
Show file tree
Hide file tree
Showing 6 changed files with 194 additions and 3 deletions.
1 change: 1 addition & 0 deletions docs/api/board_card_types.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
::: endpoints.board_card_types
2 changes: 2 additions & 0 deletions kanbanize_sdk/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,6 @@
BoardStickersUpdateBody,
LaneSectionLimitsUpdateBody,
BoardStickersInsertBody,
BoardCardTypesInsertBody,
BoardCardTypesUpdateBody,
)
16 changes: 16 additions & 0 deletions kanbanize_sdk/dataclasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,3 +384,19 @@ class BoardStickersInsertBody(BaseDataClasse):
class BoardStickersUpdateBody(BaseDataClasse):
limit_per_board: Optional[int] = None
limit_per_card: Optional[int] = None


@dataclass
class BoardCardTypesInsertBody(BaseDataClasse):
icon_type: int
icon_id: int
color: str
card_color_sync: int


@dataclass
class BoardCardTypesUpdateBody(BaseDataClasse):
icon_type: Optional[int] = None
icon_id: Optional[int] = None
color: Optional[str] = None
card_color_sync: Optional[int] = None
92 changes: 89 additions & 3 deletions kanbanize_sdk/endpoints/board_card_types.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,91 @@
from .boards import Boards
from .generics import GenericRequestMethod
from kanbanize_sdk.dataclasses import BoardCardTypesInsertBody, BoardCardTypesUpdateBody


class BoardCardTypes(Boards):
...
class BoardCardTypes(GenericRequestMethod):
"""
Class responsible to make calls to Kanbanize board card types endpoints
"""

endpoint = '/boards'

def list(self, board_id: int, *args, **kwargs) -> list:
"""
This method is responsible to list all board card types from the board into the platform.
Parameters:
board_id: An integer parameter that represents the board assignee
Returns:
An array of objects that represents the board card types
"""
return self.service.get(self.endpoint + f'/{board_id}/cardTypes')

def get(self, board_id: int, type_id: int, *args, **kwargs) -> dict:
"""
This method is responsible to get a board card types from the board into the platform.
Parameters:
board_id: An integer parameter that represents the board identification.
type_id: An integer parameter that represents the user identification.
Returns:
A board card type object with the basic information data.
"""
return self.service.get(self.endpoint + f'/{board_id}/cardTypes/{type_id}')

def get_effective_settings(self, board_id: int, type_id: int, *args, **kwargs) -> dict:
"""
This method is responsible to get a board card type settings from the board into the platform.
Parameters:
board_id: An integer parameter that represents the board identification.
type_id: An integer parameter that represents the user identification.
Returns:
A board card type settings object with the basic information data.
"""
return self.service.get(self.endpoint + f'/{board_id}/cardTypes/{type_id}/effectiveSettings')

def insert(self, board_id: int, type_id: int, body: BoardCardTypesInsertBody, *args, **kwargs) -> dict:

"""
This method is responsible to get a board card types from the board into the platform.
Parameters:
board_id: An integer parameter that represents the board identification.
type_id: An integer parameter that represents the user identification.
body: It's a dataclass object that provide the essential request body needed to update a board card types to the
board into the platform.
Returns:
An object that represents the board card type.
"""
return self.service.put(self.endpoint + f'/{board_id}/cardTypes/{type_id}', data=body.to_dict())

def update(self, board_id: int, type_id: int, body: BoardCardTypesUpdateBody, *args, **kwargs) -> dict:

"""
This method is responsible to get a board card types from the board into the platform.
Parameters:
board_id: An integer parameter that represents the board identification.
type_id: An integer parameter that represents the user identification.
body: It's a dataclass object that provide the essential request body needed to update a board card types to the
board into the platform.
"""
return self.service.patch(self.endpoint + f'/{board_id}/cardTypes/{type_id}', data=body.to_dict())

def delete(self, board_id: int, type_id: int, *args, **kwargs) -> None:

"""
This method is responsible to get a board card types from the board into the platform.
Parameters:
board_id: An integer parameter that represents the board identification.
type_id: An integer parameter that represents the user identification.
"""
return self.service.delete(self.endpoint + f'/{board_id}/cardTypes/{type_id}')

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ markers = [
"board_stickers",
"board_tags",
"board_card_templates",
"board_card_types",
]

[build-system]
Expand Down
85 changes: 85 additions & 0 deletions tests/test_board_card_types.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
from pytest import mark
from kanbanize_sdk import Kanbanize, BoardCardTypesInsertBody, BoardCardTypesUpdateBody


@mark.board_card_types
def test_list_board_card_types(requests_mock):
test_json = {
'data': [
{
"type_id": 0,
"icon_type": 0,
"icon_id": 0,
"color": 'text',
"card_color_sync": 0,
}
]
}
requests_mock.get('https://teste.kanbanize.com/api/v2/boards/1/cardTypes', json=test_json)
service = Kanbanize({'subdomain': 'teste', 'api_key': 'teste_key'})
assert service.board_card_types().list(board_id=1) == test_json.get('data')


@mark.board_card_types
def test_get_board_card_types(requests_mock):
test_json = {
'data': {
"icon_type": 0,
"icon_id": 0,
"color": 'text',
"card_color_sync": 0,
}
}
requests_mock.get('https://teste.kanbanize.com/api/v2/boards/1/cardTypes/1', json=test_json)
service = Kanbanize({'subdomain': 'teste', 'api_key': 'teste_key'})
assert service.board_card_types().get(board_id=1, type_id=1) == test_json.get('data')


@mark.board_card_types
def test_get_board_card_types_settings(requests_mock):
test_json = {
'data': {
"icon_type": 0,
"icon_id": 0,
"color": 'text',
"card_color_sync": 0,
}
}
requests_mock.get('https://teste.kanbanize.com/api/v2/boards/1/cardTypes/1/effectiveSettings', json=test_json)
service = Kanbanize({'subdomain': 'teste', 'api_key': 'teste_key'})
assert service.board_card_types().get_effective_settings(board_id=1, type_id=1) == test_json.get('data')


@mark.board_card_types
def test_insert_board_card_types(requests_mock):
test_json = {
'data': {
"limit_per_board": 0,
"limit_per_card": 0,
}
}
requests_mock.put('https://teste.kanbanize.com/api/v2/boards/1/cardTypes/1', json=test_json)
service = Kanbanize({'subdomain': 'teste', 'api_key': 'teste_key'})
body = BoardCardTypesInsertBody(icon_type=0, icon_id=0, color='ffffff', card_color_sync=0)
assert service.board_card_types().insert(board_id=1, type_id=1, body=body) == test_json.get('data')


@mark.board_card_types
def test_update_board_card_types(requests_mock):
test_json = {
'data': {
"limit_per_board": 0,
"limit_per_card": 0,
}
}
requests_mock.patch('https://teste.kanbanize.com/api/v2/boards/1/cardTypes/1', json=test_json)
service = Kanbanize({'subdomain': 'teste', 'api_key': 'teste_key'})
body = BoardCardTypesUpdateBody(card_color_sync=0)
assert service.board_card_types().update(1, 1, body) == test_json.get('data')


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

0 comments on commit e33d644

Please sign in to comment.