From ef055a2fc0c66aa3d520d828f8df6265c69f338b Mon Sep 17 00:00:00 2001 From: Kyle Prestel Date: Sat, 31 Jul 2021 14:23:55 -0400 Subject: [PATCH] test enhancements --- Makefile | 3 ++ README.md | 4 ++- bin/start-nextcloud.sh | 3 ++ deck/api.py | 73 +++++++++++++++++++++++++----------------- deck/models.py | 2 +- tests/test_api.py | 2 +- 6 files changed, 55 insertions(+), 32 deletions(-) diff --git a/Makefile b/Makefile index 1e6326a..dc00661 100644 --- a/Makefile +++ b/Makefile @@ -46,3 +46,6 @@ publish: deploy start-nextcloud-test-instance: ./bin/start-nextcloud.sh + +install-deck: + docker exec --user www-data nextcloud php occ app:install deck diff --git a/README.md b/README.md index d3ba7c1..9e39be7 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ # Python Nextcloud Deck API -Simple python based wrapper around the Nextcloud deck API \ No newline at end of file +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/) \ No newline at end of file diff --git a/bin/start-nextcloud.sh b/bin/start-nextcloud.sh index 0456ffb..11a70a5 100755 --- a/bin/start-nextcloud.sh +++ b/bin/start-nextcloud.sh @@ -4,6 +4,9 @@ docker run -d \ -e PUID=1000 \ -e PGID=1001 \ -e TZ=Europe/London \ + -e NEXTCLOUD_ADMIN_USER=Admin \ + -e NEXTCLOUD_ADMIN_PASSWORD=admin \ + -e SQLITE_DATABASE=nextcloud-deck-test \ -p 443:443 \ -v nextcloud-config:/config \ -v nextcloud-data:/data \ diff --git a/deck/api.py b/deck/api.py index 88fde6b..73ac044 100644 --- a/deck/api.py +++ b/deck/api.py @@ -12,7 +12,7 @@ IdType = typing.Union[int, str] class NextCloudDeckAPI: - """docstring for NextCloudDeck.""" + """Wrapper around the NextCloud Deck API""" def __init__( self, @@ -57,11 +57,11 @@ class NextCloudDeckAPI: return response.json() 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]: response = self.session.put( f"{self.url}/boards/{board_id}", - json={"title": title, "color": color, "archived": archived} + json={"title": title, "color": color, "archived": archived}, ) return response.json() @@ -75,7 +75,15 @@ class NextCloudDeckAPI: response = self.session.post(f"{self.url}/boards/{board_id}/undo_delete") 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( f"{self.url}/boards/{board_id}/acl", json={ @@ -83,26 +91,33 @@ class NextCloudDeckAPI: "participant": participant, "permissionEdit": perm_edit, "permissionShare": perm_share, - "permissionManage": perm_manage - } + "permissionManage": perm_manage, + }, ) 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( f"{self.url}/boards/{board_id}/acl/{acl_id}", json={ "permissionEdit": perm_edit, "permissionShare": perm_share, - "permissionManage": perm_manage - } + "permissionManage": perm_manage, + }, ) return response.json() - def delete_board_acl_rule(self, board_id: IdType, acl_id: IdType) -> typing.Dict[str, typing.Any]: - response = self.session.delete( - f"{self.url}/boards/{board_id}/acl/{acl_id}" - ) + def delete_board_acl_rule( + self, board_id: IdType, acl_id: IdType + ) -> typing.Dict[str, typing.Any]: + response = self.session.delete(f"{self.url}/boards/{board_id}/acl/{acl_id}") return response.json() # Stacks @@ -116,16 +131,12 @@ class NextCloudDeckAPI: @deserialize(typing.List[Stack]) def get_archived_stacks(self, board_id: IdType) -> typing.Dict[str, typing.Any]: - response = self.session.get( - f"{self.url}/{board_id}/stacks/archived" - ) + response = self.session.get(f"{self.url}/{board_id}/stacks/archived") return response.json() @deserialize(Stack) def get_stack(self, board_id: IdType, stack_id: IdType): - response = self.session.get( - f"{self.url}/{board_id}/stacks/{stack_id}" - ) + response = self.session.get(f"{self.url}/{board_id}/stacks/{stack_id}") return response.json() @deserialize(Stack) @@ -240,36 +251,38 @@ class NextCloudDeckAPI: return response.json() 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]: response = self.session.put( f"{self.url}/{board_id}/stacks/{stack_id}/cards/{card_id}/assignUser", - json={"userId": user_id} + json={"userId": user_id}, ) return response.json() 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]: response = self.session.put( f"{self.url}/{board_id}/stacks/{stack_id}/cards/{card_id}/unassignUser", - json={"userId": user_id} + json={"userId": user_id}, ) return response.json() 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]: response = self.session.put( 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() # Labels @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}") return response.json() @@ -282,15 +295,17 @@ class NextCloudDeckAPI: return response.json() 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]: response = self.session.put( f"{self.url}/{board_id}/labels/{label_id}", - json={"title": title, "color": color} + json={"title": title, "color": color}, ) 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}") return response.json() diff --git a/deck/models.py b/deck/models.py index 8f7a1d6..a568828 100644 --- a/deck/models.py +++ b/deck/models.py @@ -16,7 +16,7 @@ T = typing.TypeVar("T") 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): diff --git a/tests/test_api.py b/tests/test_api.py index 81ddbfb..a6c2dca 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -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): 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) cards2 = nc.get_cards_from_stack(board.id, stack2.id) assert len(cards1) == 0