<commit_before>import pytest

from github3 import GitHubError
from github3.orgs import Organization

from .helper import UnitHelper, UnitIteratorHelper


def url_for(path=''):
    """Simple function to generate URLs with the base Org URL."""
    if path:
        path = '/' + path.strip('/')
    return 'https://api.github.com/orgs/hapy' + path


class TestOrganization(UnitHelper):
    described_class = Organization
    example_data = {
        'login': 'hapy',
        'id': 1,
        'url': 'https://api.github.com/orgs/hapy',
        'avatar_url': 'https://github.com/images/error/octocat_happy.gif',
        'name': 'github',
        'company': 'GitHub',
        'blog': 'https://github.com/blog',
        'location': 'San Francisco',
        'email': '<EMAIL>',
        'public_repos': 2,
        'public_gists': 1,
        'followers': 20,
        'following': 0,
        'html_url': 'https://github.com/hapy',
        'created_at': '2008-01-14T04:33:35Z',
        'type': 'Organization'
    }

    def test_add_member(self):
        """Show that an authenticated user can add a member to an org."""
        self.instance.add_member('user', 10)

        self.session.put.assert_called_once_with(
            'https://api.github.com/teams/10/members/user'
        )

    def test_add_repository(self):
        """Show that one can add a repository to an organization."""
        self.instance.add_repository('name-of-repo', 10)

        self.session.put.assert_called_once_with(
            'https://api.github.com/teams/10/repos/name-of-repo'
        )

    def test_create_repository(self):
        """Show that one can create a repository in an organization."""
        self.instance.create_repository('repo-name', 'description', team_id=1)

        self.post_called_with(
            url_for('repos'),
            data={
                'name': 'repo-name',
                'description': 'description',
                'homepage': '',
                'private': False,
                'has_issues': True,
                'has_wiki': True,
                'auto_init': False,
                'team_id': 1,
                'gitignore_template': '',
                'license_template': ''
            }
        )

    def test_create_repository_requires_auth(self):
        """Show that one must be authenticated to create a repo for an org."""
        self.session.has_auth.return_value = False

        with pytest.raises(GitHubError):
            self.instance.create_repository('foo')

    def test_remove_repository(self):
        """Show that one can remove a repository from a team."""
        self.instance.remove_repository('repo-name', 10)

        self.session.delete.assert_called_once_with(
            'https://api.github.com/teams/10/repos/repo-name'
        )

    def test_remove_repository_requires_positive_team_id(self):
        """Show that remove_repository requires a team_id greater than 0."""
        assert self.instance.remove_repository('name', -1) is False

        assert self.session.delete.called is False

    def test_remove_repository_requires_auth(self):
        """Show that a user must be authenticated to remove a repository."""
        self.session.has_auth.return_value = False

        with pytest.raises(GitHubError):
            self.instance.remove_repository('repo-name', 10)


class TestOrganizationRequiresAuth(UnitHelper):
    described_class = Organization
    example_data = {
        'login': 'hapy',
        'id': 1,
        'url': 'https://api.github.com/orgs/hapy',
        'avatar_url': 'https://github.com/images/error/octocat_happy.gif',
        'name': 'github',
        'company': 'GitHub',
        'blog': 'https://github.com/blog',
        'location': 'San Francisco',
        'email': '<EMAIL>',
        'public_repos': 2,
        'public_gists': 1,
        'followers': 20,
        'following': 0,
        'html_url': 'https://github.com/hapy',
        'created_at': '2008-01-14T04:33:35Z',
        'type': 'Organization'
    }

    def setUp(self):
        """Set MockedSession#has_auth.return_value to False."""
        super(TestOrganizationIterator, self).setUp()
        self.session.has_auth.return_value = False

    def test_add_member_requires_auth(self):
        """Show that one must be authenticated to add a member to an org."""
        with pytest.raises(GitHubError):
            self.instance.add_member('user', 10)

    def test_add_repository_requires_auth(self):
        """Show that one must be authenticated to add a repo to an org."""
        with pytest.raises(GitHubError):
            self.instance.add_repository('foo', 10)


class TestOrganizationIterator(UnitIteratorHelper):
    described_class = Organization

    example_data = {
        'url': url_for()
    }

    def test_events(self):
        """Show that one can iterate over an organization's events."""
        i = self.instance.events()
        self.get_next(i)

        self.session.get.assert_called_once_with(
            url_for('events'),
            params={'per_page': 100},
            headers={}
        )

    def test_members(self):
        """Show that one can iterate over all members."""
        i = self.instance.members()
        self.get_next(i)

        self.session.get.assert_called_once_with(
            url_for('members'),
            params={'per_page': 100},
            headers={}
        )
<commit_msg>Move last of requires_auth tests<commit_after>import pytest

from github3 import GitHubError
from github3.orgs import Organization

from .helper import UnitHelper, UnitIteratorHelper


def url_for(path=''):
    """Simple function to generate URLs with the base Org URL."""
    if path:
        path = '/' + path.strip('/')
    return 'https://api.github.com/orgs/hapy' + path


class TestOrganization(UnitHelper):
    described_class = Organization
    example_data = {
        'login': 'hapy',
        'id': 1,
        'url': 'https://api.github.com/orgs/hapy',
        'avatar_url': 'https://github.com/images/error/octocat_happy.gif',
        'name': 'github',
        'company': 'GitHub',
        'blog': 'https://github.com/blog',
        'location': 'San Francisco',
        'email': '<EMAIL>',
        'public_repos': 2,
        'public_gists': 1,
        'followers': 20,
        'following': 0,
        'html_url': 'https://github.com/hapy',
        'created_at': '2008-01-14T04:33:35Z',
        'type': 'Organization'
    }

    def test_add_member(self):
        """Show that an authenticated user can add a member to an org."""
        self.instance.add_member('user', 10)

        self.session.put.assert_called_once_with(
            'https://api.github.com/teams/10/members/user'
        )

    def test_add_repository(self):
        """Show that one can add a repository to an organization."""
        self.instance.add_repository('name-of-repo', 10)

        self.session.put.assert_called_once_with(
            'https://api.github.com/teams/10/repos/name-of-repo'
        )

    def test_create_repository(self):
        """Show that one can create a repository in an organization."""
        self.instance.create_repository('repo-name', 'description', team_id=1)

        self.post_called_with(
            url_for('repos'),
            data={
                'name': 'repo-name',
                'description': 'description',
                'homepage': '',
                'private': False,
                'has_issues': True,
                'has_wiki': True,
                'auto_init': False,
                'team_id': 1,
                'gitignore_template': '',
                'license_template': ''
            }
        )

    def test_remove_repository(self):
        """Show that one can remove a repository from a team."""
        self.instance.remove_repository('repo-name', 10)

        self.session.delete.assert_called_once_with(
            'https://api.github.com/teams/10/repos/repo-name'
        )

    def test_remove_repository_requires_positive_team_id(self):
        """Show that remove_repository requires a team_id greater than 0."""
        assert self.instance.remove_repository('name', -1) is False

        assert self.session.delete.called is False


class TestOrganizationRequiresAuth(UnitHelper):
    described_class = Organization
    example_data = {
        'login': 'hapy',
        'id': 1,
        'url': 'https://api.github.com/orgs/hapy',
        'avatar_url': 'https://github.com/images/error/octocat_happy.gif',
        'name': 'github',
        'company': 'GitHub',
        'blog': 'https://github.com/blog',
        'location': 'San Francisco',
        'email': '<EMAIL>',
        'public_repos': 2,
        'public_gists': 1,
        'followers': 20,
        'following': 0,
        'html_url': 'https://github.com/hapy',
        'created_at': '2008-01-14T04:33:35Z',
        'type': 'Organization'
    }

    def setUp(self):
        """Set MockedSession#has_auth.return_value to False."""
        super(TestOrganizationRequiresAuth, self).setUp()
        self.session.has_auth.return_value = False

    def test_add_member_requires_auth(self):
        """Show that one must be authenticated to add a member to an org."""
        with pytest.raises(GitHubError):
            self.instance.add_member('user', 10)

    def test_add_repository_requires_auth(self):
        """Show that one must be authenticated to add a repo to an org."""
        with pytest.raises(GitHubError):
            self.instance.add_repository('foo', 10)

    def test_create_repository_requires_auth(self):
        """Show that one must be authenticated to create a repo for an org."""
        with pytest.raises(GitHubError):
            self.instance.create_repository('foo')

    def test_remove_repository_requires_auth(self):
        """Show that a user must be authenticated to remove a repository."""
        with pytest.raises(GitHubError):
            self.instance.remove_repository('repo-name', 10)


class TestOrganizationIterator(UnitIteratorHelper):
    described_class = Organization

    example_data = {
        'url': url_for()
    }

    def test_events(self):
        """Show that one can iterate over an organization's events."""
        i = self.instance.events()
        self.get_next(i)

        self.session.get.assert_called_once_with(
            url_for('events'),
            params={'per_page': 100},
            headers={}
        )

    def test_members(self):
        """Show that one can iterate over all members."""
        i = self.instance.members()
        self.get_next(i)

        self.session.get.assert_called_once_with(
            url_for('members'),
            params={'per_page': 100},
            headers={}
        )

{'fraction_non_alphanumeric': 0.12987012987012986, 'fraction_numerical': 0.013080444735120994, 'mean_word_length': 2.3149581913905233, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 24, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5360842', 'n_tokens_mistral': 3319, 'n_tokens_neox': 3116, 'n_words': 692}