Skip to content

Commit

Permalink
Merge pull request #1131 from guardrails-ai/bug/first-time-login
Browse files Browse the repository at this point in the history
referesh settings singleton after writing to rc
  • Loading branch information
zsimjee authored Oct 19, 2024
2 parents 5b3aca8 + 3a6f809 commit de707ee
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
3 changes: 3 additions & 0 deletions guardrails/cli/configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ def save_configuration_file(
rc_file.writelines(lines)
rc_file.close()

settings._initialize()


def _get_default_token() -> str:
"""Get the default token from the configuration file."""
Expand Down Expand Up @@ -106,6 +108,7 @@ def configure(

try:
save_configuration_file(token, enable_metrics, remote_inferencing)
# update setting singleton
logger.info("Configuration saved.")
except Exception as e:
logger.error("An unexpected error occured saving configuration!")
Expand Down
7 changes: 6 additions & 1 deletion tests/unit_tests/cli/test_configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ def test_save_configuration_file(mocker):
expanduser_mock = mocker.patch("guardrails.cli.configure.expanduser")
expanduser_mock.return_value = "/Home"

rcexpanduser_mock = mocker.patch("guardrails.classes.rc.expanduser")
rcexpanduser_mock.return_value = "/Home"

import os

join_spy = mocker.spy(os.path, "join")
Expand All @@ -88,7 +91,9 @@ def test_save_configuration_file(mocker):
save_configuration_file("token", True)

assert expanduser_mock.called is True
join_spy.assert_called_once_with("/Home", ".guardrailsrc")
assert rcexpanduser_mock.called is True
join_spy.assert_called_with("/Home", ".guardrailsrc")
assert join_spy.call_count == 2

assert mock_open.call_count == 1
writelines_spy.assert_called_once_with(
Expand Down

0 comments on commit de707ee

Please sign in to comment.