63 lines
1.9 KiB
Python
63 lines
1.9 KiB
Python
import pytest
|
|
from unittest.mock import MagicMock, patch
|
|
from server import PlankaClient
|
|
|
|
@pytest.fixture
|
|
def client():
|
|
return PlankaClient("https://planka.test", "fake-token")
|
|
|
|
def test_get_projects_nested(client):
|
|
mock_response = {
|
|
"items": [
|
|
{"id": "1", "name": "Project 1"},
|
|
{"id": "2", "name": "Project 2"}
|
|
]
|
|
}
|
|
with patch("requests.get") as mock_get:
|
|
mock_get.return_value.json.return_value = mock_response
|
|
mock_get.return_value.status_code = 200
|
|
|
|
projects = client.get_projects()
|
|
assert len(projects) == 2
|
|
assert projects[0]["name"] == "Project 1"
|
|
|
|
def test_get_boards_included(client):
|
|
# Test the 'included' structure we saw in the real API
|
|
mock_response = {
|
|
"included": {
|
|
"boards": [
|
|
{"id": "b1", "name": "Board 1"}
|
|
]
|
|
}
|
|
}
|
|
with patch("requests.get") as mock_get:
|
|
mock_get.return_value.json.return_value = mock_response
|
|
mock_get.return_value.status_code = 200
|
|
|
|
boards = client.get_boards("p1")
|
|
assert len(boards) == 1
|
|
assert boards[0]["name"] == "Board 1"
|
|
|
|
def test_get_boards_empty(client):
|
|
mock_response = {"item": {"id": "p1"}, "included": {}}
|
|
with patch("requests.get") as mock_get:
|
|
mock_get.return_value.json.return_value = mock_response
|
|
mock_get.return_value.status_code = 200
|
|
|
|
boards = client.get_boards("p1")
|
|
assert boards == []
|
|
|
|
def test_get_cards_nested(client):
|
|
mock_response = {
|
|
"items": [
|
|
{"id": "c1", "name": "Card 1"}
|
|
]
|
|
}
|
|
with patch("requests.get") as mock_get:
|
|
mock_get.return_value.json.return_value = mock_response
|
|
mock_get.return_value.status_code = 200
|
|
|
|
cards = client.get_cards("b1")
|
|
assert len(cards) == 1
|
|
assert cards[0]["name"] == "Card 1"
|