test enhancements

dev
Kyle Prestel 2021-07-31 14:23:55 -04:00
rodzic a90c18bfa6
commit ef055a2fc0
6 zmienionych plików z 55 dodań i 32 usunięć

Wyświetl plik

@ -46,3 +46,6 @@ publish: deploy
start-nextcloud-test-instance: start-nextcloud-test-instance:
./bin/start-nextcloud.sh ./bin/start-nextcloud.sh
install-deck:
docker exec --user www-data nextcloud php occ app:install deck

Wyświetl plik

@ -1,3 +1,5 @@
# Python Nextcloud Deck API # Python Nextcloud Deck API
Simple python based wrapper around the Nextcloud deck API Simple python based wrapper around the Nextcloud deck API
Before using this library you should get familiar with the [Offical REST API](https://deck.readthedocs.io/en/latest/API/)

Wyświetl plik

@ -4,6 +4,9 @@ docker run -d \
-e PUID=1000 \ -e PUID=1000 \
-e PGID=1001 \ -e PGID=1001 \
-e TZ=Europe/London \ -e TZ=Europe/London \
-e NEXTCLOUD_ADMIN_USER=Admin \
-e NEXTCLOUD_ADMIN_PASSWORD=admin \
-e SQLITE_DATABASE=nextcloud-deck-test \
-p 443:443 \ -p 443:443 \
-v nextcloud-config:/config \ -v nextcloud-config:/config \
-v nextcloud-data:/data \ -v nextcloud-data:/data \

Wyświetl plik

@ -12,7 +12,7 @@ IdType = typing.Union[int, str]
class NextCloudDeckAPI: class NextCloudDeckAPI:
"""docstring for NextCloudDeck.""" """Wrapper around the NextCloud Deck API"""
def __init__( def __init__(
self, self,
@ -57,11 +57,11 @@ class NextCloudDeckAPI:
return response.json() return response.json()
def update_board( def update_board(
self, board_id: IdType, title: str, color: str, archived: bool self, board_id: IdType, title: str, color: str, archived: bool
) -> typing.Dict[str, typing.Any]: ) -> typing.Dict[str, typing.Any]:
response = self.session.put( response = self.session.put(
f"{self.url}/boards/{board_id}", f"{self.url}/boards/{board_id}",
json={"title": title, "color": color, "archived": archived} json={"title": title, "color": color, "archived": archived},
) )
return response.json() return response.json()
@ -75,7 +75,15 @@ class NextCloudDeckAPI:
response = self.session.post(f"{self.url}/boards/{board_id}/undo_delete") response = self.session.post(f"{self.url}/boards/{board_id}/undo_delete")
return response.json() return response.json()
def add_board_acl_rule(self, board_id: IdType, type: int, participant: str, perm_edit: bool, perm_share: bool, perm_manage: bool): def add_board_acl_rule(
self,
board_id: IdType,
type: int,
participant: str,
perm_edit: bool,
perm_share: bool,
perm_manage: bool,
):
response = self.session.post( response = self.session.post(
f"{self.url}/boards/{board_id}/acl", f"{self.url}/boards/{board_id}/acl",
json={ json={
@ -83,26 +91,33 @@ class NextCloudDeckAPI:
"participant": participant, "participant": participant,
"permissionEdit": perm_edit, "permissionEdit": perm_edit,
"permissionShare": perm_share, "permissionShare": perm_share,
"permissionManage": perm_manage "permissionManage": perm_manage,
} },
) )
return response.json() # TODO: Deserialization to model for ACL rule return response.json() # TODO: Deserialization to model for ACL rule
def update_board_acl_rule(self, board_id: IdType, acl_id: IdType, perm_edit: bool, perm_share: bool, perm_manage: bool) -> typing.Dict[str, typing.Any]: def update_board_acl_rule(
self,
board_id: IdType,
acl_id: IdType,
perm_edit: bool,
perm_share: bool,
perm_manage: bool,
) -> typing.Dict[str, typing.Any]:
response = self.session.put( response = self.session.put(
f"{self.url}/boards/{board_id}/acl/{acl_id}", f"{self.url}/boards/{board_id}/acl/{acl_id}",
json={ json={
"permissionEdit": perm_edit, "permissionEdit": perm_edit,
"permissionShare": perm_share, "permissionShare": perm_share,
"permissionManage": perm_manage "permissionManage": perm_manage,
} },
) )
return response.json() return response.json()
def delete_board_acl_rule(self, board_id: IdType, acl_id: IdType) -> typing.Dict[str, typing.Any]: def delete_board_acl_rule(
response = self.session.delete( self, board_id: IdType, acl_id: IdType
f"{self.url}/boards/{board_id}/acl/{acl_id}" ) -> typing.Dict[str, typing.Any]:
) response = self.session.delete(f"{self.url}/boards/{board_id}/acl/{acl_id}")
return response.json() return response.json()
# Stacks # Stacks
@ -116,16 +131,12 @@ class NextCloudDeckAPI:
@deserialize(typing.List[Stack]) @deserialize(typing.List[Stack])
def get_archived_stacks(self, board_id: IdType) -> typing.Dict[str, typing.Any]: def get_archived_stacks(self, board_id: IdType) -> typing.Dict[str, typing.Any]:
response = self.session.get( response = self.session.get(f"{self.url}/{board_id}/stacks/archived")
f"{self.url}/{board_id}/stacks/archived"
)
return response.json() return response.json()
@deserialize(Stack) @deserialize(Stack)
def get_stack(self, board_id: IdType, stack_id: IdType): def get_stack(self, board_id: IdType, stack_id: IdType):
response = self.session.get( response = self.session.get(f"{self.url}/{board_id}/stacks/{stack_id}")
f"{self.url}/{board_id}/stacks/{stack_id}"
)
return response.json() return response.json()
@deserialize(Stack) @deserialize(Stack)
@ -240,36 +251,38 @@ class NextCloudDeckAPI:
return response.json() return response.json()
def assign_user_to_card( def assign_user_to_card(
self, board_id, stack_id, card_id, user_id self, board_id, stack_id, card_id, user_id
) -> typing.Dict[str, typing.Any]: ) -> typing.Dict[str, typing.Any]:
response = self.session.put( response = self.session.put(
f"{self.url}/{board_id}/stacks/{stack_id}/cards/{card_id}/assignUser", f"{self.url}/{board_id}/stacks/{stack_id}/cards/{card_id}/assignUser",
json={"userId": user_id} json={"userId": user_id},
) )
return response.json() return response.json()
def unassign_user_from_card( def unassign_user_from_card(
self, board_id, stack_id, card_id, user_id self, board_id, stack_id, card_id, user_id
) -> typing.Dict[str, typing.Any]: ) -> typing.Dict[str, typing.Any]:
response = self.session.put( response = self.session.put(
f"{self.url}/{board_id}/stacks/{stack_id}/cards/{card_id}/unassignUser", f"{self.url}/{board_id}/stacks/{stack_id}/cards/{card_id}/unassignUser",
json={"userId": user_id} json={"userId": user_id},
) )
return response.json() return response.json()
def reorder_card( def reorder_card(
self, board_id, stack_id, card_id, order, stack_target self, board_id, stack_id, card_id, order, stack_target
) -> typing.Dict[str, typing.Any]: ) -> typing.Dict[str, typing.Any]:
response = self.session.put( response = self.session.put(
f"{self.url}/{board_id}/stacks/{stack_id}/cards/{card_id}/reorder", f"{self.url}/{board_id}/stacks/{stack_id}/cards/{card_id}/reorder",
json={"order": order, "stackId": stack_target} json={"order": order, "stackId": stack_target},
) )
return response.json() return response.json()
# Labels # Labels
@deserialize(Label) @deserialize(Label)
def get_label(self, board_id: IdType, label_id: IdType) -> typing.Dict[str, typing.Any]: def get_label(
self, board_id: IdType, label_id: IdType
) -> typing.Dict[str, typing.Any]:
response = self.session.get(f"{self.url}/{board_id}/labels/{label_id}") response = self.session.get(f"{self.url}/{board_id}/labels/{label_id}")
return response.json() return response.json()
@ -282,15 +295,17 @@ class NextCloudDeckAPI:
return response.json() return response.json()
def update_label( def update_label(
self, board_id: IdType, label_id: IdType, title: str, color: str self, board_id: IdType, label_id: IdType, title: str, color: str
) -> typing.Dict[str, typing.Any]: ) -> typing.Dict[str, typing.Any]:
response = self.session.put( response = self.session.put(
f"{self.url}/{board_id}/labels/{label_id}", f"{self.url}/{board_id}/labels/{label_id}",
json={"title": title, "color": color} json={"title": title, "color": color},
) )
return response.json() return response.json()
def delete_label(self, board_id: IdType, label_id: IdType) -> typing.Dict[str, typing.Any]: def delete_label(
self, board_id: IdType, label_id: IdType
) -> typing.Dict[str, typing.Any]:
response = self.session.delete(f"{self.url}/{board_id}/labels/{label_id}") response = self.session.delete(f"{self.url}/{board_id}/labels/{label_id}")
return response.json() return response.json()

Wyświetl plik

@ -16,7 +16,7 @@ T = typing.TypeVar("T")
def to_snake(s): def to_snake(s):
return re.sub("([A-Z]\w+$)", "_\\1", s).lower() return re.sub(r"([A-Z]\w+$)", "_\\1", s).lower()
def json_to_snake(d): def json_to_snake(d):

Wyświetl plik

@ -125,7 +125,7 @@ def test_get_cards_from_stack(board, stack, card, nc: NextCloudDeckAPI):
def test_reorder_card(board, stack, stack2, card, nc: NextCloudDeckAPI): def test_reorder_card(board, stack, stack2, card, nc: NextCloudDeckAPI):
assert card.stack_id == stack.id assert card.stack_id == stack.id
nc.reorder_card(board.id, stack.id, card.id, card.order-1, stack2.id) nc.reorder_card(board.id, stack.id, card.id, card.order - 1, stack2.id)
cards1 = nc.get_cards_from_stack(board.id, stack.id) cards1 = nc.get_cards_from_stack(board.id, stack.id)
cards2 = nc.get_cards_from_stack(board.id, stack2.id) cards2 = nc.get_cards_from_stack(board.id, stack2.id)
assert len(cards1) == 0 assert len(cards1) == 0