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)
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)
def test_clone_repo_with_bad_config(self): config = Config(config_file=utils.testdata('bad_git.cfg')) remote_name = config["test"]["remote_name"] remote_url = config["test"]["remote_url"] remote_branch = config["test"]["remote_branch"] self.assertRaises(GitException, Git, remote_name, remote_url, remote_branch, config)
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)
def test_daemon_rebind(self): d = daemon.Daemon(stdin=utils.testdata('fake'), stdout=utils.testdata('fake'), stderr=utils.testdata('fake')) old_stdin = sys.stdin old_stdout = sys.stdout old_stderr = sys.stderr with open('/tmp/testfile', 'w') as fd: sys.stdin = fd sys.stdin.close() # Test to make sure we hit IOError sys.stdout = fd sys.stderr = fd self.assertCalled(file.close, d._Daemon__rebind) sys.stdin = old_stdin sys.stdout = old_stdout sys.stderr = old_stderr
def create_test_repo(): repo_path = utils.testdata('test_repo') if not os.path.exists(repo_path): repo = git.Repo.init(repo_path, mkdir=True) with open(os.path.join(repo_path, "README"), "w") as fp: fp.write("This is just test stuff") repo.git.execute(("git", "add", "README")) repo.git.execute(("git", "commit", "-m", "Test commit")) return repo_path
def setUp(self): self.t = time.time() repo_path = create_test_repo() config = Config(config_file=utils.testdata('good_git.cfg')) config["git"]["base_repo_url"] = repo_path remote_branch = config["test"]["remote_branch"] remote_name = config["test"]["remote_name"] remote_url = repo_path self.repo = Git(remote_name=remote_name, remote_url=remote_url, remote_branch=remote_branch, config=config)
def test_pylint_runs(self): cfg = config.Config(utils.testdata('good.cfg')) p = pylint.Pylint(['tests'], config=cfg) self.assertTrue(p) cfg.update("pylint", "current_score", 1000)
def setUp(self): drivers.PROC_MOUNTS_PATH = utils.testdata("proc_mounts_with_configfs") self.configfs = configfs.ConfigFS()
def test_that_update_works(self): config = Config(config_file=utils.testdata("good.cfg")) self.assertCalled(json.dump, config.update, "pylint","max_score", 10000)
def setUp(self): self.pr_path = utils.testdata('output/pulls')
def get(self, *args): if args[0] == "pulls": if len(args) == 2: # PullRequests return utils.load(utils.testdata(self.pull_request_files[0])) elif len(args) == 3: # PullRequest return utils.load(utils.testdata(self.pull_request_files[1]))
def teams(self): return utils.load(utils.testdata("teams.json"))
def setUp(self): drivers.PROC_MOUNTS_PATH = utils.testdata("proc_mounts") self.procfs = procfs.ProcFS()
def setUp(self): drivers.PROC_MOUNTS_PATH = utils.testdata("proc_mounts") self.sysfs = sysfs.SysFS()