import pytest import requests_mock from server import PlankaClient @pytest.fixture def planka_client(): return PlankaClient("https://planka.example.com", "test_token") def test_get_projects(planka_client): with requests_mock.Mocker() as m: m.get("https://planka.example.com/api/projects", json=[ {"id": "1", "name": "Project 1"}, {"id": "2", "name": "Project 2"} ]) projects = planka_client.get_projects() assert len(projects) == 2 assert projects[0]["name"] == "Project 1" assert projects[1]["id"] == "2" assert m.request_history[0].headers["Authorization"] == "Bearer test_token" def test_get_boards(planka_client): with requests_mock.Mocker() as m: m.get("https://planka.example.com/api/projects/1", json={ "included": { "boards": [{"id": "b1", "name": "Board 1"}] } }) boards = planka_client.get_boards("1") assert len(boards) == 1 assert boards[0]["name"] == "Board 1" def test_get_cards(planka_client): with requests_mock.Mocker() as m: m.get("https://planka.example.com/api/boards/b1", json={ "included": { "cards": [{"id": "c1", "name": "Card 1"}] } }) cards = planka_client.get_cards("b1") assert len(cards) == 1 assert cards[0]["name"] == "Card 1" def test_create_card(planka_client): with requests_mock.Mocker() as m: m.post("https://planka.example.com/api/cards", json={ "id": "cnew", "name": "New Card" }) card = planka_client.create_card("b1", "l1", "New Card", "Desc") assert card["id"] == "cnew" assert m.request_history[0].json() == { "boardId": "b1", "listId": "l1", "name": "New Card", "description": "Desc" } def test_get_board_lists(planka_client): with requests_mock.Mocker() as m: m.get("https://planka.example.com/api/boards/b1", json={ "included": { "lists": [{"id": "l1", "name": "List 1"}] } }) lists = planka_client.get_board_lists("b1") assert len(lists) == 1 assert lists[0]["name"] == "List 1" def test_get_actions(planka_client): with requests_mock.Mocker() as m: m.get("https://planka.example.com/api/cards/c1/actions", json={ "items": [{"id": "a1", "type": "commentCard"}] }) actions = planka_client.get_actions("c1") assert len(actions) == 1 assert actions[0]["type"] == "commentCard" def test_create_comment(planka_client): with requests_mock.Mocker() as m: m.post("https://planka.example.com/api/cards/c1/actions", json={ "id": "a2" }) comment = planka_client.create_comment("c1", "Hello") assert comment["id"] == "a2" assert m.request_history[0].json()["data"]["text"] == "Hello"