def test_url_exception(stc): """returns nothing""" # not mocked to generate URLError try: vcmlib.listversions('badserver', 1234) assert(0), 'expected an urllib2.URLError exception' except urllib2.URLError as ex: pass
def test_http_exception(stc): """returns nothing""" # not mocked to generate InvalidURL try: vcmlib.listversions('badserver', 'bad port') assert(0), 'expected an httplib.InvalidURL exception' except httplib.InvalidURL as ex: pass
def test_json_exception(stc): """returns nothing""" result = 'bad json' res = Response(result, 200) saveurlopen = urllib2.urlopen urllib2.urlopen = MagicMock(return_value=res) try: vcmlib.listversions('server1', 1234) urllib2.urlopen = saveurlopen assert(0), 'expected a ValueError exception' except ValueError as ex: urllib2.urlopen = saveurlopen