Skip to content

Commit

Permalink
[Fix] Failed Unittest
Browse files Browse the repository at this point in the history
Signed-off-by: Kent Huang <kent@infuseai.io>
  • Loading branch information
kentwelcome committed Oct 4, 2024
1 parent c4925a1 commit 8a88897
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
1 change: 1 addition & 0 deletions recce/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ async def config_flag():
async def mark_onboarding_completed():
context = default_context()
context.mark_onboarding_completed()
app.state.flag['show_onboarding_guide'] = False


@app.get("/api/info")
Expand Down
11 changes: 7 additions & 4 deletions recce/util/recce_cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,13 @@ def set_onboarding_state(self, state: str):


def get_recce_cloud_onboarding_state(token: str) -> str:
recce_cloud = RecceCloud(token)
user_info = recce_cloud.get_user_info()
if user_info:
return user_info.get('onboarding_state')
try:
recce_cloud = RecceCloud(token)
user_info = recce_cloud.get_user_info()
if user_info:
return user_info.get('onboarding_state')
except Exception as e:
logger.debug(str(e))
return 'undefined'


Expand Down
4 changes: 3 additions & 1 deletion tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,14 @@ def test_cmd_server_with_cloud_without_token(self, mock_run):
result = self.runner.invoke(cli_command_server, ['--cloud', '--password', 'unittest'])
assert result.exit_code == 1

@patch('recce.util.recce_cloud.get_recce_cloud_onboarding_state')
@patch('recce.cli.uvicorn.run')
@patch('recce.cli.RecceStateLoader')
def test_cmd_server_with_cloud(self, mock_state_loader_class, mock_run):
def test_cmd_server_with_cloud(self, mock_state_loader_class, mock_run, mock_get_recce_cloud_onboarding_state):
mock_state_loader = MagicMock(spec=RecceStateLoader)
mock_state_loader.verify.return_value = True
mock_state_loader.review_mode = True
mock_get_recce_cloud_onboarding_state.return_value = 'completed'

mock_state_loader_class.return_value = mock_state_loader
self.runner.invoke(cli_command_server, ['--cloud', '--password', 'unittest', '--cloud-token', 'unittest'])
Expand Down

0 comments on commit 8a88897

Please sign in to comment.