Skip to content

Commit

Permalink
test: Delete workspace after webhook test (#9891)
Browse files Browse the repository at this point in the history
  • Loading branch information
gt2345 authored Sep 4, 2024
1 parent a30bc25 commit be2622a
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions e2e_tests/tests/cluster/test_webhooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from tests import api_utils
from tests import config as conf
from tests import experiment as exp
from tests.cluster import utils
from tests.cluster import test_agent_user_group, utils


@pytest.mark.e2e_cpu
Expand Down Expand Up @@ -92,6 +92,7 @@ def test_log_pattern_send_webhook(should_match: bool) -> None:
port = 5006
server = utils.WebhookServer(port)
sess = api_utils.admin_session()
ws_id = []

regex = r"assert 0 <= self\.metrics_sigma"
if not should_match:
Expand All @@ -103,7 +104,7 @@ def test_log_pattern_send_webhook(should_match: bool) -> None:
)

slack_path = f"/test/slack/path/here/{str(uuid.uuid4())}"
bindings.post_PostWebhook(
w = bindings.post_PostWebhook(
sess,
body=bindings.v1Webhook(
url=f"http://localhost:{port}{slack_path}",
Expand All @@ -114,9 +115,10 @@ def test_log_pattern_send_webhook(should_match: bool) -> None:
workspaceId=None,
),
)
ws_id.append(w.webhook.id)

default_path = f"/test/path/here/{str(uuid.uuid4())}"
bindings.post_PostWebhook(
w = bindings.post_PostWebhook(
sess,
body=bindings.v1Webhook(
url=f"http://localhost:{port}{default_path}",
Expand All @@ -127,6 +129,7 @@ def test_log_pattern_send_webhook(should_match: bool) -> None:
workspaceId=None,
),
)
ws_id.append(w.webhook.id)

workspace = bindings.post_PostWorkspace(
sess, body=bindings.v1PostWorkspaceRequest(name=f"webhook-test{random.random()}")
Expand All @@ -141,7 +144,7 @@ def test_log_pattern_send_webhook(should_match: bool) -> None:
).project

specific_path = f"/test/path/here/{str(uuid.uuid4())}"
bindings.post_PostWebhook(
w = bindings.post_PostWebhook(
sess,
body=bindings.v1Webhook(
url=f"http://localhost:{port}{specific_path}",
Expand All @@ -152,9 +155,10 @@ def test_log_pattern_send_webhook(should_match: bool) -> None:
workspaceId=workspace.id,
),
)
ws_id.append(w.webhook.id)

specific_path_unmatch = f"/test/path/here/{str(uuid.uuid4())}"
bindings.post_PostWebhook(
w = bindings.post_PostWebhook(
sess,
body=bindings.v1Webhook(
url=f"http://localhost:{port}{specific_path_unmatch}",
Expand All @@ -165,6 +169,7 @@ def test_log_pattern_send_webhook(should_match: bool) -> None:
workspaceId=1,
),
)
ws_id.append(w.webhook.id)

exp_id = exp.create_experiment(
sess,
Expand Down Expand Up @@ -200,6 +205,10 @@ def test_log_pattern_send_webhook(should_match: bool) -> None:
assert specific_path not in responses
assert specific_path_unmatch not in responses

for i in ws_id:
bindings.delete_DeleteWebhook(sess, id=i or 0)
test_agent_user_group._delete_workspace_and_check(sess, workspace)


@pytest.mark.e2e_cpu
def test_specific_webhook() -> None:
Expand Down Expand Up @@ -273,6 +282,10 @@ def test_specific_webhook() -> None:
responses = server2.close_and_return_responses()
assert len(responses) == 1

bindings.delete_DeleteWebhook(sess, id=webhook_res_1.id or 0)
bindings.delete_DeleteWebhook(sess, id=webhook_res_2.id or 0)
test_agent_user_group._delete_workspace_and_check(sess, workspace)


def create_default_webhook(sess: api.Session, workspaceId: Optional[int] = None) -> int:
webhook_trigger = bindings.v1Trigger(
Expand Down Expand Up @@ -349,6 +362,8 @@ def test_webhook_permission() -> None:
# user should be able to delete webhook from their own workspace
bindings.delete_DeleteWebhook(user2_sess, id=workspace_webhook_id)

test_agent_user_group._delete_workspace_and_check(admin_sess, workspace)


@pytest.mark.e2e_cpu_rbac
@api_utils.skipif_rbac_not_enabled()
Expand Down Expand Up @@ -404,3 +419,5 @@ def test_webhook_rbac() -> None:
bindings.delete_DeleteWebhook(admin_sess, id=global_webhook_id)
# user with editor access to workspace should be able to delete it's webhook
bindings.delete_DeleteWebhook(user2_sess, id=workspace_webhook_id)

test_agent_user_group._delete_workspace_and_check(admin_sess, workspace)

0 comments on commit be2622a

Please sign in to comment.