|
| 1 | +from unittest.mock import AsyncMock, MagicMock |
| 2 | + |
| 3 | +import pytest |
| 4 | + |
| 5 | +from aleph.sdk import AlephHttpClient |
| 6 | +from aleph.sdk.client.services.settings import NetworkSettingsModel, Settings |
| 7 | + |
| 8 | + |
| 9 | +@pytest.fixture |
| 10 | +def mock_settings_aggregate_response(): |
| 11 | + return { |
| 12 | + "compatible_gpus": [ |
| 13 | + { |
| 14 | + "name": "AD102GL [L40S]", |
| 15 | + "model": "L40S", |
| 16 | + "vendor": "NVIDIA", |
| 17 | + "device_id": "10de:26b9", |
| 18 | + }, |
| 19 | + { |
| 20 | + "name": "GB202 [GeForce RTX 5090]", |
| 21 | + "model": "RTX 5090", |
| 22 | + "vendor": "NVIDIA", |
| 23 | + "device_id": "10de:2685", |
| 24 | + }, |
| 25 | + { |
| 26 | + "name": "GB202 [GeForce RTX 5090 D]", |
| 27 | + "model": "RTX 5090", |
| 28 | + "vendor": "NVIDIA", |
| 29 | + "device_id": "10de:2687", |
| 30 | + }, |
| 31 | + { |
| 32 | + "name": "AD102 [GeForce RTX 4090]", |
| 33 | + "model": "RTX 4090", |
| 34 | + "vendor": "NVIDIA", |
| 35 | + "device_id": "10de:2684", |
| 36 | + }, |
| 37 | + { |
| 38 | + "name": "AD102 [GeForce RTX 4090 D]", |
| 39 | + "model": "RTX 4090", |
| 40 | + "vendor": "NVIDIA", |
| 41 | + "device_id": "10de:2685", |
| 42 | + }, |
| 43 | + { |
| 44 | + "name": "GA102 [GeForce RTX 3090]", |
| 45 | + "model": "RTX 3090", |
| 46 | + "vendor": "NVIDIA", |
| 47 | + "device_id": "10de:2204", |
| 48 | + }, |
| 49 | + { |
| 50 | + "name": "GA102 [GeForce RTX 3090 Ti]", |
| 51 | + "model": "RTX 3090", |
| 52 | + "vendor": "NVIDIA", |
| 53 | + "device_id": "10de:2203", |
| 54 | + }, |
| 55 | + { |
| 56 | + "name": "AD104GL [RTX 4000 SFF Ada Generation]", |
| 57 | + "model": "RTX 4000 ADA", |
| 58 | + "vendor": "NVIDIA", |
| 59 | + "device_id": "10de:27b0", |
| 60 | + }, |
| 61 | + { |
| 62 | + "name": "AD104GL [RTX 4000 Ada Generation]", |
| 63 | + "model": "RTX 4000 ADA", |
| 64 | + "vendor": "NVIDIA", |
| 65 | + "device_id": "10de:27b2", |
| 66 | + }, |
| 67 | + { |
| 68 | + "name": "GA102GL [RTX A5000]", |
| 69 | + "model": "RTX A5000", |
| 70 | + "vendor": "NVIDIA", |
| 71 | + "device_id": "10de:2231", |
| 72 | + }, |
| 73 | + { |
| 74 | + "name": "GA102GL [RTX A6000]", |
| 75 | + "model": "RTX A6000", |
| 76 | + "vendor": "NVIDIA", |
| 77 | + "device_id": "10de:2230", |
| 78 | + }, |
| 79 | + { |
| 80 | + "name": "GH100 [H100]", |
| 81 | + "model": "H100", |
| 82 | + "vendor": "NVIDIA", |
| 83 | + "device_id": "10de:2336", |
| 84 | + }, |
| 85 | + { |
| 86 | + "name": "GH100 [H100 NVSwitch]", |
| 87 | + "model": "H100", |
| 88 | + "vendor": "NVIDIA", |
| 89 | + "device_id": "10de:22a3", |
| 90 | + }, |
| 91 | + { |
| 92 | + "name": "GH100 [H100 CNX]", |
| 93 | + "model": "H100", |
| 94 | + "vendor": "NVIDIA", |
| 95 | + "device_id": "10de:2313", |
| 96 | + }, |
| 97 | + { |
| 98 | + "name": "GH100 [H100 SXM5 80GB]", |
| 99 | + "model": "H100", |
| 100 | + "vendor": "NVIDIA", |
| 101 | + "device_id": "10de:2330", |
| 102 | + }, |
| 103 | + { |
| 104 | + "name": "GH100 [H100 PCIe]", |
| 105 | + "model": "H100", |
| 106 | + "vendor": "NVIDIA", |
| 107 | + "device_id": "10de:2331", |
| 108 | + }, |
| 109 | + { |
| 110 | + "name": "GA100", |
| 111 | + "model": "A100", |
| 112 | + "vendor": "NVIDIA", |
| 113 | + "device_id": "10de:2080", |
| 114 | + }, |
| 115 | + { |
| 116 | + "name": "GA100", |
| 117 | + "model": "A100", |
| 118 | + "vendor": "NVIDIA", |
| 119 | + "device_id": "10de:2081", |
| 120 | + }, |
| 121 | + { |
| 122 | + "name": "GA100 [A100 SXM4 80GB]", |
| 123 | + "model": "A100", |
| 124 | + "vendor": "NVIDIA", |
| 125 | + "device_id": "10de:20b2", |
| 126 | + }, |
| 127 | + { |
| 128 | + "name": "GA100 [A100 PCIe 80GB]", |
| 129 | + "model": "A100", |
| 130 | + "vendor": "NVIDIA", |
| 131 | + "device_id": "10de:20b5", |
| 132 | + }, |
| 133 | + { |
| 134 | + "name": "GA100 [A100X]", |
| 135 | + "model": "A100", |
| 136 | + "vendor": "NVIDIA", |
| 137 | + "device_id": "10de:20b8", |
| 138 | + }, |
| 139 | + { |
| 140 | + "name": "GH100 [H200 SXM 141GB]", |
| 141 | + "model": "H200", |
| 142 | + "vendor": "NVIDIA", |
| 143 | + "device_id": "10de:2335", |
| 144 | + }, |
| 145 | + { |
| 146 | + "name": "GH100 [H200 NVL]", |
| 147 | + "model": "H200", |
| 148 | + "vendor": "NVIDIA", |
| 149 | + "device_id": "10de:233b", |
| 150 | + }, |
| 151 | + { |
| 152 | + "name": "AD102GL [RTX 6000 ADA]", |
| 153 | + "model": "RTX 6000 ADA", |
| 154 | + "vendor": "NVIDIA", |
| 155 | + "device_id": "10de:26b1", |
| 156 | + }, |
| 157 | + ], |
| 158 | + "last_crn_version": "1.7.2", |
| 159 | + "community_wallet_address": "0x5aBd3258C5492fD378EBC2e0017416E199e5Da56", |
| 160 | + "community_wallet_timestamp": 1739996239, |
| 161 | + } |
| 162 | + |
| 163 | + |
| 164 | +@pytest.mark.asyncio |
| 165 | +async def test_get_settings_aggregate( |
| 166 | + make_mock_aiohttp_session, mock_settings_aggregate_response |
| 167 | +): |
| 168 | + client = AlephHttpClient(api_server="http://localhost") |
| 169 | + |
| 170 | + # Properly mock the fetch_aggregate method using monkeypatch |
| 171 | + client._http_session = MagicMock() |
| 172 | + monkeypatch = AsyncMock(return_value=mock_settings_aggregate_response) |
| 173 | + setattr(client, "fetch_aggregate", monkeypatch) |
| 174 | + |
| 175 | + settings_service = Settings(client) |
| 176 | + result = await settings_service.get_settings_aggregate() |
| 177 | + |
| 178 | + assert isinstance(result, NetworkSettingsModel) |
| 179 | + assert len(result.compatible_gpus) == 24 # We have 24 GPUs in the mock data |
| 180 | + |
| 181 | + rtx4000_gpu = next( |
| 182 | + gpu for gpu in result.compatible_gpus if gpu.device_id == "10de:27b0" |
| 183 | + ) |
| 184 | + assert rtx4000_gpu.name == "AD104GL [RTX 4000 SFF Ada Generation]" |
| 185 | + assert rtx4000_gpu.model == "RTX 4000 ADA" |
| 186 | + assert rtx4000_gpu.vendor == "NVIDIA" |
| 187 | + |
| 188 | + assert result.last_crn_version == "1.7.2" |
| 189 | + assert ( |
| 190 | + result.community_wallet_address == "0x5aBd3258C5492fD378EBC2e0017416E199e5Da56" |
| 191 | + ) |
| 192 | + assert result.community_wallet_timestamp == 1739996239 |
| 193 | + |
| 194 | + # Verify that fetch_aggregate was called with the correct parameters |
| 195 | + assert monkeypatch.call_count == 1 |
| 196 | + assert ( |
| 197 | + monkeypatch.call_args.kwargs["address"] |
| 198 | + == "0xFba561a84A537fCaa567bb7A2257e7142701ae2A" |
| 199 | + ) |
| 200 | + assert monkeypatch.call_args.kwargs["key"] == "settings" |
0 commit comments