Fixed unittest for Gitea source step

This commit is contained in:
Marvin Pohl 2018-09-27 16:53:16 +02:00
parent d39640ea10
commit c5fba6c44a
2 changed files with 14 additions and 12 deletions

View File

@ -16,13 +16,11 @@ class Gitea(Git):
"""
@defer.inlineCallbacks
def _fetch(self, arg):
print("Update")
super(Gitea, self)._fetch(arg)
res = yield super(Gitea, self)._fetch(arg)
if self.build.hasProperty("pr_id"):
remote = yield self._dovccmd(
['config', 'remote.pr_source.url'], collectStdout=True)
print(remote)
if remote is None or remote is '':
if remote is None or remote.strip() is '':
yield self._dovccmd(
['remote', 'add', 'pr_source',
self.build.getProperty("head_git_ssh_url", None)])
@ -31,6 +29,5 @@ class Gitea(Git):
['remote', 'set-url', 'pr_source',
self.build.getProperty("head_git_ssh_url", None)])
yield self._dovccmd(['fetch', 'pr_source'])
yield self._dovccmd(['merge', self.build.getProperty("head_sha", None)])
else:
print("Not a PR")
res = yield self._dovccmd(['merge', self.build.getProperty("head_sha", None)])
defer.returnValue(res)

View File

@ -33,8 +33,8 @@ class TestGitea(sourcesteps.SourceStepMixin, config.ConfigErrorsMixin, unittest.
self.sourceName = self.stepClass.__name__
return self.setUpSourceStep()
def setupStep(self, step, args, **kwargs):
step = sourcesteps.SourceStepMixin.setupStep(self, step, args, **kwargs)
def setupStep(self, step, **kwargs):
step = sourcesteps.SourceStepMixin.setupStep(self, step, **kwargs)
step.build.properties.setProperty("pr_id", "1", "gitea pr id")
step.build.properties.setProperty("base_sha", "f6ad368298bd941e934a41f3babc827b2aa95a1d", "gitea source branch")
step.build.properties.setProperty("base_branch", "master", "gitea source branch")
@ -54,7 +54,7 @@ class TestGitea(sourcesteps.SourceStepMixin, config.ConfigErrorsMixin, unittest.
def test_with_merge_branch(self):
self.setupStep(
Gitea(repourl='git@gitea.example.com:base/awesome_project.git',
mode='full', method='clean'), None)
mode='full', method='clean'))
self.expectCommands(
ExpectShell(workdir='wkdir',
@ -91,9 +91,14 @@ class TestGitea(sourcesteps.SourceStepMixin, config.ConfigErrorsMixin, unittest.
+ 0,
ExpectShell(workdir='wkdir',
command=['git', 'merge', 'e4cd1224c622d46a8199c85c858485723115d2c8'])
+ 0
+ 0,
ExpectShell(workdir='wkdir',
command=['git', 'rev-parse', 'HEAD'])
+ ExpectShell.log('stdio',
stdout='e4cd1224c622d46a8199c85c858485723115d2c8')
+ 0,
)
self.expectOutcome(result=SUCCESS)
self.expectProperty(
'got_revision', 'e4cd1224c622d46a8199c85c858485723115d2c8', 'GitLab')
'got_revision', 'e4cd1224c622d46a8199c85c858485723115d2c8', 'Gitea')
return self.runStep()