From be6eb7599c101d41d6b519b75e27825cef283683 Mon Sep 17 00:00:00 2001 From: Arash Date: Fri, 3 Jan 2025 11:34:11 +0100 Subject: [PATCH] Add ondelete cascade to user credential group foreign keys and update integration tests --- lib/galaxy/model/__init__.py | 4 ++-- test/integration/test_credentials.py | 13 +++++-------- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/lib/galaxy/model/__init__.py b/lib/galaxy/model/__init__.py index 2d37c13919db..fb5a5ae459ff 100644 --- a/lib/galaxy/model/__init__.py +++ b/lib/galaxy/model/__init__.py @@ -11646,7 +11646,7 @@ class Variable(Base): id: Mapped[int] = mapped_column(primary_key=True) user_credential_group_id: Mapped[int] = mapped_column( - ForeignKey("user_credentials_group.id"), index=True, nullable=False + ForeignKey("user_credentials_group.id", ondelete="CASCADE"), index=True, nullable=False ) name: Mapped[str] = mapped_column(nullable=False) value: Mapped[str] = mapped_column(nullable=False) @@ -11663,7 +11663,7 @@ class Secret(Base): id: Mapped[int] = mapped_column(primary_key=True) user_credential_group_id: Mapped[int] = mapped_column( - ForeignKey("user_credentials_group.id"), index=True, nullable=False + ForeignKey("user_credentials_group.id", ondelete="CASCADE"), index=True, nullable=False ) name: Mapped[str] = mapped_column(nullable=False) already_set: Mapped[bool] = mapped_column(nullable=False, default=False) diff --git a/test/integration/test_credentials.py b/test/integration/test_credentials.py index 29fa8842825c..ca383b8cc137 100644 --- a/test/integration/test_credentials.py +++ b/test/integration/test_credentials.py @@ -12,12 +12,14 @@ def test_provide_credential(self): assert created_user_credentials[0]["current_group_name"] == "default" def test_list_user_credentials(self): - list_user_credentials = self._list_user_credentials() + response = self._get("/api/users/current/credentials") + self._assert_status_code_is(response, 200) + list_user_credentials = response.json() assert len(list_user_credentials) > 0 def test_delete_service_credentials(self): - list_user_credentials = self._list_user_credentials() - user_credentials_id = list_user_credentials[0]["id"] + created_user_credentials = self._populate_user_credentials() + user_credentials_id = created_user_credentials[0]["id"] response = self._delete(f"/api/users/current/credentials/{user_credentials_id}") self._assert_status_code_is(response, 204) @@ -72,8 +74,3 @@ def _populate_user_credentials(self): response = self._post("/api/users/current/credentials", data=payload, json=True) self._assert_status_code_is(response, 200) return response.json() - - def _list_user_credentials(self): - response = self._get("/api/users/current/credentials") - self._assert_status_code_is(response, 200) - return response.json()