def map_sql_to_schema(team: SqlModelTeam) -> Team: return Team( id=str(team.id), name=team.name, api_key=team.api_key, description=team.description, organization_id=str(team.organization_id), )
def test_list_teams_returns_all_teams(client, custom_test_server): repository_mock = mock.Mock(spec=SqlAlchemyRepository) expected_team_1 = TEAM_1 expected_team_2 = TEAM_2 expected_team_list = [expected_team_1, expected_team_2] repository_mock.list_teams.return_value = [ Team(**expected_team_1), Team(**expected_team_2), ] with custom_test_server.container.team_repository.override( repository_mock): response = client.get("/teams") actual_team_list = response.json() assert response.status_code == status.HTTP_200_OK assert actual_team_list == expected_team_list
def test_add_team(client, custom_test_server): repository_mock = mock.Mock(spec=SqlAlchemyRepository) expected_team = TEAM_1 repository_mock.add_team.return_value = Team(**TEAM_1) with custom_test_server.container.team_repository.override( repository_mock): response = client.post("/team", json=TEAM_TO_CREATE) actual_team = response.json() assert response.status_code == status.HTTP_201_CREATED assert actual_team == expected_team
def test_get_one_team_returns_correct_team(client, custom_test_server): repository_mock = mock.Mock(spec=SqlAlchemyRepository) expected_team = TEAM_1 repository_mock.get_one_team.return_value = Team(**expected_team) with custom_test_server.container.team_repository.override( repository_mock): response = client.get("/team/read_team/", params={"id": TEAM_ID}) actual_team = response.json() assert response.status_code == status.HTTP_200_OK assert actual_team == expected_team
def test_add_team_with_no_org_links_to_data_for_good_org( client, custom_test_server): repository_mock = mock.Mock(spec=SqlAlchemyRepository) default_org_id = ORG_ID repository_mock.add_team.return_value = Team(**TEAM_1) with custom_test_server.container.team_repository.override( repository_mock): response = client.post("/team", json=TEAM_TO_CREATE) actual_team = response.json() assert response.status_code == status.HTTP_201_CREATED assert actual_team["organization_id"] == default_org_id
def test_get_teams_from_organization_returns_correct_team( client, custom_test_server): repository_mock = mock.Mock(spec=SqlAlchemyRepository) expected_team_1 = TEAM_1 expected_team_list = [expected_team_1] repository_mock.get_teams_from_organization.return_value = [ Team(**expected_team_1), ] with custom_test_server.container.team_repository.override( repository_mock): response = client.get("/teams/organization/" + ORG_ID) actual_team_list = response.json() assert response.status_code == status.HTTP_200_OK assert actual_team_list == expected_team_list
from carbonserver.api.infra.repositories.repository_teams import SqlAlchemyRepository from carbonserver.api.schemas import Team, TeamCreate from carbonserver.api.services.team_service import TeamService API_KEY = "9INn3JsdhCGzLAuOUC6rAw" ORG_ID = UUID("e52fe339-164d-4c2b-a8c0-f562dfce066d") ORG_ID_2 = UUID("e395767d-0255-40f3-a314-5d2e01f56fbd") TEAM_ID = UUID("c13e851f-5c2f-403d-98d0-51fe15df3bc3") TEAM_ID_2 = UUID("dd011783-7d05-4376-ab60-9537738be25f") TEAM_1 = Team( id=TEAM_ID, name="DFG Code Carbon", description="DFG Code Carbon Team", api_key=API_KEY, organization_id=ORG_ID, ) TEAM_2 = Team( id=TEAM_ID_2, name="DFG Code Carbon 2", description="DFG Code Carbon 2", api_key=API_KEY, organization_id=ORG_ID_2, ) @mock.patch("uuid.uuid4", return_value=TEAM_ID) def test_teams_service_creates_correct_team(_):