From 407bd4afb3a76fd05c16e5f07fc62065c4ea5e7d Mon Sep 17 00:00:00 2001 From: Paco Aranda Date: Tue, 30 Jul 2024 09:00:54 +0200 Subject: [PATCH] [BUGFIX] fix failing tests (#5331) # Description This PR fixes tests errors since latest changes in the server setup. **Type of change** - Bug fix (non-breaking change which fixes an issue) **How Has This Been Tested** **Checklist** - I added relevant documentation - I followed the style guidelines of this project - I did a self-review of my code - I made corresponding changes to the documentation - I confirm My changes generate no new warnings - I have added tests that prove my fix is effective or that my feature works - I have added relevant notes to the CHANGELOG.md file (See https://keepachangelog.com/) --- .github/workflows/argilla.yml | 5 ++++- argilla/tests/integration/conftest.py | 11 +++++++--- argilla/tests/integration/test_add_records.py | 2 +- .../tests/integration/test_create_datasets.py | 11 ---------- .../integration/test_dataset_workspace.py | 11 ---------- .../tests/integration/test_manage_users.py | 22 +++++-------------- .../integration/test_manage_workspaces.py | 3 ++- 7 files changed, 21 insertions(+), 44 deletions(-) diff --git a/.github/workflows/argilla.yml b/.github/workflows/argilla.yml index 117ca824de..3896c10f47 100644 --- a/.github/workflows/argilla.yml +++ b/.github/workflows/argilla.yml @@ -27,7 +27,10 @@ jobs: env: ARGILLA_ENABLE_TELEMETRY: 0 ARGILLA_ELASTICSEARCH: http://elasticsearch:9200 - DEFAULT_USER_ENABLED: 1 + # Set credentials + USERNAME: argilla + PASSWORD: 12345678 + API_KEY: argilla.apikey elasticsearch: image: docker.elastic.co/elasticsearch/elasticsearch:8.8.2 ports: diff --git a/argilla/tests/integration/conftest.py b/argilla/tests/integration/conftest.py index 21e4ce8fca..b8d2457550 100644 --- a/argilla/tests/integration/conftest.py +++ b/argilla/tests/integration/conftest.py @@ -22,11 +22,16 @@ @pytest.fixture(scope="session") def client() -> rg.Argilla: client = rg.Argilla() + + if len(list(client.workspaces)) == 0: + client.workspaces.add(rg.Workspace(name=f"test_{uuid.uuid4()}")) + yield client + _cleanup(client) + -@pytest.fixture(autouse=True) -def cleanup(client: rg.Argilla): +def _cleanup(client: rg.Argilla): for workspace in client.workspaces: if workspace.name.startswith("test_"): for dataset in workspace.datasets: @@ -46,7 +51,7 @@ def dataset_name() -> str: @pytest.fixture def workspace(client: Argilla) -> Workspace: - ws_name = "test-workspace" + ws_name = f"test-{uuid.uuid4()}" workspace = client.workspaces(ws_name) if workspace is None: diff --git a/argilla/tests/integration/test_add_records.py b/argilla/tests/integration/test_add_records.py index f53041cf52..adf143a0de 100644 --- a/argilla/tests/integration/test_add_records.py +++ b/argilla/tests/integration/test_add_records.py @@ -22,7 +22,7 @@ def test_create_dataset(client): - workspace = client.workspaces[0] + workspace = client.workspaces.default mock_dataset_name = f"test_create_dataset{datetime.now().strftime('%Y%m%d%H%M%S')}" dataset = rg.Dataset( name=mock_dataset_name, diff --git a/argilla/tests/integration/test_create_datasets.py b/argilla/tests/integration/test_create_datasets.py index 214fb38f95..8848ad1085 100644 --- a/argilla/tests/integration/test_create_datasets.py +++ b/argilla/tests/integration/test_create_datasets.py @@ -12,8 +12,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -import pytest - from argilla import ( Argilla, Dataset, @@ -28,15 +26,6 @@ from argilla.settings._task_distribution import TaskDistribution -@pytest.fixture(scope="session", autouse=True) -def clean_datasets(client: Argilla): - datasets = client.datasets - for dataset in datasets: - if dataset.name.startswith("test_"): - dataset.delete() - yield - - class TestCreateDatasets: def test_create_dataset(self, client: Argilla, dataset_name: str): dataset = Dataset( diff --git a/argilla/tests/integration/test_dataset_workspace.py b/argilla/tests/integration/test_dataset_workspace.py index 284aea93de..f500d0a8a4 100644 --- a/argilla/tests/integration/test_dataset_workspace.py +++ b/argilla/tests/integration/test_dataset_workspace.py @@ -20,17 +20,6 @@ from argilla._exceptions import NotFoundError -@pytest.fixture(autouse=True, scope="session") -def clean_test_datasets(client: rg.Argilla): - for dataset in client.datasets: - if dataset.name.startswith("test_"): - dataset.delete() - yield - for dataset in client.datasets: - if dataset.name.startswith("test_"): - dataset.delete() - - @pytest.fixture def dataset(client: rg.Argilla): ws = client.workspaces[0] diff --git a/argilla/tests/integration/test_manage_users.py b/argilla/tests/integration/test_manage_users.py index 48f44f5076..58d716cef2 100644 --- a/argilla/tests/integration/test_manage_users.py +++ b/argilla/tests/integration/test_manage_users.py @@ -11,6 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +import uuid import pytest @@ -18,40 +19,29 @@ from argilla._exceptions import UnprocessableEntityError -@pytest.fixture(scope="session", autouse=True) -def clean_environment(client: Argilla): - for user in client.users: - if user.username.startswith("test"): - user.delete() - yield - for user in client.users: - if user.username.startswith("test"): - user.delete() - - class TestManageUsers: def test_create_user(self, client: Argilla): - user = User(username="test_user", password="test_password") + user = User(username=f"test_user_{uuid.uuid4()}", password="test_password") client.users.add(user) assert user.id is not None assert client.users(username=user.username).id == user.id def test_create_user_without_password(self, client: Argilla): - user = User(username="test_user") + user = User(username=f"test_user_{uuid.uuid4()}") with pytest.raises(expected_exception=UnprocessableEntityError): client.users.add(user) def test_delete_user(self, client: Argilla): - user = User(username="test_delete_user", password="test_password") + user = User(username=f"test_delete_user_{uuid.uuid4()}", password="test_password") client.users.add(user) user.delete() assert not client.api.users.exist(user.id) def test_add_user_to_workspace(self, client: Argilla, workspace: Workspace): - user = User(username="test_user", password="test_password") + user = User(username=f"test_user_{uuid.uuid4()}", password="test_password") client.users.add(user) - user = client.users(username="test_user") + user = client.users(username=user.username) assert user.password is None user.add_to_workspace(workspace) diff --git a/argilla/tests/integration/test_manage_workspaces.py b/argilla/tests/integration/test_manage_workspaces.py index 0e3dc20143..6462003a65 100644 --- a/argilla/tests/integration/test_manage_workspaces.py +++ b/argilla/tests/integration/test_manage_workspaces.py @@ -11,13 +11,14 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +import uuid from argilla import Argilla, Workspace, User class TestWorkspacesManagement: def test_create_workspace(self, client: Argilla): - workspace = Workspace(name="test_workspace") + workspace = Workspace(name=f"test_workspace{uuid.uuid4()}") client.workspaces.add(workspace) assert workspace in client.workspaces