Skip to content

Commit

Permalink
Update block creation in a couple of tests
Browse files Browse the repository at this point in the history
  • Loading branch information
desertaxle committed Jul 25, 2024
1 parent 02d8e97 commit 8775b12
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
11 changes: 6 additions & 5 deletions src/prefect/server/api/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import asyncio
import atexit
import contextlib
import mimetypes
import os
import shutil
Expand Down Expand Up @@ -771,11 +772,11 @@ def __init__(self, port: Optional[int] = None):
self._initialized = True

def find_available_port(self):
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind(("", 0)) # Bind to a free port provided by the host.
port = s.getsockname()[1] # Retrieve the port number assigned.
s.close()
return port
with contextlib.closing(
socket.socket(socket.AF_INET, socket.SOCK_STREAM)
) as sock:
sock.bind(("127.0.0.1", 0))
return sock.getsockname()[1]

def address(self) -> str:
return f"http://127.0.0.1:{self.port}"
Expand Down
4 changes: 2 additions & 2 deletions tests/events/server/actions/test_calling_webhook.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ async def take_a_picture_work_queue(


@pytest.fixture
async def webhook_block_id() -> UUID:
async def webhook_block_id(prefect_client) -> UUID:
block = Webhook(method="POST", url="https://example.com", headers={"foo": "bar"})
return await block.save(name="webhook-test")
return await block.save(name="webhook-test", client=prefect_client)


@pytest.fixture
Expand Down
6 changes: 3 additions & 3 deletions tests/server/models/test_block_documents.py
Original file line number Diff line number Diff line change
Expand Up @@ -1754,16 +1754,16 @@ async def test_updating_secret_block_document_with_obfuscated_result_is_ignored(
# x was NOT overwritten
assert block2.data["x"] != obfuscate_string(X)

async def test_block_with_list_of_secrets(self, session):
async def test_block_with_list_of_secrets(self, session, prefect_client):
class ListSecretBlock(Block):
x: List[SecretStr]

# save the block
orig_block = ListSecretBlock(x=["a", "b"])
await orig_block.save(name="list-secret")
await orig_block.save(name="list-secret", client=prefect_client)

# load the block
block = await ListSecretBlock.load("list-secret")
block = await ListSecretBlock.load("list-secret", client=prefect_client)

assert block.x[0].get_secret_value() == "a"
assert block.x[1].get_secret_value() == "b"
Expand Down

0 comments on commit 8775b12

Please sign in to comment.