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())
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)
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
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())
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()
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
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
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())
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())
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_)
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())
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)
def get_artifact_data(self, id): obj_fingerprint = Fingerprint(self.baseurl, id, jenkins_obj=self) obj_fingerprint.validate() return obj_fingerprint.get_info()
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)
def get_artifact_data(self, id_): obj_fingerprint = Fingerprint(self.baseurl, id_, jenkins_obj=self) obj_fingerprint.validate() return obj_fingerprint.get_info()
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())