From 87f5b9d66bf654378d53387f70983b7191c70e96 Mon Sep 17 00:00:00 2001 From: "James E. Blair" Date: Mon, 25 Apr 2022 15:04:21 -0700 Subject: Add more files tests to Pagure driver The github and gitlab drivers were just updated to support a base_sha attribute. Pagure doesn't need this because of the way it gets its file lists from the diffstat endpoint. Update the Pagure driver with similar tests to codify this behavior. Change-Id: I87c6fe4ee0da29f3b920a343a0d759214f70b577 --- tests/base.py | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) (limited to 'tests/base.py') diff --git a/tests/base.py b/tests/base.py index c257147a1..492b012b8 100644 --- a/tests/base.py +++ b/tests/base.py @@ -1670,9 +1670,9 @@ class FakePagurePullRequest(object): return PagureChangeReference.create( repo, self.getPRReference(), 'refs/tags/init') - def addCommit(self, files={}): + def addCommit(self, files={}, delete_files=None): """Adds a commit on top of the actual PR head.""" - self._addCommitInPR(files=files) + self._addCommitInPR(files=files, delete_files=delete_files) self._updateTimeStamp() def forcePush(self, files={}): @@ -1680,7 +1680,7 @@ class FakePagurePullRequest(object): self._addCommitInPR(files=files, reset=True) self._updateTimeStamp() - def _addCommitInPR(self, files={}, reset=False): + def _addCommitInPR(self, files={}, delete_files=None, reset=False): repo = self._getRepo() ref = repo.references[self.getPRReference()] if reset: @@ -1692,7 +1692,7 @@ class FakePagurePullRequest(object): if files: self.files = files - else: + elif not delete_files: fn = '%s-%s' % (self.branch.replace('/', '_'), self.number) self.files = {fn: "test %s %s\n" % (self.branch, self.number)} msg = self.subject + '-' + str(self.number_of_commits) @@ -1702,6 +1702,13 @@ class FakePagurePullRequest(object): f.write(content) repo.index.add([fn]) + if delete_files: + for fn in delete_files: + if fn in self.files: + del self.files[fn] + fn = os.path.join(repo.working_dir, fn) + repo.index.remove([fn]) + self.commit_stop = repo.index.commit(msg).hexsha if not self.commit_start: self.commit_start = self.commit_stop @@ -2148,7 +2155,7 @@ class FakeGitlabMergeRequest(object): if files: self.files = files - else: + elif not delete_files: fn = '%s-%s' % (self.branch.replace('/', '_'), self.number) self.files = {fn: "test %s %s\n" % (self.branch, self.number)} msg = self.subject + '-' + str(self.number_of_commits) @@ -2160,6 +2167,8 @@ class FakeGitlabMergeRequest(object): if delete_files: for fn in delete_files: + if fn in self.files: + del self.files[fn] fn = os.path.join(repo.working_dir, fn) repo.index.remove([fn]) @@ -2507,7 +2516,7 @@ class FakeGithubPullRequest(object): else: normalized_files[tests.fakegithub.FakeFile(fn)] = content self.files.update(normalized_files) - else: + elif not delete_files: fn = '%s-%s' % (self.branch.replace('/', '_'), self.number) content = f"test {self.branch} {self.number}\n" self.files.update({tests.fakegithub.FakeFile(fn): content}) @@ -2521,6 +2530,8 @@ class FakeGithubPullRequest(object): if delete_files: for fn in delete_files: + if fn in self.files: + del self.files[fn] fn = os.path.join(repo.working_dir, fn) repo.index.remove([fn]) -- cgit v1.2.1