def test_post_password_already_posted(self, mock_post_data): exc = url_helper.UrlError(None) exc.status_code = http_client.CONFLICT mock_post_data.side_effect = exc self.assertFalse(self._source.post_password(mock.sentinel.password)) mock_post_data.assert_called_once_with(self._source._password_path, mock.sentinel.password)
def test_post_password_other_error(self, mock_post_data): exc = url_helper.UrlError(None) exc.status_code = http_client.NOT_FOUND mock_post_data.side_effect = exc self.assertRaises(url_helper.UrlError, self._source.post_password, mock.sentinel.password) mock_post_data.assert_called_once_with(self._source._password_path, mock.sentinel.password)
def test_exception_warns(self, m_read): url = "http://example.com/foo" cmdline = "ro cloud-config-url=%s root=LABEL=bar" % url fpath = self.tmp_path("ccfile") m_read.side_effect = url_helper.UrlError( cause="Unexpected Error", url="http://example.com/foo") lvl, msg = main.attempt_cmdline_url( fpath, network=True, cmdline=cmdline) self.assertEqual(logging.WARN, lvl) self.assertIn(url, msg) self.assertFalse(os.path.exists(fpath))
def my_readurl(*args, **kwargs): if len(args): url = args[0] else: url = kwargs['url'] prefix = "%s/%s/" % (seed, version) if not url.startswith(prefix): raise ValueError("unexpected call %s" % url) short = url[len(prefix):] if short not in data: raise url_helper.UrlError("not found", code=404, url=url) return url_helper.StringResponse(data[short])