コード例 #1
0
    def test_adding_new_members(self):
        target_org = mock_org('target_org', team_names=['Team1'])
        team1 = target_org.team('Team1')

        me = mock_user('me')
        assert team1.members() == []

        team1.grant_access(me.login())
        assert team1.members() == [me]
        assert team1.members('member') == [me]
        assert team1.members('maintainer') == []
コード例 #2
0
    def test_adding_existing_member(self):
        team1 = mock_team('Team1', mock_org('target_org',
                                            team_names=['Team1']))
        assert team1.members() == []
        me = mock_user('me')

        team1.grant_access(me.login())
        assert team1.members() == [me]

        team1.grant_access(me.login())
        assert team1.members() == [me]
コード例 #3
0
    def test_adding_existing_team_to_org(self):
        target_org = mock_org('target-org', team_names=['Read', 'Write'])

        read = mock_team('Read', target_org.login())
        write = mock_team('Write', target_org.login())

        assert target_org.teams() == [read, write]

        target_org.create_team('Read')

        assert target_org.teams() == [read, write]
コード例 #4
0
    def test_promote_existing_member(self):
        team1 = mock_team('Team1', mock_org('target_org',
                                            team_names=['Team1']))
        assert team1.members() == []
        me = mock_user('me')

        team1.grant_access(me.login())
        assert team1.members() == [me]

        team1.grant_access(me.login(), 'maintainer')
        assert team1.members() == [me]
        assert team1.members(role='member') == []
        assert team1.members(role='maintainer') == [me]
コード例 #5
0
    def test_team_not_in_repos_until_added(self):
        target_org = mock_org('target_org',
                              number_of_repos=2,
                              team_names=['Team1'])
        team1 = target_org.team('Team1')

        assert team1.name() == 'Team1'
        assert team1.repositories() == []

        repo1, repo2 = target_org.repositories()

        team1.add_to_repo(repo1.login(), 'maintainer')
        assert team1.repositories() == [repo1]
コード例 #6
0
    def test_team_with_initial_teams_has_them(self):
        target_org = mock_org('target-org',
                              team_names=['Read', 'Write', 'Admin'])

        read = mock_team('Read', target_org.login())
        write = mock_team('Write', target_org.login())
        admin = mock_team('Admin', target_org.login())

        org_teams = target_org.teams()
        assert org_teams == [read, write, admin]

        for actual_team in org_teams:
            assert actual_team.repositories() == []
        assert read.members() == []
コード例 #7
0
def git_client():
    mocked_client = mock.Mock(spec=GitHub)
    iron_man = mock_user('Iron Man')
    professor_hulk = mock_user('Professor Hulk')

    mocked_client.me.return_value = iron_man.raw_object()

    training_org = mock_org('training',
                            3,
                            owner=iron_man.login(),
                            team_names=['read'])
    tools_org = mock_org('tools',
                         5,
                         owner=iron_man.login(),
                         team_names=['read', 'write'])
    lab_org = mock_org('lab',
                       2,
                       owner=professor_hulk.login(),
                       team_names=['doctors', 'not-doctors'])

    all_orgs = {org.login(): org for org in [training_org, tools_org, lab_org]}
    mocked_client.organizations.return_value = [
        mocked_org.raw_object() for mocked_org in all_orgs.values()
    ]

    all_repositories = []
    for org in [training_org, tools_org, lab_org]:
        all_repositories += org.repositories()

    mocked_client.repositories.return_value = [
        repo.raw_object() for repo in all_repositories
    ]

    mocked_client.organization.side_effect = lambda org_login: all_orgs.get(
        org_login, mock_org('Not an org')).raw_object()

    return GitClient(mocked_client)
コード例 #8
0
    def test_initial_org_has_no_teams(self):
        target_org = mock_org('target-org')

        assert target_org.teams() == []
        assert target_org.team('Any Name') is None