Fixed issue with getting the latest ref

Signed-off-by: Martin Curlej <mcurlej@redhat.com>
This commit is contained in:
Martin Curlej
2017-11-09 12:46:58 +01:00
parent f369182d72
commit bf2369e8e0
3 changed files with 46 additions and 12 deletions

View File

@@ -65,8 +65,10 @@ class TestSCMModule(unittest.TestCase):
scm = module_build_service.scm.SCM(repo_path)
assert scm.scheme == 'git', scm.scheme
fname = tempfile.mktemp(suffix='mbs-scm-test')
scm.get_latest(branch='master; touch %s' % fname)
assert not os.path.exists(fname), "%r exists! Vulnerable." % fname
try:
scm.get_latest(branch='master; touch %s' % fname)
except UnprocessableEntity:
assert not os.path.exists(fname), "%r exists! Vulnerable." % fname
def test_local_extract_name(self):
scm = module_build_service.scm.SCM(repo_path)
@@ -115,3 +117,26 @@ class TestSCMModule(unittest.TestCase):
scm.checkout(self.tempdir)
scm.verify()
scm.get_module_yaml()
@raises(UnprocessableEntity)
def test_get_latest_incorect_component_branch(self):
scm = module_build_service.scm.SCM(repo_path)
scm.get_latest(branch='foobar')
def test_get_latest_component_branch(self):
ref = "5481faa232d66589e660cc301179867fb00842c9"
branch = "master"
scm = module_build_service.scm.SCM(repo_path)
commit = scm.get_latest(branch=branch)
assert commit == ref
def test_get_latest_component_ref(self):
ref = "5481faa232d66589e660cc301179867fb00842c9"
scm = module_build_service.scm.SCM(repo_path)
commit = scm.get_latest(branch=ref)
assert commit == ref
@raises(UnprocessableEntity)
def test_get_latest_incorect_component_ref(self):
scm = module_build_service.scm.SCM(repo_path)
scm.get_latest(branch='15481faa232d66589e660cc301179867fb00842c9')

View File

@@ -81,7 +81,7 @@ class FakeSCM(object):
self.mocked_scm.return_value.commit = self.commit
if get_latest_raise:
self.mocked_scm.return_value.get_latest.side_effect = \
RuntimeError("Failed to get_latest commit")
UnprocessableEntity("Failed to get_latest commit")
else:
self.mocked_scm.return_value.get_latest = self.get_latest
self.mocked_scm.return_value.repository_root = "git://pkgs.stg.fedoraproject.org/modules/"