Example #1
0
    def test_remove_label__label_exists(self):
        pull = GithubPullRequest(self.model)
        label_name = 'No lint errors'
        with add_ok_label(pull, label_name):
            pull.remove_label(label_name)

            pull.pull.issue().remove_label.assert_called_with(label_name)
Example #2
0
    def test_create_comment(self):
        self.model.review_comments = Mock()
        pull = GithubPullRequest(self.model)

        pull.review_comments(text)
        ok_(self.model.review_comments.called,
               'Method should delegate')
Example #3
0
    def test_create_comment(self):
        self.model.create_comment = Mock()
        pull = GithubPullRequest(self.model)

        text = 'No lint errors found'
        pull.create_comment(text)
        self.model.create_comment.assert_called_with(text)
Example #4
0
    def test_remove_label__label_exists(self):
        pull = GithubPullRequest(self.model)
        label_name = 'No lint errors'
        with add_ok_label(pull, label_name):
            pull.remove_label(label_name)

            pull.pull.issue().remove_label.assert_called_with(label_name)
Example #5
0
    def test_create_comment(self):
        self.model.create_comment = Mock()
        pull = GithubPullRequest(self.model)

        text = 'No lint errors found'
        pull.create_comment(text)
        self.model.create_comment.assert_called_with(text)
Example #6
0
    def test_maintainer_can_modify__same_repo(self):
        pull = GithubPullRequest(self.model)
        self.assertEqual(True, pull.maintainer_can_modify)

        fixture = load_fixture('pull_request.json')
        data = json.loads(fixture)
        data['maintainer_can_modify'] = False

        model = PullRequest(data, self.session)
        pull = GithubPullRequest(model)
        self.assertEqual(True, pull.maintainer_can_modify)
Example #7
0
    def test_maintainer_can_modify__same_repo(self):
        pull = GithubPullRequest(self.model)
        eq_(True, pull.maintainer_can_modify)

        fixture = load_fixture('pull_request.json')
        data = json.loads(fixture)['pull_request']
        data['maintainer_can_modify'] = False

        model = PullRequest(data)
        pull = GithubPullRequest(model)
        eq_(True, pull.maintainer_can_modify)
Example #8
0
    def test_create_review_comment(self):
        self.model.create_review_comment = Mock()
        pull = GithubPullRequest(self.model)

        comment = {
            'body': 'bad whitespace',
            'commit_id': 'abc123',
            'path': 'some/file.php',
            'position': 12
        }
        pull.create_review_comment(**comment)
        self.model.create_review_comment.assert_called_with(
            comment['body'], comment['commit_id'], comment['path'],
            comment['position'])
Example #9
0
    def test_create_review_comment(self):
        self.model.create_review_comment = Mock()
        pull = GithubPullRequest(self.model)

        comment = {
            'body': 'bad whitespace',
            'commit_id': 'abc123',
            'path': 'some/file.php',
            'position': 12
        }
        pull.create_review_comment(**comment)
        self.model.create_review_comment.assert_called_with(
            comment['body'],
            comment['commit_id'],
            comment['path'],
            comment['position'])
Example #10
0
    def test_clone_url__private_fork__not_a_fork(self):
        fixture = load_fixture('pull_request.json')
        data = json.loads(fixture)

        pull = GithubPullRequest(PullRequest(data, self.session))
        self.assertEqual(False, pull.from_private_fork)
        self.assertEqual(data['head']['repo']['clone_url'], pull.clone_url)
        self.assertEqual('test', pull.head_branch)
Example #11
0
 def test_create_review(self):
     self.model._post = Mock()
     self.model._json = Mock()
     pull = GithubPullRequest(self.model)
     review = {
         'commit_id': 'abc123',
         'event': 'COMMENT',
         'body': 'Bad things',
         'comments': [
             {'position': 1, 'body': 'Bad space', 'path': 'some/file.php'}
         ]
     }
     pull.create_review(review)
     self.model._post.assert_called_with(
         'https://api.github.com/repos/markstory/lint-test/pulls/1/reviews',
         data=review)
     assert self.model._json.called
Example #12
0
    def test_clone_url__private_fork__not_a_fork(self):
        fixture = load_fixture('pull_request.json')
        data = json.loads(fixture)['pull_request']

        pull = GithubPullRequest(PullRequest(data))
        eq_(False, pull.from_private_fork)
        eq_(data['head']['repo']['clone_url'], pull.clone_url)
        eq_('test', pull.head_branch)
Example #13
0
    def get_pull_request(self):
        fixture = load_fixture('pull_request.json')
        model = PullRequest.from_json(fixture, self.session)

        files = load_fixture('one_file_pull_request.json')
        model.files = lambda: create_pull_files(files)

        return GithubPullRequest(model)
Example #14
0
    def get_pull_request(self):
        fixture = load_fixture('pull_request.json')
        model = PullRequest(json.loads(fixture)['pull_request'])

        files = load_fixture('one_file_pull_request.json')
        model.files = lambda: create_pull_files(files)

        return GithubPullRequest(model)
Example #15
0
    def test_maintainer_can_modify__forked_repo(self):
        fixture = load_fixture('pull_request.json')
        data = json.loads(fixture)['pull_request']

        # Make repo different
        data['head']['repo']['full_name'] = 'contributor/lint-test'
        pull = GithubPullRequest(PullRequest(data))
        eq_(True, pull.maintainer_can_modify, 'reflects flag')

        # Different repo reflects flag data
        data['maintainer_can_modify'] = False
        pull = GithubPullRequest(PullRequest(data))
        eq_(False, pull.maintainer_can_modify)

        data['maintainer_can_modify'] = True
        pull = GithubPullRequest(PullRequest(data))
        eq_(True, pull.maintainer_can_modify)
Example #16
0
    def test_clone_url__private_fork__forked(self):
        fixture = load_fixture('pull_request.json')
        data = json.loads(fixture)['pull_request']

        data['head']['repo']['full_name'] = 'contributor/lint-test'
        data['head']['repo']['fork'] = True

        pull = GithubPullRequest(PullRequest(data))
        eq_(False, pull.from_private_fork)
Example #17
0
    def get_pull_request(self):
        fixture = load_fixture('pull_request.json')
        model = PullRequest.from_json(fixture, self.session)

        # TODO This needs to be adapted for local diffs
        # Perhaps pull.read_diff can be added and mocked
        # here?
        files = load_fixture('one_file_pull_request.json')
        model.files = lambda: create_pull_files(files)

        return GithubPullRequest(model)
Example #18
0
    def test_clone_url__private_fork(self):
        fixture = load_fixture('pull_request.json')
        data = json.loads(fixture)['pull_request']

        data['head']['repo']['full_name'] = 'contributor/lint-test'
        data['head']['repo']['clone_url'] = 'secret-repo'
        data['head']['repo']['fork'] = True
        data['head']['repo']['private'] = True
        pull = GithubPullRequest(PullRequest(data))
        eq_(True, pull.from_private_fork)
        eq_(data['base']['repo']['clone_url'], pull.clone_url)
        eq_('refs/pull/1/head', pull.head_branch)
Example #19
0
 def test_create_review(self):
     self.model._post = Mock()
     self.model._json = Mock()
     pull = GithubPullRequest(self.model)
     review = {
         'commit_id':
         'abc123',
         'event':
         'COMMENT',
         'body':
         'Bad things',
         'comments': [{
             'position': 1,
             'body': 'Bad space',
             'path': 'some/file.php'
         }]
     }
     pull.create_review(review)
     self.model._post.assert_called_with(
         'https://api.github.com/repos/markstory/lint-test/pulls/1/reviews',
         data=review)
     assert self.model._json.called
Example #20
0
 def test_base(self):
     pull = GithubPullRequest(self.model)
     expected = '55a0965a0af4165058b17ebd0951fa483e8043c8'
     assert expected == pull.base
Example #21
0
 def test_clone_url(self):
     pull = GithubPullRequest(self.model)
     expected = 'https://github.com/contributor/lint-test.git'
     assert expected == pull.clone_url
Example #22
0
 def test_base_repo_url(self):
     pull = GithubPullRequest(self.model)
     expected = 'https://github.com/markstory/lint-test.git'
     assert expected == pull.base_repo_url
Example #23
0
 def test_number(self):
     pull = GithubPullRequest(self.model)
     assert 1 == pull.number
Example #24
0
 def test_head(self):
     pull = GithubPullRequest(self.model)
     expected = '53cb70abadcb3237dcb2aa2b1f24dcf7bcc7d68e'
     assert expected == pull.head
Example #25
0
 def test_is_private(self):
     pull = GithubPullRequest(self.model)
     assert False is pull.is_private
Example #26
0
 def test_display_name(self):
     pull = GithubPullRequest(self.model)
     assert 'markstory/lint-test/pull/1' == pull.display_name
Example #27
0
 def test_head(self):
     pull = GithubPullRequest(self.model)
     expected = 'a840e46033fab78c30fccb31d4d58dd0a8160d40'
     assert expected == pull.head
Example #28
0
    def test_create_comment(self):
        self.model.review_comments = Mock()
        pull = GithubPullRequest(self.model)

        pull.review_comments(text)
        ok_(self.model.review_comments.called, 'Method should delegate')
Example #29
0
 def test_target_branch(self):
     pull = GithubPullRequest(self.model)
     assert 'master' == pull.target_branch
Example #30
0
 def test_remove_label__label_missing(self):
     pull = GithubPullRequest(self.model)
     label_name = 'No lint errors'
     with add_ok_label(pull, 'Other label'):
         pull.remove_label(label_name)
         assert 0 == pull.pull.issue().remove_label.call_count
Example #31
0
 def test_add_label(self):
     mock_issue = Mock()
     self.model.issue = lambda: mock_issue
     pull = GithubPullRequest(self.model)
     pull.add_label('No lint errors')
     mock_issue.add_labels.assert_called_with('No lint errors')
Example #32
0
 def test_add_label(self):
     mock_issue = Mock()
     self.model.issue = lambda: mock_issue
     pull = GithubPullRequest(self.model)
     pull.add_label('No lint errors')
     mock_issue.add_labels.assert_called_with('No lint errors')
Example #33
0
 def test_remove_label__label_missing(self):
     pull = GithubPullRequest(self.model)
     label_name = 'No lint errors'
     with add_ok_label(pull, 'Other label'):
         pull.remove_label(label_name)
         assert 0 == pull.pull.issue().remove_label.call_count