|
7 | 7 |
|
8 | 8 | import aiohttp
|
9 | 9 | import pytest
|
| 10 | +import typer |
10 | 11 | from aleph.sdk.conf import settings
|
11 | 12 | from aleph_message.models import Chain
|
12 | 13 |
|
@@ -190,6 +191,39 @@ async def upload_program():
|
190 | 191 | await upload_program()
|
191 | 192 |
|
192 | 193 |
|
| 194 | +@pytest.mark.asyncio |
| 195 | +async def test_upload_program_reject(): |
| 196 | + mock_load_account = create_mock_load_account() |
| 197 | + mock_account = mock_load_account.return_value |
| 198 | + mock_auth_client_class, mock_auth_client = create_mock_auth_client(mock_account) |
| 199 | + mock_get_balance = AsyncMock(return_value={"available_amount": 100000}) |
| 200 | + |
| 201 | + @patch("aleph_client.commands.program._load_account", mock_load_account) |
| 202 | + @patch("aleph_client.utils.os.path.isfile", MagicMock(return_value=True)) |
| 203 | + @patch("aleph_client.commands.program.AuthenticatedAlephHttpClient", mock_auth_client_class) |
| 204 | + @patch("aleph_client.commands.program.get_balance", mock_get_balance) |
| 205 | + @patch("aleph_client.commands.program.open", MagicMock()) |
| 206 | + async def upload_program(): |
| 207 | + print() # For better display when pytest -v -s |
| 208 | + with pytest.raises(typer.Exit) as exc_info: |
| 209 | + await upload( |
| 210 | + address=FAKE_ADDRESS_EVM, |
| 211 | + path=Path("/fake/file.squashfs"), |
| 212 | + entrypoint="main:app", |
| 213 | + name="mock_program", |
| 214 | + runtime=settings.DEFAULT_RUNTIME_ID, |
| 215 | + compute_units=6, # Program with more than 4 compute unit should return an error |
| 216 | + updatable=True, |
| 217 | + skip_volume=True, |
| 218 | + skip_env_var=True, |
| 219 | + ) |
| 220 | + mock_load_account.assert_called_once() |
| 221 | + mock_auth_client.create_program.assert_called_once() |
| 222 | + assert exc_info.value.exit_code == 1 |
| 223 | + |
| 224 | + await upload_program() |
| 225 | + |
| 226 | + |
193 | 227 | @pytest.mark.asyncio
|
194 | 228 | async def test_update_program():
|
195 | 229 | mock_load_account = create_mock_load_account()
|
|
0 commit comments