Coverage for src/fastapi_cloud_cli/commands/teams/get.py: 100%

36 statements  

« prev     ^ index     » next       coverage.py v7.16.0, created at 2026-11-09 00:25 +0000

1import logging 1abcdefg

2from typing import Annotated, Any 1abcdefg

3 

4import typer 1abcdefg

5from pydantic import BaseModel 1abcdefg

6from rich_toolkit import RichToolkit 1abcdefg

7 

8from fastapi_cloud_cli.api import APIClient 1abcdefg

9from fastapi_cloud_cli.commands._auth import UserCommand, get_user_command_context 1abcdefg

10from fastapi_cloud_cli.commands.teams._app import teams_app 1abcdefg

11from fastapi_cloud_cli.config import Settings 1abcdefg

12from fastapi_cloud_cli.utils.cli import get_details_table 1abcdefg

13from fastapi_cloud_cli.utils.execution import JsonOutputOption 1abcdefg

14 

15logger = logging.getLogger(__name__) 1abcdefg

16 

17 

18class Team(BaseModel): 1abcdefg

19 id: str 1abcdefg

20 slug: str 1abcdefg

21 name: str 1abcdefg

22 

23 

24class TeamGetOutput(BaseModel): 1abcdefg

25 team: Team 1abcdefg

26 

27 

28def _get_team_dashboard_url(team: Team, *, settings: Settings) -> str: 1abcdefg

29 return f"{settings.dashboard_base_url}/{team.slug}/apps" 1hJiKmLjMkNnOlP

30 

31 

32def _get_team(client: APIClient, team_id: str) -> TeamGetOutput: 1abcdefg

33 response = client.get(f"/teams/{team_id}") 1ohvwqizArmBCsjDEpkxytnFGulHI

34 response.raise_for_status() 1ohvwqizArmBCsjDEpkxytnFGulHI

35 

36 team = Team.model_validate(response.json()) 1ohqirmsjpktnul

37 

38 return TeamGetOutput(team=team) 1ohqirmsjpktnul

39 

40 

41def _render_team_get_output(data: TeamGetOutput, toolkit: RichToolkit) -> None: 1abicdjefgl

42 toolkit.print(f"[bold]{data.team.name}[/bold]", emoji="🏢") 1himjknl

43 toolkit.print_line() 1himjknl

44 toolkit.print( 1himjknl

45 get_details_table( 

46 [ 

47 ("id", data.team.id), 

48 ("slug", data.team.slug), 

49 ("url", _get_team_dashboard_url(data.team, settings=Settings.get())), 

50 ] 

51 ) 

52 ) 

53 

54 

55@teams_app.command("get", cls=UserCommand) 1abcdefg

56def get_team( 1abQcdRefgS

57 ctx: typer.Context, 

58 team_id: Annotated[ 

59 str, 

60 typer.Argument( 

61 help="ID of the team to return.", 

62 ), 

63 ], 

64 json_output: JsonOutputOption = False, 

65) -> Any: 

66 """ 

67 Get a FastAPI Cloud team by ID. 

68 """ 

69 

70 toolkit = get_user_command_context(ctx).toolkit 1ohvwqizArmBCsjDEpkxytnFGulHI

71 

72 with ( 1ohvwpkxy

73 APIClient() as client, 

74 toolkit.progress( 

75 title="Fetching team", 

76 transient=True, 

77 ) as progress, 

78 ): 

79 with client.handle_http_errors( 1ohvwqizArmBCsjDEpkxytnFGulHI

80 progress, 

81 default_message="Error fetching team. Please try again later.", 

82 not_found_message="Team not found.", 

83 toolkit=toolkit, 

84 ): 

85 result = _get_team(client, team_id) 1ohvwqizArmBCsjDEpkxytnFGulHI

86 

87 toolkit.success(result, render_output=_render_team_get_output) 1ohqirmsjpktnul