コード例 #1
0
 def test_valid_with_requests_HTTPError_Not404(self, _poll, _basepoll):
     resp_obj = requests.models.Response()
     resp_obj.status_code = 401
     _poll.side_effect = requests.exceptions.HTTPError(response=resp_obj)
     J = Jenkins(self.baseurl, username="******", password="******")
     fp = Fingerprint(self.baseurl, self.dummy_md5, J)
     self.assertFalse(fp.valid())
コード例 #2
0
ファイル: artifact.py プロジェクト: 117111302/jenkinsapi
 def _verify_download(self, fspath):
     """
     Verify that a downloaded object has a valid fingerprint.
     """
     local_md5 = self._md5sum(fspath)
     fp = Fingerprint(self.build.job.jenkins.baseurl, local_md5, self.build.job.jenkins)
     return fp.validate_for_build(os.path.basename(fspath), self.build.job.name, self.build.buildno)
コード例 #3
0
 def _verify_download(self, fspath):
     """
     Verify that a downloaded object has a valid fingerprint.
     """
     local_md5 = self._md5sum(fspath)
     fp = Fingerprint(self.build.job.jenkins.baseurl, local_md5, self.build.job.jenkins)
     return fp.validate_for_build(os.path.basename(fspath), self.build.job.name, self.build.buildno)
コード例 #4
0
def test_invalid_for_401(jenkins, dummy_md5, monkeypatch):
    class FakeResponse(object):
        status_code = 401
        text = '{}'

    class FakeHTTPError(HTTPError):
        def __init__(self):
            self.response = FakeResponse()

    def fake_poll(cls, tree=None):   # pylint: disable=unused-argument
        raise FakeHTTPError()

    monkeypatch.setattr(JenkinsBase, '_poll', fake_poll)

    def fake_get_url(
            url,  # pylint: disable=unused-argument
            params=None,  # pylint: disable=unused-argument
            headers=None,  # pylint: disable=unused-argument
            allow_redirects=True,  # pylint: disable=unused-argument
            stream=False):  # pylint: disable=unused-argument

        return FakeResponse()

    monkeypatch.setattr(Requester, 'get_url', fake_get_url)

    fingerprint = Fingerprint('http://foo:8080', dummy_md5, jenkins)
    assert fingerprint.valid() is not True
コード例 #5
0
 def test_valid_with_requests_HTTPError_Not404(self, _poll, _basepoll):
     resp_obj = requests.models.Response()
     resp_obj.status_code = 401
     _poll.side_effect = requests.exceptions.HTTPError(response=resp_obj)
     J = Jenkins(self.baseurl, username='******', password='******')
     fp = Fingerprint(self.baseurl, self.dummy_md5, J)
     self.assertFalse(fp.valid())
コード例 #6
0
def test_object_creation(jenkins, dummy_md5, monkeypatch):
    def fake_poll(cls, tree=None):   # pylint: disable=unused-argument
        return {}

    monkeypatch.setattr(JenkinsBase, '_poll', fake_poll)
    fp_instance = Fingerprint('http://foo:8080', dummy_md5, jenkins)

    assert isinstance(fp_instance, Fingerprint)
    assert str(fp_instance) == dummy_md5
    assert fp_instance.valid()
コード例 #7
0
ファイル: artifact.py プロジェクト: CBNL/jenkinsapi
 def _verify_download(self, fspath, strict_validation):
     """
     Verify that a downloaded object has a valid fingerprint.
     """
     local_md5 = self._md5sum(fspath)
     baseurl = self.build.job.jenkins.baseurl
     fp = Fingerprint(baseurl, local_md5, self.build.job.jenkins)
     valid = fp.validate_for_build(os.path.basename(fspath), self.build.job.name, self.build.buildno)
     if not valid or (fp.unknown and strict_validation):  # strict = 404 as invalid
         raise ArtifactBroken("Artifact %s seems to be broken, check %s" % (local_md5, baseurl))
     return True
コード例 #8
0
 def _verify_download(self, fspath, strict_validation):
     """
     Verify that a downloaded object has a valid fingerprint.
     """
     local_md5 = self._md5sum(fspath)
     baseurl = self.build.job.jenkins.baseurl
     fp = Fingerprint(baseurl, local_md5, self.build.job.jenkins)
     valid = fp.validate_for_build(self.filename, self.build.job.name,
                                   self.build.buildno)
     if not valid or (fp.unknown and strict_validation):
         # strict = 404 as invalid
         raise ArtifactBroken("Artifact %s seems to be broken, check %s" %
                              (local_md5, baseurl))
     return True
コード例 #9
0
class TestFingerprint(unittest.TestCase):
    def setUp(self):
        self.baseurl = 'http://*****:*****@mock.patch.object(Jenkins, '_poll')
    @mock.patch.object(JenkinsBase, '_poll')
    def test_object_creation(self, _poll, _basepoll):
        J = Jenkins(self.baseurl, username='******', password='******')
        self.fp_instance = Fingerprint(self.baseurl, self.dummy_md5, J)
        self.assertTrue(isinstance(self.fp_instance, Fingerprint))
        self.assertEquals(str(self.fp_instance), self.dummy_md5)
        self.assertTrue(self.fp_instance.valid())

    @mock.patch.object(Jenkins, '_poll')
    @mock.patch.object(JenkinsBase, '_poll')
    def test_valid_with_requests_HTTPError_404(self, _poll, _basepoll):
        resp_obj = requests.models.Response()
        resp_obj.status_code = 404
        _poll.side_effect = requests.exceptions.HTTPError(response=resp_obj)
        J = Jenkins(self.baseurl, username='******', password='******')
        fp = Fingerprint(self.baseurl, self.dummy_md5, J)
        self.assertTrue(fp.valid())

    @mock.patch.object(Jenkins, '_poll')
    @mock.patch.object(JenkinsBase, '_poll')
    def test_valid_with_requests_HTTPError_Not404(self, _poll, _basepoll):
        resp_obj = requests.models.Response()
        resp_obj.status_code = 401
        _poll.side_effect = requests.exceptions.HTTPError(response=resp_obj)
        J = Jenkins(self.baseurl, username='******', password='******')
        fp = Fingerprint(self.baseurl, self.dummy_md5, J)
        self.assertFalse(fp.valid())
コード例 #10
0
class TestFingerprint(unittest.TestCase):
    def setUp(self):
        self.baseurl = "http://*****:*****@mock.patch.object(Jenkins, "_poll")
    @mock.patch.object(JenkinsBase, "_poll")
    def test_object_creation(self, _poll, _basepoll):
        J = Jenkins(self.baseurl, username="******", password="******")
        self.fp_instance = Fingerprint(self.baseurl, self.dummy_md5, J)
        self.assertTrue(isinstance(self.fp_instance, Fingerprint))
        self.assertEquals(str(self.fp_instance), self.dummy_md5)
        self.assertTrue(self.fp_instance.valid())

    @mock.patch.object(Jenkins, "_poll")
    @mock.patch.object(JenkinsBase, "_poll")
    def test_valid_with_requests_HTTPError_404(self, _poll, _basepoll):
        resp_obj = requests.models.Response()
        resp_obj.status_code = 404
        _poll.side_effect = requests.exceptions.HTTPError(response=resp_obj)
        J = Jenkins(self.baseurl, username="******", password="******")
        fp = Fingerprint(self.baseurl, self.dummy_md5, J)
        self.assertTrue(fp.valid())

    @mock.patch.object(Jenkins, "_poll")
    @mock.patch.object(JenkinsBase, "_poll")
    def test_valid_with_requests_HTTPError_Not404(self, _poll, _basepoll):
        resp_obj = requests.models.Response()
        resp_obj.status_code = 401
        _poll.side_effect = requests.exceptions.HTTPError(response=resp_obj)
        J = Jenkins(self.baseurl, username="******", password="******")
        fp = Fingerprint(self.baseurl, self.dummy_md5, J)
        self.assertFalse(fp.valid())
コード例 #11
0
 def validate_fingerprint(self, id_):
     obj_fingerprint = Fingerprint(self.baseurl, id_, jenkins_obj=self)
     obj_fingerprint.validate()
     log.info(msg="Jenkins says %s is valid" % id_)
コード例 #12
0
 def test_object_creation(self, _poll, _basepoll):
     J = Jenkins(self.baseurl, username='******', password='******')
     self.fp_instance = Fingerprint(self.baseurl, self.dummy_md5, J)
     self.assertTrue(isinstance(self.fp_instance, Fingerprint))
     self.assertEquals(str(self.fp_instance), self.dummy_md5)
     self.assertTrue(self.fp_instance.valid())
コード例 #13
0
ファイル: jenkins.py プロジェクト: aamerine/jenkinsapi
 def validate_fingerprint_for_build(self, digest, filename, job, build):
     obj_fingerprint = Fingerprint(self.baseurl, digest, jenkins_obj=self)
     return obj_fingerprint.validate_for_build(filename, job, build)
コード例 #14
0
ファイル: jenkins.py プロジェクト: aamerine/jenkinsapi
 def get_artifact_data(self, id):
     obj_fingerprint = Fingerprint(self.baseurl, id, jenkins_obj=self)
     obj_fingerprint.validate()
     return obj_fingerprint.get_info()
コード例 #15
0
ファイル: jenkins.py プロジェクト: aamerine/jenkinsapi
 def validate_fingerprint(self, id):
     obj_fingerprint = Fingerprint(self.baseurl, id, jenkins_obj=self)
     obj_fingerprint.validate()
     log.info("Jenkins says %s is valid" % id)
コード例 #16
0
 def validate_fingerprint_for_build(self, digest, filename, job, build):
     obj_fingerprint = Fingerprint(self.baseurl, digest, jenkins_obj=self)
     return obj_fingerprint.validate_for_build(filename, job, build)
コード例 #17
0
 def get_artifact_data(self, id_):
     obj_fingerprint = Fingerprint(self.baseurl, id_, jenkins_obj=self)
     obj_fingerprint.validate()
     return obj_fingerprint.get_info()
コード例 #18
0
 def test_object_creation(self, _poll, _basepoll):
     J = Jenkins(self.baseurl, username="******", password="******")
     self.fp_instance = Fingerprint(self.baseurl, self.dummy_md5, J)
     self.assertTrue(isinstance(self.fp_instance, Fingerprint))
     self.assertEquals(str(self.fp_instance), self.dummy_md5)
     self.assertTrue(self.fp_instance.valid())