Skip to content

Commit

Permalink
[BUGFIX] fix failing tests (#5331)
Browse files Browse the repository at this point in the history
# Description
<!-- Please include a summary of the changes and the related issue.
Please also include relevant motivation and context. List any
dependencies that are required for this change. -->

This PR fixes tests errors since latest changes in the server setup.

**Type of change**
<!-- Please delete options that are not relevant. Remember to title the
PR according to the type of change -->

- Bug fix (non-breaking change which fixes an issue)

**How Has This Been Tested**
<!-- Please add some reference about how your feature has been tested.
-->

**Checklist**
<!-- Please go over the list and make sure you've taken everything into
account -->

- 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/)
  • Loading branch information
frascuchon authored Jul 30, 2024
1 parent 0c860ec commit 407bd4a
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 44 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/argilla.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
11 changes: 8 additions & 3 deletions argilla/tests/integration/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion argilla/tests/integration/test_add_records.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
11 changes: 0 additions & 11 deletions argilla/tests/integration/test_create_datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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(
Expand Down
11 changes: 0 additions & 11 deletions argilla/tests/integration/test_dataset_workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
22 changes: 6 additions & 16 deletions argilla/tests/integration/test_manage_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,47 +11,37 @@
# 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

from argilla import User, Argilla, Workspace
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)
Expand Down
3 changes: 2 additions & 1 deletion argilla/tests/integration/test_manage_workspaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 407bd4a

Please sign in to comment.