From: Alfredo Deza Date: Thu, 8 Dec 2016 15:34:19 +0000 (-0500) Subject: [RM-18169] tests: add a unit test for the url utility X-Git-Tag: v1.5.37~3^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=refs%2Fpull%2F426%2Fhead;p=ceph-deploy.git [RM-18169] tests: add a unit test for the url utility Signed-off-by: Alfredo Deza --- diff --git a/ceph_deploy/tests/unit/util/test_net.py b/ceph_deploy/tests/unit/util/test_net.py index 690201c..9c71bad 100644 --- a/ceph_deploy/tests/unit/util/test_net.py +++ b/ceph_deploy/tests/unit/util/test_net.py @@ -1,3 +1,13 @@ +try: + from urllib.error import HTTPError +except ImportError: + from urllib2 import HTTPError + +try: + from StringIO import StringIO +except ImportError: + from io import StringIO + from ceph_deploy.util import net from ceph_deploy.tests import util import pytest @@ -30,3 +40,14 @@ class TestIpInSubnet(object): @pytest.mark.parametrize('ip', util.generate_ips("10.9.8.0", "10.9.8.255")) def test_false_for_24_subnets(self, ip): assert net.ip_in_subnet(ip, "10.9.1.0/24") is False + + +class TestGetRequest(object): + + def test_urlopen_fails(self, monkeypatch): + def bad_urlopen(url): + raise HTTPError('url', 500, 'error', '', StringIO()) + + monkeypatch.setattr(net, 'urlopen', bad_urlopen) + with pytest.raises(RuntimeError): + net.get_request('https://example.ceph.com')