|
4 | 4 |
|
5 | 5 | import pytest |
6 | 6 |
|
| 7 | +from .utils import get_random_resource_name |
| 8 | + |
7 | 9 | if TYPE_CHECKING: |
8 | 10 | from apify_client import ApifyClientAsync |
9 | 11 |
|
@@ -113,3 +115,92 @@ async def test_build_wait_for_finish(apify_client_async: ApifyClientAsync) -> No |
113 | 115 |
|
114 | 116 | assert build is not None |
115 | 117 | assert build.id == completed_build.id |
| 118 | + |
| 119 | + |
| 120 | +async def test_build_delete_and_abort(apify_client_async: ApifyClientAsync) -> None: |
| 121 | + """Test deleting and aborting a build on our own actor.""" |
| 122 | + actor_name = get_random_resource_name('actor') |
| 123 | + |
| 124 | + # Create actor with two versions |
| 125 | + created_actor = await apify_client_async.actors().create( |
| 126 | + name=actor_name, |
| 127 | + title='Test Actor for Build Delete', |
| 128 | + versions=[ |
| 129 | + { |
| 130 | + 'versionNumber': '0.1', |
| 131 | + 'sourceType': 'SOURCE_FILES', |
| 132 | + 'buildTag': 'beta', |
| 133 | + 'sourceFiles': [ |
| 134 | + { |
| 135 | + 'name': 'main.js', |
| 136 | + 'format': 'TEXT', |
| 137 | + 'content': 'console.log("Hello v0.1")', |
| 138 | + } |
| 139 | + ], |
| 140 | + }, |
| 141 | + { |
| 142 | + 'versionNumber': '0.2', |
| 143 | + 'sourceType': 'SOURCE_FILES', |
| 144 | + 'buildTag': 'latest', |
| 145 | + 'sourceFiles': [ |
| 146 | + { |
| 147 | + 'name': 'main.js', |
| 148 | + 'format': 'TEXT', |
| 149 | + 'content': 'console.log("Hello v0.2")', |
| 150 | + } |
| 151 | + ], |
| 152 | + }, |
| 153 | + ], |
| 154 | + ) |
| 155 | + assert created_actor is not None |
| 156 | + actor_client = apify_client_async.actor(created_actor.id) |
| 157 | + |
| 158 | + try: |
| 159 | + # Build both versions - we need 2 builds because we can't delete the default build |
| 160 | + first_build = await actor_client.build(version_number='0.1') |
| 161 | + assert first_build is not None |
| 162 | + first_build_client = apify_client_async.build(first_build.id) |
| 163 | + await first_build_client.wait_for_finish() |
| 164 | + |
| 165 | + second_build = await actor_client.build(version_number='0.2') |
| 166 | + assert second_build is not None |
| 167 | + second_build_client = apify_client_async.build(second_build.id) |
| 168 | + |
| 169 | + # Wait for the second build to finish |
| 170 | + finished_build = await second_build_client.wait_for_finish() |
| 171 | + assert finished_build is not None |
| 172 | + assert finished_build.status.value in ('SUCCEEDED', 'FAILED') |
| 173 | + |
| 174 | + # Test abort on already finished build (should return the build in its current state) |
| 175 | + aborted_build = await second_build_client.abort() |
| 176 | + assert aborted_build is not None |
| 177 | + assert aborted_build.status.value in ('SUCCEEDED', 'FAILED', 'ABORTED') |
| 178 | + |
| 179 | + # Delete the first build (not the default/latest) |
| 180 | + await first_build_client.delete() |
| 181 | + |
| 182 | + # Verify the build is deleted |
| 183 | + deleted_build = await first_build_client.get() |
| 184 | + assert deleted_build is None |
| 185 | + |
| 186 | + finally: |
| 187 | + # Cleanup - delete actor |
| 188 | + await actor_client.delete() |
| 189 | + |
| 190 | + |
| 191 | +async def test_build_get_open_api_definition(apify_client_async: ApifyClientAsync) -> None: |
| 192 | + """Test getting OpenAPI definition for a build.""" |
| 193 | + # Get builds for hello-world actor |
| 194 | + actor = apify_client_async.actor(HELLO_WORLD_ACTOR) |
| 195 | + builds_page = await actor.builds().list(limit=1) |
| 196 | + assert builds_page.items |
| 197 | + build_id = builds_page.items[0].id |
| 198 | + |
| 199 | + # Get the OpenAPI definition |
| 200 | + build_client = apify_client_async.build(build_id) |
| 201 | + openapi_def = await build_client.get_open_api_definition() |
| 202 | + |
| 203 | + # OpenAPI definition should be a dict with standard OpenAPI fields |
| 204 | + # Note: May be None if the actor doesn't have an OpenAPI definition |
| 205 | + if openapi_def is not None: |
| 206 | + assert isinstance(openapi_def, dict) |
0 commit comments