Esempio n. 1
0
def test_teams_service_retrieves_correct_team_by_organization_id():

    repository_mock: SqlAlchemyRepository = mock.Mock(spec=SqlAlchemyRepository)
    expected_organization_id = ORG_ID
    team_service: TeamService = TeamService(repository_mock)
    repository_mock.get_teams_from_organization.return_value = [TEAM_1]

    actual_teams = team_service.list_teams_from_organization(ORG_ID)

    assert actual_teams[0].organization_id == expected_organization_id
Esempio n. 2
0
def test_teams_service_retrieves_correct_team_by_id():

    repository_mock: SqlAlchemyRepository = mock.Mock(spec=SqlAlchemyRepository)
    expected_org: Team = TEAM_1
    organization_service: TeamService = TeamService(repository_mock)
    repository_mock.get_one_team.return_value = TEAM_1

    actual_saved_org = organization_service.read_team(TEAM_ID)

    assert actual_saved_org.id == expected_org.id
    assert actual_saved_org.name == expected_org.name
Esempio n. 3
0
def test_teams_service_retrieves_all_existing_teams():

    repository_mock: SqlAlchemyRepository = mock.Mock(spec=SqlAlchemyRepository)
    expected_team_ids_list = [TEAM_ID, TEAM_ID_2]
    organization_service: TeamService = TeamService(repository_mock)
    repository_mock.list_teams.return_value = [TEAM_1, TEAM_2]

    team_list = organization_service.list_teams()
    actual_team_ids_list = map(lambda x: x.id, iter(team_list))
    diff = set(actual_team_ids_list) ^ set(expected_team_ids_list)

    assert not diff
    assert len(team_list) == len(expected_team_ids_list)
Esempio n. 4
0
def test_teams_service_creates_correct_team(_):

    repository_mock: SqlAlchemyRepository = mock.Mock(spec=SqlAlchemyRepository)
    expected_id = TEAM_ID
    user_service: TeamService = TeamService(repository_mock)
    repository_mock.add_team.return_value = TEAM_1
    team_to_create = TeamCreate(
        name="DFG Code Carbon",
        description="DFG Code Carbon Team",
        organization_id=ORG_ID,
    )

    actual_saved_org = user_service.add_team(team_to_create)

    repository_mock.add_team.assert_called_with(team_to_create)
    assert actual_saved_org.id == expected_id
Esempio n. 5
0
def read_teams_from_organization(
    organization_id: str,
    team_service: TeamService = Depends(Provide[ServerContainer.team_service]),
):
    return team_service.list_teams_from_organization(organization_id)
Esempio n. 6
0
def list_teams(
    team_service: TeamService = Depends(Provide[ServerContainer.team_service]),
) -> List[Team]:
    return team_service.list_teams()
Esempio n. 7
0
def read_team(
    team_id: str,
    team_service: TeamService = Depends(Provide[ServerContainer.team_service]),
) -> Team:
    return team_service.read_team(team_id)
Esempio n. 8
0
def add_team(
    team: TeamCreate,
    team_service: TeamService = Depends(Provide[ServerContainer.team_service]),
) -> Team:
    return team_service.add_team(team)