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)
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')
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)
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)
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)
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'])
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)
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
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)
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)
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)
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)
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)
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)
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)
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
def test_base(self): pull = GithubPullRequest(self.model) expected = '55a0965a0af4165058b17ebd0951fa483e8043c8' assert expected == pull.base
def test_clone_url(self): pull = GithubPullRequest(self.model) expected = 'https://github.com/contributor/lint-test.git' assert expected == pull.clone_url
def test_base_repo_url(self): pull = GithubPullRequest(self.model) expected = 'https://github.com/markstory/lint-test.git' assert expected == pull.base_repo_url
def test_number(self): pull = GithubPullRequest(self.model) assert 1 == pull.number
def test_head(self): pull = GithubPullRequest(self.model) expected = '53cb70abadcb3237dcb2aa2b1f24dcf7bcc7d68e' assert expected == pull.head
def test_is_private(self): pull = GithubPullRequest(self.model) assert False is pull.is_private
def test_display_name(self): pull = GithubPullRequest(self.model) assert 'markstory/lint-test/pull/1' == pull.display_name
def test_head(self): pull = GithubPullRequest(self.model) expected = 'a840e46033fab78c30fccb31d4d58dd0a8160d40' assert expected == pull.head
def test_target_branch(self): pull = GithubPullRequest(self.model) assert 'master' == pull.target_branch
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
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')