Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add logout command #3605

Merged
merged 9 commits into from
Aug 28, 2023
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ These are the section headers that we use:

- Added `login` function in `argilla.client.login` to login into an Argilla server and store the credentials locally ([#3582](https://github.com/argilla-io/argilla/pull/3582)).
- Added `login` command to login into an Argilla server ([#3600](https://github.com/argilla-io/argilla/pull/3600)).
- Added `logout` command to logout from an Argilla server ([#3605](https://github.com/argilla-io/argilla/pull/3605)).
- Added `DELETE /api/v1/suggestions/{suggestion_id}` endpoint to delete a suggestion given its ID ([#3617](https://github.com/argilla-io/argilla/pull/3617)).
- Added `DELETE /api/v1/records/{record_id}/suggestions` endpoint to delete several suggestions linked to the same record given their IDs ([#3617](https://github.com/argilla-io/argilla/pull/3617)).
- Added `response_status` param to `GET /api/v1/datasets/{dataset_id}/records` to be able to filter by `response_status` as previously included for `GET /api/v1/me/datasets/{dataset_id}/records` ([#3613](https://github.com/argilla-io/argilla/pull/3613)).
Expand Down
3 changes: 2 additions & 1 deletion src/argilla/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@
# limitations under the License.


from argilla.tasks import database_app, login_app, server_app, training_app
from argilla.tasks import database_app, login_app, logout_app, server_app, training_app
from argilla.tasks.async_typer import AsyncTyper

app = AsyncTyper(rich_help_panel=True, help="Argilla CLI", no_args_is_help=True)

app.add_typer(database_app, name="database")
app.add_typer(login_app, name="login")
app.add_typer(logout_app, name="logout")
app.add_typer(server_app, name="server")
app.add_typer(training_app, name="train")

Expand Down
1 change: 1 addition & 0 deletions src/argilla/tasks/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@

from .database import app as database_app
from .login import app as login_app
from .logout import app as logout_app
from .server import app as server_app
from .training import app as training_app
18 changes: 18 additions & 0 deletions src/argilla/tasks/logout/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Copyright 2021-present, the Recognai S.L. team.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# 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.

from .__main__ import app

if __name__ == "__main__":
app()
32 changes: 32 additions & 0 deletions src/argilla/tasks/logout/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Copyright 2021-present, the Recognai S.L. team.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# 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 typer

app = typer.Typer(invoke_without_command=True)


@app.callback(help="Logout from an Argilla Server.")
def logout():
from argilla.client.login import ArgillaCredentials
from argilla.tasks.callback import init_callback

init_callback()
ArgillaCredentials.remove()
typer.echo("Logged out successfully from Argilla server!")


if __name__ == "__main__":
app()
13 changes: 13 additions & 0 deletions tests/unit/tasks/logout/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright 2021-present, the Recognai S.L. team.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# 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.
47 changes: 47 additions & 0 deletions tests/unit/tasks/logout/test_logout.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Copyright 2021-present, the Recognai S.L. team.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# 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.

from typing import TYPE_CHECKING

if TYPE_CHECKING:
from click.testing import CliRunner
from pytest_mock import MockerFixture
from typer import Typer


def test_logout(cli_runner: "CliRunner", cli: "Typer", mocker: "MockerFixture"):
init_callback_mock = mocker.patch("argilla.tasks.callback.init_callback")
argilla_credentials_remove_mock = mocker.patch("argilla.client.login.ArgillaCredentials.remove")

result = cli_runner.invoke(
cli,
"logout",
)
assert result.exit_code == 0

init_callback_mock.assert_called_once()
argilla_credentials_remove_mock.assert_called_once()


def test_logout_fails(cli_runner: "CliRunner", cli: "Typer", mocker: "MockerFixture"):
init_callback_mock = mocker.patch("argilla.tasks.callback.init_callback")
init_callback_mock.side_effect = ValueError("Error")

result = cli_runner.invoke(
cli,
"logout",
)
assert result.exit_code == 1

init_callback_mock.assert_called_once()