Exemplo n.º 1
0
    def test_comment(self):
        """
        Adds a comment to a test issue and verifies the comment is added.
        TODO(LB): need to change the test setup so we're mocking the github 
        stuff for this (or else the tests run as slow as Chris's Mom).
        """

        class Comment(object):
            def __init__(self, dictionary):
                self.__dict__ = dictionary

        client = StubbedGithub(config=self.config, conn_class=FakeGithub)
        client.config["github"]["core_team"] = "test team 1"
        pull_request = client.pull_requests.values()[0]

        test_issue_id = 12345
        comment_text = u"test comment text"

        # add the comment
        self.expect(utils.load(utils.testdata("comment.json")))
        comment_result = pull_request.comment(comment_text)

        # now verify the comment was added
        self.expect([Comment(x) for x in utils.load(utils.testdata("comments.json"))["comments"]])
        comments = self.client.github.issues.comments(self.config["github"]["repo"], test_issue_id)

        # filter the comments list by id
        comment = [x for x in comments if x.id == comment_result["id"]]

        # should only be one comment here
        self.assertTrue(len(comment) == 1)
        comment = comment[0]

        self.assertEqual(comment_text, comment.body)
Exemplo n.º 2
0
    def test_reject(self):
        class Issue(object):
            def __init__(self, dictionary):
                self.__dict__ = dictionary

        def _get_issue(issue_id):
            return self.client.github.issues.show(self.config["github"]["repo"], issue_id)

        test_pr_id = 1
        reject_message = u"Merge failed"

        # TODO(LB): temporary -- repoen the pull request for this test
        # Remove this line once github mocking is in place
        self.expect(Issue(utils.load(utils.testdata("issue_open.json"))["issue"]))
        self.client.github.issues.reopen(self.config["github"]["repo"], test_pr_id)
        # verify the issue is open
        issue = _get_issue(test_pr_id)
        self.assertEqual(u"open", issue.state)

        # TODO(LB): need to mock up github here as well; see test_comment()
        client = StubbedGithub(config=self.config, conn_class=FakeGithub)
        client.config.github_core_team = "test team 1"
        pull_request = client.pull_requests.values()[0]

        self.expect(Issue(utils.load(utils.testdata("issue_closed.json"))["issue"]))
        rejected_issue = pull_request.close(reject_message)
        self.assertEqual(u"closed", rejected_issue.state)
Exemplo n.º 3
0
    def test_create_a_new_pull_request(self):
        pr_str = utils.load(utils.testdata('new_pull_request.json'))
        pr = pull_request.PullRequest(pr_str, self.pr_path)

        self.assertNothingRaised(pr.save,)
        self.assertTrue(os.path.exists(os.path.join(self.pr_path, "2", "pull.js")))
        pr2 = pull_request.PullRequest.load(os.path.join(self.pr_path, "2"))
        self.assertEqual(pr._pull_request, pr2._pull_request)
Exemplo n.º 4
0
 def test_issue_137(self):
     """
     GitHub sometimes returns `pull` as part of of the `html_url` for Issue
     requests.
     """
     i = Issue(load('issue_137'))
     self.assertEqual(i.html_url,
                      "https://github.com/sigmavirus24/github3.py/pull/1")
     self.assertEqual(i.repository, ("sigmavirus24", "github3.py"))
Exemplo n.º 5
0
    def test_delete_key(self):
        self.request.return_value = generate_response(None, 204)

        self.login()
        with patch.object(github3.github.GitHub, 'key') as key:
            key.return_value = github3.users.Key(load('key'), self.g)
            assert self.g.delete_key(10) is True

        assert self.request.called is True
    def test_iter_issue_comments(self):
        pull = github3.pulls.PullRequest(load('pull19'))
        self.response('pull19_comment', _iter=True)
        self.get(pull.links['comments'])

        c = next(pull.iter_issue_comments())
        assert isinstance(c, github3.issues.comment.IssueComment)
        self.mock_assertions()

        assert repr(c).startswith('<Issue Comment')
Exemplo n.º 7
0
    def test_iter_issue_comments(self):
        pull = github3.pulls.PullRequest(load('pull19'))
        self.response('pull19_comment', _iter=True)
        self.get(pull.links['comments'])

        c = next(pull.iter_issue_comments())
        assert isinstance(c, github3.issues.comment.IssueComment)
        self.mock_assertions()

        assert repr(c).startswith('<Issue Comment')
Exemplo n.º 8
0
 def test_issue_137(self):
     """
     GitHub sometimes returns `pull` as part of of the `html_url` for Issue
     requests.
     """
     i = Issue(load('issue_137'))
     self.assertEqual(
         i.html_url,
         "https://github.com/sigmavirus24/github3.py/pull/1")
     self.assertEqual(i.repository, ("sigmavirus24", "github3.py"))
Exemplo n.º 9
0
    def test_delete_key(self):
        self.response(None, 204)

        self.login()
        with patch.object(github3.github.GitHub, 'key') as key:
            key.return_value = github3.users.Key(load('key'), self.g)
            assert self.g.delete_key(10) is True
            key.return_value = None
            assert self.g.delete_key(10) is False

        assert self.request.called is True
Exemplo n.º 10
0
    def test_issue(self):
        self.response('issue', 200)
        self.get('https://api.github.com/repos/sigmavirus24/github3.py/'
                 'issues/1')

        assert self.g.issue(None, None, 0) is None
        with patch.object(github3.github.GitHub, 'repository') as repo:
            repo.return_value = github3.repos.Repository(load('repo'))
            i = self.g.issue('user', 'repo', 1)

        expect(i).isinstance(github3.issues.Issue)
        self.mock_assertions()
Exemplo n.º 11
0
    def test_iter_repo_issues(self):
        self.response('issue', _iter=True)
        self.get('https://api.github.com/repos/sigmavirus24/github3.py/'
                 'issues')

        with patch.object(github3.GitHub, 'repository') as repo:
            repo.return_value = github3.repos.Repository(load('repo'),
                                                         self.g)
            i = next(self.g.iter_repo_issues('sigmavirus24', 'github3.py'))

        expect(i).isinstance(github3.issues.Issue)
        self.mock_assertions()
Exemplo n.º 12
0
    def test_issue(self):
        self.response('issue', 200)
        self.get('https://api.github.com/repos/sigmavirus24/github3.py/'
                 'issues/1')

        assert self.g.issue(None, None, 0) is None
        with patch.object(github3.github.GitHub, 'repository') as repo:
            repo.return_value = github3.repos.Repository(load('repo'))
            i = self.g.issue('user', 'repo', 1)

        expect(i).isinstance(github3.issues.Issue)
        self.mock_assertions()
Exemplo n.º 13
0
    def test_update_user(self):
        self.login()
        args = ('Ian Cordasco', '*****@*****.**', 'www.blog.com', 'company',
                'loc', True, 'bio')

        with patch.object(github3.github.GitHub, 'user') as user:
            with patch.object(github3.users.User, 'update') as upd:
                user.return_value = github3.users.User(load('user'), self.g)
                upd.return_value = True
                expect(self.g.update_user(*args)).is_True()
                expect(user.called).is_True()
                expect(upd.called).is_True()
                upd.assert_called_with(*args)
Exemplo n.º 14
0
    def test_pull_request(self):
        self.response('pull')
        self.get('https://api.github.com/repos/sigmavirus24/'
                 'github3.py/pulls/18')
        pr = None

        with patch.object(github3.github.GitHub, 'repository') as repo:
            repo.return_value = github3.repos.Repository(load('repo'))
            pr = self.g.pull_request('sigmavirus24', 'github3.py', 18)

        expect(pr).isinstance(github3.pulls.PullRequest)

        self.mock_assertions()
Exemplo n.º 15
0
    def test_pull_request(self):
        self.response('pull')
        self.get('https://api.github.com/repos/sigmavirus24/'
                 'github3.py/pulls/18')
        pr = None

        with patch.object(github3.github.GitHub, 'repository') as repo:
            repo.return_value = github3.repos.Repository(load('repo'))
            pr = self.g.pull_request('sigmavirus24', 'github3.py', 18)

        expect(pr).isinstance(github3.pulls.PullRequest)

        self.mock_assertions()
Exemplo n.º 16
0
    def test_update_user(self):
        self.login()
        args = ('Ian Cordasco', '*****@*****.**', 'www.blog.com', 'company',
                'loc', True, 'bio')

        with patch.object(github3.github.GitHub, 'user') as user:
            with patch.object(github3.users.User, 'update') as upd:
                user.return_value = github3.users.User(load('user'), self.g)
                upd.return_value = True
                expect(self.g.update_user(*args)).is_True()
                expect(user.called).is_True()
                expect(upd.called).is_True()
                upd.assert_called_with(*args)
Exemplo n.º 17
0
    def test_iter_repo_issues(self):
        self.response('issue', _iter=True)
        self.get('https://api.github.com/repos/sigmavirus24/github3.py/'
                 'issues')

        with patch.object(github3.GitHub, 'repository') as repo:
            repo.return_value = github3.repos.Repository(load('repo'), self.g)
            i = next(self.g.iter_repo_issues('sigmavirus24', 'github3.py'))

        expect(i).isinstance(github3.issues.Issue)
        self.mock_assertions()

        with expect.raises(StopIteration):
            next(self.g.iter_repo_issues(None, None))
Exemplo n.º 18
0
    def test_iter_starred(self):
        self.response('repo', _iter=True)
        self.get('https://api.github.com/user/starred')
        self.conf.update(params={})

        self.login()
        expect(next(self.g.iter_starred())).isinstance(
            github3.repos.Repository)
        self.mock_assertions()

        with patch.object(github3.github.GitHub, 'user') as user:
            user.return_value = github3.users.User(load('user'))
            self.get('https://api.github.com/users/sigmavirus24/starred')
            expect(next(self.g.iter_starred('sigmavirus24'))).isinstance(
                github3.repos.Repository)
            self.mock_assertions()
Exemplo n.º 19
0
    def test_iter_starred(self):
        self.response('repo', _iter=True)
        self.get('https://api.github.com/user/starred')
        self.conf.update(params={})

        self.login()
        expect(next(self.g.iter_starred())).isinstance(
            github3.repos.Repository)
        self.mock_assertions()

        with patch.object(github3.github.GitHub, 'user') as user:
            user.return_value = github3.users.User(load('user'))
            self.get('https://api.github.com/users/sigmavirus24/starred')
            expect(next(self.g.iter_starred('sigmavirus24'))).isinstance(
                github3.repos.Repository)
            self.mock_assertions()
Exemplo n.º 20
0
    def test_iter_subscriptions(self):
        self.response('repo', _iter=True)
        self.get('https://api.github.com/user/subscriptions')
        self.conf.update(params={'per_page': 100})

        self.login()
        assert isinstance(next(self.g.iter_subscriptions()),
                          github3.repos.Repository)
        self.mock_assertions()

        with patch.object(github3.github.GitHub, 'user') as user:
            user.return_value = github3.users.User(load('user'))
            self.get('https://api.github.com/users/sigmavirus24/'
                     'subscriptions')
            assert isinstance(next(self.g.iter_subscriptions('sigmavirus24')),
                              github3.repos.Repository)
            self.mock_assertions()
Exemplo n.º 21
0
    def test_create_issue(self):
        self.response('issue', 201)

        self.login()
        i = self.g.create_issue(None, None, None)
        assert i is None
        assert self.request.called is False

        i = self.g.create_issue('user', 'repo', '')
        assert i is None
        assert self.request.called is False

        with patch.object(github3.GitHub, 'repository') as repo:
            repo.return_value = github3.repos.Repository(load('repo'), self.g)
            i = self.g.create_issue('user', 'repo', 'Title')

        expect(i).isinstance(github3.issues.Issue)
        assert self.request.called is True
Exemplo n.º 22
0
    def test_iter_subscriptions(self):
        self.request.return_value = generate_response('repo', _iter=True)
        self.args = ('GET', 'https://api.github.com/user/subscriptions')
        self.conf.update(params=None)

        self.login()
        expect(next(self.g.iter_subscriptions())).isinstance(
            github3.repos.Repository)
        self.mock_assertions()

        with patch.object(github3.github.GitHub, 'user') as user:
            user.return_value = github3.users.User(load('user'))
            self.args = ('GET',
                         'https://api.github.com/users/sigmavirus24/'
                         'subscriptions'
                         )
            expect(next(self.g.iter_subscriptions('sigmavirus24'))).isinstance(
                github3.repos.Repository)
            self.mock_assertions()
Exemplo n.º 23
0
    def test_create_issue(self):
        self.response('issue', 201)

        self.login()
        i = self.g.create_issue(None, None, None)
        assert i is None
        assert self.request.called is False

        i = self.g.create_issue('user', 'repo', '')
        assert i is None
        assert self.request.called is False

        with patch.object(github3.GitHub, 'repository') as repo:
            repo.return_value = github3.repos.Repository(
                load('repo'), self.g)
            i = self.g.create_issue('user', 'repo', 'Title')

        expect(i).isinstance(github3.issues.Issue)
        assert self.request.called is True
Exemplo n.º 24
0
    def test_update_label(self):
        self.response('label')
        self.patch(self.api + 'labels/Bug')
        self.conf = {'data': {'name': 'big_bug', 'color': 'fafafa'}}

        self.assertRaises(github3.GitHubError, self.repo.update_label, 'foo', 'bar')
        self.not_called()

        self.login()
        with patch.object(repos.Repository, 'label') as l:
            l.return_value = None
            assert self.repo.update_label('foo', 'bar') is False
            self.not_called()

        with patch.object(repos.Repository, 'label') as l:
            l.return_value = github3.issues.label.Label(load('label'), self.g)
            assert self.repo.update_label('big_bug', 'fafafa')

        self.mock_assertions()
Exemplo n.º 25
0
    def test_iter_following(self):
        self.response('user', _iter=True)
        self.get('https://api.github.com/users/sigmavirus24/following')
        self.conf.update(params={'per_page': 100})

        self.assertRaises(github3.GitHubError, self.g.iter_following)
        assert self.request.called is False

        with patch.object(github3.github.GitHub, 'user') as ghuser:
            ghuser.return_value = github3.users.User(load('user'))
            u = next(self.g.iter_following('sigmavirus24'))
            assert isinstance(u, github3.users.User)
            self.mock_assertions()

            self.login()
            v = next(self.g.iter_following())
            assert isinstance(v, github3.users.User)
            self.get('https://api.github.com/user/following')
            self.mock_assertions()
Exemplo n.º 26
0
    def test_update_label(self):
        self.response('label', 200)
        self.patch(self.api + 'labels/bug')
        self.conf = {'data': {'name': 'big_bug', 'color': 'fafafa'}}

        with expect.githuberror():
            self.repo.update_label('foo', 'bar')
        self.not_called()

        self.login()
        with patch.object(github3.repos.Repository, 'label') as l:
            l.return_value = None
            expect(self.repo.update_label('foo', 'bar')).is_False()
            self.not_called()

        with patch.object(github3.repos.Repository, 'label') as l:
            l.return_value = github3.issues.Label(load('label'), self.g)
            expect(self.repo.update_label('big_bug', 'fafafa')).is_True()

        self.mock_assertions()
Exemplo n.º 27
0
    def test_iter_following(self):
        self.response('user', _iter=True)
        self.get('https://api.github.com/users/sigmavirus24/following')
        self.conf.update(params=None)

        with expect.githuberror():
            next(self.g.iter_following())
        assert self.request.called is False

        with patch.object(github3.github.GitHub, 'user') as ghuser:
            ghuser.return_value = github3.users.User(load('user'))
            u = next(self.g.iter_following('sigmavirus24'))
            expect(u).isinstance(github3.users.User)
            self.mock_assertions()

            self.login()
            v = next(self.g.iter_following())
            expect(v).isinstance(github3.users.User)
            self.get('https://api.github.com/user/following')
            self.mock_assertions()
Exemplo n.º 28
0
    def test_update_label(self):
        self.response('label')
        self.patch(self.api + 'labels/bug')
        self.conf = {'data': {'name': 'big_bug', 'color': 'fafafa'}}

        with expect.githuberror():
            self.repo.update_label('foo', 'bar')
        self.not_called()

        self.login()
        with patch.object(repos.Repository, 'label') as l:
            l.return_value = None
            expect(self.repo.update_label('foo', 'bar')).is_False()
            self.not_called()

        with patch.object(repos.Repository, 'label') as l:
            l.return_value = github3.issues.label.Label(load('label'), self.g)
            expect(self.repo.update_label('big_bug', 'fafafa')).is_True()

        self.mock_assertions()
Exemplo n.º 29
0
    def test_update_label(self):
        self.response('label')
        self.patch(self.api + 'labels/Bug')
        self.conf = {'data': {'name': 'big_bug', 'color': 'fafafa'}}

        self.assertRaises(github3.GitHubError, self.repo.update_label, 'foo',
                          'bar')
        self.not_called()

        self.login()
        with mock.patch.object(repos.Repository, 'label') as l:
            l.return_value = None
            assert self.repo.update_label('foo', 'bar') is False
            self.not_called()

        with mock.patch.object(repos.Repository, 'label') as l:
            l.return_value = github3.issues.label.Label(load('label'), self.g)
            assert self.repo.update_label('big_bug', 'fafafa')

        self.mock_assertions()
Exemplo n.º 30
0
    def test_iter_following(self):
        self.response('user', _iter=True)
        self.get('https://api.github.com/users/sigmavirus24/following')
        self.conf.update(params=None)

        with expect.githuberror():
            next(self.g.iter_following())
        assert self.request.called is False

        with patch.object(github3.github.GitHub, 'user') as ghuser:
            ghuser.return_value = github3.users.User(load('user'))
            u = next(self.g.iter_following('sigmavirus24'))
            expect(u).isinstance(github3.users.User)
            self.mock_assertions()

            self.login()
            v = next(self.g.iter_following())
            expect(v).isinstance(github3.users.User)
            self.get('https://api.github.com/user/following')
            self.mock_assertions()
Exemplo n.º 31
0
 def __init__(self, methodName='runTest'):
     super(TestGist, self).__init__(methodName)
     self.gist = gists.Gist(load('gist'))
     self.api = 'https://api.github.com/gists/3813862'
Exemplo n.º 32
0
 def test_enterprise(self):
     Issue(load('issue_enterprise'))
Exemplo n.º 33
0
 def test_pull_request_issues(self):
     pr = github3.pulls.PullRequest(load('pull_request'))
     self.assertEqual(
         pr.issue_url,
         'https://github.com/sigmavirus24/github3.py/pull/135')
Exemplo n.º 34
0
 def __init__(self, methodName='runTest'):
     super(TestTeam, self).__init__(methodName)
     self.team = github3.orgs.Team(load('team'))
     self.api = "https://api.github.com/teams/190009"
Exemplo n.º 35
0
 def test_equality(self):
     t = github3.orgs.Team(load('team'))
     assert self.team == t
     t.id = 'foo'
     assert self.team != t
Exemplo n.º 36
0
 def __init__(self, methodName='runTest'):
     super(TestLabel, self).__init__(methodName)
     self.l = github3.issues.Label(load('label'))
     self.api = ("https://api.github.com/repos/sigmavirus24/github3.py/"
                 "labels/bug")
Exemplo n.º 37
0
 def test_equality(self):
     a = github3.auths.Authorization(load('authorization'))
     expect(self.auth) == a
     a.id = 1
     expect(self.auth) != a
Exemplo n.º 38
0
 def __init__(self, methodName='runTest'):
     super(TestMilestone, self).__init__(methodName)
     self.m = Milestone(load('milestone'))
     self.api = ("https://api.github.com/repos/kennethreitz/requests/"
                 "milestones/18")
Exemplo n.º 39
0
 def test_equality(self):
     e = IssueEvent(load('issue_event'))
     assert self.ev == e
     e._uniq = 'fake'
     assert self.ev != e
Exemplo n.º 40
0
 def setUp(self):
     super(TestIssueEvent, self).setUp()
     self.ev = IssueEvent(load('issue_event'))
Exemplo n.º 41
0
 def __init__(self, methodName='runTest'):
     super(TestPullRequest, self).__init__(methodName)
     self.pull = github3.pulls.PullRequest(load('pull'))
     self.api = ("https://api.github.com/repos/sigmavirus24/github3.py/"
                 "pulls/18")
Exemplo n.º 42
0
 def __init__(self, methodName='runTest'):
     super(TestIssue, self).__init__(methodName)
     self.i = github3.issues.Issue(load('issue'))
     self.api = ("https://api.github.com/repos/sigmavirus24/github3.py/"
                 "issues/1")
Exemplo n.º 43
0
 def __init__(self, methodName='runTest'):
     super(TestMilestone, self).__init__(methodName)
     self.m = github3.issues.Milestone(load('milestone'))
     self.api = ("https://api.github.com/repos/kennethreitz/requests/"
                 "milestones/18")
Exemplo n.º 44
0
 def __init__(self, methodName='runTest'):
     super(TestUser, self).__init__(methodName)
     self.user = github3.users.User(load('user'))
     self.api = "https://api.github.com/users/sigmavirus24"
Exemplo n.º 45
0
 def __init__(self, methodName='runTest'):
     super(TestOrganization, self).__init__(methodName)
     self.org = github3.orgs.Organization(load('org'))
     self.api = "https://api.github.com/orgs/github3py"
Exemplo n.º 46
0
 def test_hashing(self):
     p = github3.pulls.PullRequest(load('pull'))
     s = set()
     s.add(p)
     s.add(p)
     assert len(s) == 1
Exemplo n.º 47
0
 def test_equality(self):
     assert self.org == github3.orgs.Organization(load('org'))
Exemplo n.º 48
0
 def test_equality(self):
     p = github3.pulls.PullRequest(load('pull'))
     assert self.pull == p
     p._uniq = 'foo'
     assert self.pull != p
Exemplo n.º 49
0
 def __init__(self, methodName='runTest'):
     super(TestRepository, self).__init__(methodName)
     self.repo = github3.repos.Repository(load('repo'))
Exemplo n.º 50
0
 def __init__(self, methodName='runTest'):
     super(TestLabel, self).__init__(methodName)
     self.l = Label(load('label'))
     self.api = ("https://api.github.com/repos/sigmavirus24/github3.py/"
                 "labels/Bug")
Exemplo n.º 51
0
 def test_equality(self):
     i = Issue(load('issue'))
     assert self.i == i
     i._uniq = 1
     assert self.i != i
Exemplo n.º 52
0
 def test_equality(self):
     h = gists.history.GistHistory(load('gist_history'))
     expect(self.hist) == h
     h.version = 'foo'
     expect(self.hist) != h
Exemplo n.º 53
0
 def __init__(self, methodName='runTest'):
     super(TestIssue, self).__init__(methodName)
     self.i = Issue(load('issue'))
     self.api = ("https://api.github.com/repos/sigmavirus24/github3.py/"
                 "issues/1")
Exemplo n.º 54
0
 def test_equality(self):
     l = Label(load('label'))
     assert self.l == l
     l._uniq = ("https://api.github.com/repos/sigmavirus24/github3.py/"
                "labels/wontfix")
     assert self.l != l
Exemplo n.º 55
0
 def __init__(self, methodName='runTest'):
     super(TestKey, self).__init__(methodName)
     self.key = github3.users.Key(load('key'))
     self.api = "https://api.github.com/user/keys/10"
Exemplo n.º 56
0
 def test_enterprise(self):
     github3.pulls.PullRequest(load('pull_enterprise'))
Exemplo n.º 57
0
 def __init__(self, methodName='runTest'):
     super(TestAuthorization, self).__init__(methodName)
     self.auth = github3.auths.Authorization(load('authorization'))
     self.api = "https://api.github.com/authorizations/10"
Exemplo n.º 58
0
 def test_equality(self):
     u = github3.users.User(load('user'))
     assert self.user == u
     u._uniq += 1
     assert self.user != u