|
| 1 | +from unittest.mock import patch |
| 2 | + |
| 3 | +import pytest |
| 4 | + |
| 5 | +from blindpay import BlindPay, BlindPaySync |
| 6 | + |
| 7 | + |
| 8 | +class TestSandbox: |
| 9 | + @pytest.fixture(autouse=True) |
| 10 | + def setup(self): |
| 11 | + self.blindpay = BlindPay(api_key="test-key", instance_id="in_000000000000") |
| 12 | + |
| 13 | + @pytest.mark.asyncio |
| 14 | + async def test_list(self): |
| 15 | + mocked_data = [{"id": "sb_000000000000", "name": "My Sandbox Item", "status": "active"}] |
| 16 | + |
| 17 | + with patch.object(self.blindpay._api, "_request") as mock_request: |
| 18 | + mock_request.return_value = {"data": mocked_data, "error": None} |
| 19 | + |
| 20 | + response = await self.blindpay.sandbox.list() |
| 21 | + |
| 22 | + assert response["error"] is None |
| 23 | + assert response["data"] == mocked_data |
| 24 | + mock_request.assert_called_once_with("GET", "/instances/in_000000000000/sandbox") |
| 25 | + |
| 26 | + @pytest.mark.asyncio |
| 27 | + async def test_get(self): |
| 28 | + mocked_data = {"id": "sb_000000000000", "name": "My Sandbox Item", "status": "active"} |
| 29 | + |
| 30 | + with patch.object(self.blindpay._api, "_request") as mock_request: |
| 31 | + mock_request.return_value = {"data": mocked_data, "error": None} |
| 32 | + |
| 33 | + response = await self.blindpay.sandbox.get("sb_000000000000") |
| 34 | + |
| 35 | + assert response["error"] is None |
| 36 | + assert response["data"] == mocked_data |
| 37 | + mock_request.assert_called_once_with("GET", "/instances/in_000000000000/sandbox/sb_000000000000") |
| 38 | + |
| 39 | + @pytest.mark.asyncio |
| 40 | + async def test_create(self): |
| 41 | + mocked_data = {"id": "sb_000000000000", "name": "My Sandbox Item", "status": "active"} |
| 42 | + |
| 43 | + with patch.object(self.blindpay._api, "_request") as mock_request: |
| 44 | + mock_request.return_value = {"data": mocked_data, "error": None} |
| 45 | + |
| 46 | + response = await self.blindpay.sandbox.create({"name": "My Sandbox Item"}) |
| 47 | + |
| 48 | + assert response["error"] is None |
| 49 | + assert response["data"] == mocked_data |
| 50 | + mock_request.assert_called_once_with("POST", "/instances/in_000000000000/sandbox", {"name": "My Sandbox Item"}) |
| 51 | + |
| 52 | + @pytest.mark.asyncio |
| 53 | + async def test_update(self): |
| 54 | + mocked_data = {"id": "sb_000000000000", "name": "Updated Name", "status": "active"} |
| 55 | + |
| 56 | + with patch.object(self.blindpay._api, "_request") as mock_request: |
| 57 | + mock_request.return_value = {"data": mocked_data, "error": None} |
| 58 | + |
| 59 | + response = await self.blindpay.sandbox.update({"sandbox_id": "sb_000000000000", "name": "Updated Name"}) |
| 60 | + |
| 61 | + assert response["error"] is None |
| 62 | + assert response["data"] == mocked_data |
| 63 | + mock_request.assert_called_once_with( |
| 64 | + "PATCH", "/instances/in_000000000000/sandbox/sb_000000000000", {"name": "Updated Name"} |
| 65 | + ) |
| 66 | + |
| 67 | + @pytest.mark.asyncio |
| 68 | + async def test_delete(self): |
| 69 | + with patch.object(self.blindpay._api, "_request") as mock_request: |
| 70 | + mock_request.return_value = {"data": None, "error": None} |
| 71 | + |
| 72 | + response = await self.blindpay.sandbox.delete("sb_000000000000") |
| 73 | + |
| 74 | + assert response["error"] is None |
| 75 | + mock_request.assert_called_once_with("DELETE", "/instances/in_000000000000/sandbox/sb_000000000000", None) |
| 76 | + |
| 77 | + |
| 78 | +class TestSandboxSync: |
| 79 | + @pytest.fixture(autouse=True) |
| 80 | + def setup(self): |
| 81 | + self.blindpay = BlindPaySync(api_key="test-key", instance_id="in_000000000000") |
| 82 | + |
| 83 | + def test_list(self): |
| 84 | + mocked_data = [{"id": "sb_000000000000", "name": "My Sandbox Item", "status": "active"}] |
| 85 | + |
| 86 | + with patch.object(self.blindpay._api, "_request") as mock_request: |
| 87 | + mock_request.return_value = {"data": mocked_data, "error": None} |
| 88 | + |
| 89 | + response = self.blindpay.sandbox.list() |
| 90 | + |
| 91 | + assert response["error"] is None |
| 92 | + assert response["data"] == mocked_data |
| 93 | + mock_request.assert_called_once_with("GET", "/instances/in_000000000000/sandbox") |
| 94 | + |
| 95 | + def test_get(self): |
| 96 | + mocked_data = {"id": "sb_000000000000", "name": "My Sandbox Item", "status": "active"} |
| 97 | + |
| 98 | + with patch.object(self.blindpay._api, "_request") as mock_request: |
| 99 | + mock_request.return_value = {"data": mocked_data, "error": None} |
| 100 | + |
| 101 | + response = self.blindpay.sandbox.get("sb_000000000000") |
| 102 | + |
| 103 | + assert response["error"] is None |
| 104 | + assert response["data"] == mocked_data |
| 105 | + mock_request.assert_called_once_with("GET", "/instances/in_000000000000/sandbox/sb_000000000000") |
| 106 | + |
| 107 | + def test_create(self): |
| 108 | + mocked_data = {"id": "sb_000000000000", "name": "My Sandbox Item", "status": "active"} |
| 109 | + |
| 110 | + with patch.object(self.blindpay._api, "_request") as mock_request: |
| 111 | + mock_request.return_value = {"data": mocked_data, "error": None} |
| 112 | + |
| 113 | + response = self.blindpay.sandbox.create({"name": "My Sandbox Item"}) |
| 114 | + |
| 115 | + assert response["error"] is None |
| 116 | + assert response["data"] == mocked_data |
| 117 | + mock_request.assert_called_once_with("POST", "/instances/in_000000000000/sandbox", {"name": "My Sandbox Item"}) |
| 118 | + |
| 119 | + def test_update(self): |
| 120 | + mocked_data = {"id": "sb_000000000000", "name": "Updated Name", "status": "active"} |
| 121 | + |
| 122 | + with patch.object(self.blindpay._api, "_request") as mock_request: |
| 123 | + mock_request.return_value = {"data": mocked_data, "error": None} |
| 124 | + |
| 125 | + response = self.blindpay.sandbox.update({"sandbox_id": "sb_000000000000", "name": "Updated Name"}) |
| 126 | + |
| 127 | + assert response["error"] is None |
| 128 | + assert response["data"] == mocked_data |
| 129 | + mock_request.assert_called_once_with( |
| 130 | + "PATCH", "/instances/in_000000000000/sandbox/sb_000000000000", {"name": "Updated Name"} |
| 131 | + ) |
| 132 | + |
| 133 | + def test_delete(self): |
| 134 | + with patch.object(self.blindpay._api, "_request") as mock_request: |
| 135 | + mock_request.return_value = {"data": None, "error": None} |
| 136 | + |
| 137 | + response = self.blindpay.sandbox.delete("sb_000000000000") |
| 138 | + |
| 139 | + assert response["error"] is None |
| 140 | + mock_request.assert_called_once_with("DELETE", "/instances/in_000000000000/sandbox/sb_000000000000", None) |
0 commit comments