def test_get_patch_invalid_patch(self):
     bz = Bugzilla(api_url="http://fake", attachment_url="fake")
     with mock.patch("requests.get", autospec=True) as get:
         r = get.return_value
         r.content = "The attachment id 1111 is invalid"
         with self.assertRaises(autoland.errors.InvalidAttachment):
             bz.download_patch(patch_id=1111, path=self.tmpdir)
 def test_get_patch_http_failure(self):
     bz = Bugzilla(api_url="http://fake", attachment_url="fake")
     with mock.patch("requests.get", autospec=True) as get:
         r = get.return_value
         r.raise_for_status.side_effect = requests.HTTPError()
         with self.assertRaises(requests.RequestException):
             bz.download_patch(patch_id=1111, path=self.tmpdir)
 def test_get_patch_overwrite_refetches(self):
     bz = Bugzilla(api_url="http://fake", attachment_url="fake")
     with mock.patch("requests.get", autospec=True) as get:
         r = get.return_value
         content = "Super patch"
         r.content = content
         bz.download_patch(patch_id=1111, path=self.tmpdir)
         r.raise_for_status.side_effect = requests.HTTPError()
         with self.assertRaises(requests.RequestException):
             bz.download_patch(patch_id=1111, path=self.tmpdir,
                          overwrite_patch=True)
 def test_get_patch(self):
     bz = Bugzilla(api_url="http://fake", attachment_url="fake")
     with mock.patch("requests.get", autospec=True) as get:
         r = get.return_value
         content = "Super patch"
         r.content = content
         patch_file = bz.download_patch(patch_id=1111, path=self.tmpdir)
         self.assertEquals(content, open(patch_file).read())