def test_get_organization_information(self):
        return_value = (
            {
                'name': 'name1',
                'description': 'desc1',
                'blog': 'blog1',
                'html_url': 'hu1',
                'created_at': 'ca1',
                'updated_at': 'ua1',
                'email': 'email1',
                'location': 'loc1',
                'login': '******',
                'public_repos': 'pr1',
            },
            requests.codes.OK,
        )

        ghapi = mock.MagicMock()
        ghapi.get_public_organization = mock.MagicMock(
            return_value=return_value
        )

        result = analytics.get_organization_information(ghapi, "unused")

        expected = collections.OrderedDict([
            ('Organization Name', 'name1'),
            ('Description', 'desc1'),
            ('Website', 'blog1'),
            ('Github URL', 'hu1'),
            ('Created', 'ca1'),
            ('Last Updated', 'ua1'),
            ('Email Address', 'email1'),
            ('Location', 'loc1'),
            ('Username', 'test1'),
            ('# of Public Repositories', 'pr1'),
        ])

        self.assertEqual(result, expected)
Exemple #2
0
def organization(ghapi, *args, **kwargs):
    organization = kwargs['name']
    verbose = kwargs['verbose']

    organization_info = analytics.get_organization_information(
        ghapi,
        organization
    )
    organization_repositories = analytics.get_organization_repositories(
        ghapi,
        organization
    )
    organization_members = analytics.get_organization_members(
        ghapi,
        organization
    )

    for human_readable_name, api_info in organization_info.items():
        leftpad_print(
            "{}: {}".format(human_readable_name, api_info),
            leftpad_length=0
        )

    leftpad_print("Public Members:", leftpad_length=0)

    def member_administrator(member):
        return member['Site Administrator']

    members = sorted(
        organization_members,
        key=member_administrator,
        reverse=True
    )

    member_count = len(organization_members) if verbose else CONCISE_COUNT
    members = members[:member_count]

    for member in members:
        for human_readable_name, api_info in member.items():
            leftpad_print(
                "{}: {}".format(human_readable_name, api_info),
                leftpad_length=2
            )

        leftpad_print("", leftpad_length=0)

    leftpad_print("Public Repositories:", leftpad_length=0)

    def repository_popularity(repository):
        return (
            int(repository['Watchers']) +
            int(repository['Stars']) +
            int(repository['Forks'])
        )

    repositories = sorted(
        organization_repositories,
        key=repository_popularity,
        reverse=True
    )
    repository_count = len(organization_repositories) if verbose else CONCISE_COUNT
    repositories = repositories[:repository_count]

    for repository in repositories:
        for human_readable_name, api_info in repository.items():
            leftpad_print(
                "{}: {}".format(human_readable_name, api_info),
                leftpad_length=2
            )

        leftpad_print("", leftpad_length=0)