Merge "improve test coverage"
This commit is contained in:
commit
e9f42d1014
@ -6,6 +6,8 @@
|
|||||||
from cloudinit import safeyaml as yaml
|
from cloudinit import safeyaml as yaml
|
||||||
from cloudinit import tests
|
from cloudinit import tests
|
||||||
|
|
||||||
|
import tempfile
|
||||||
|
|
||||||
|
|
||||||
class TestSafeYaml(tests.TestCase):
|
class TestSafeYaml(tests.TestCase):
|
||||||
def test_simple(self):
|
def test_simple(self):
|
||||||
@ -27,3 +29,19 @@ class TestSafeYaml(tests.TestCase):
|
|||||||
# in the past this type was allowed, but not now, so explicit test.
|
# in the past this type was allowed, but not now, so explicit test.
|
||||||
blob = "{k1: !!python/unicode 'my unicode', k2: my string}"
|
blob = "{k1: !!python/unicode 'my unicode', k2: my string}"
|
||||||
self.assertRaises(yaml.YAMLError, yaml.loads, blob)
|
self.assertRaises(yaml.YAMLError, yaml.loads, blob)
|
||||||
|
|
||||||
|
def test_dumps_returns_string(self):
|
||||||
|
self.assertTrue(
|
||||||
|
isinstance(yaml.dumps(867 - 5309), (str,)))
|
||||||
|
|
||||||
|
def test_dumps_is_loadable(self):
|
||||||
|
mydata = {'a': 'hey', 'b': ['bee', 'Bea']}
|
||||||
|
self.assertEqual(yaml.loads(yaml.dumps(mydata)), mydata)
|
||||||
|
|
||||||
|
def test_load(self):
|
||||||
|
valid_yaml = "foo: bar"
|
||||||
|
expected = {'foo': 'bar'}
|
||||||
|
with tempfile.NamedTemporaryFile(mode='w', delete=False) as tmpf:
|
||||||
|
tmpf.write(valid_yaml)
|
||||||
|
tmpf.close()
|
||||||
|
self.assertEqual(yaml.load(tmpf.name), expected)
|
||||||
|
@ -80,6 +80,23 @@ class UrlHelperFetchTest(tests.TestCase):
|
|||||||
self.assertEqual(b"it worked!", resp.contents)
|
self.assertEqual(b"it worked!", resp.contents)
|
||||||
self.assertEqual(url_helper.OK, resp.status_code)
|
self.assertEqual(url_helper.OK, resp.status_code)
|
||||||
|
|
||||||
|
@httpretty.activate
|
||||||
|
def test_no_protocol_url(self):
|
||||||
|
body = b'it worked!'
|
||||||
|
no_proto = 'www.yahoo.com'
|
||||||
|
httpretty.register_uri(httpretty.GET, "http://" + no_proto, body=body)
|
||||||
|
resp = url_helper.read_url(no_proto)
|
||||||
|
self.assertTrue(resp.url.startswith("http://"))
|
||||||
|
|
||||||
|
@httpretty.activate
|
||||||
|
def test_response_has_url(self):
|
||||||
|
body = b'it worked!'
|
||||||
|
url = 'http://www.yahoo.com/'
|
||||||
|
httpretty.register_uri(httpretty.GET, url, body=body)
|
||||||
|
resp = url_helper.read_url(url)
|
||||||
|
self.assertEqual(resp.url, url)
|
||||||
|
self.assertEqual(body, resp.contents)
|
||||||
|
|
||||||
@httpretty.activate
|
@httpretty.activate
|
||||||
def test_retry_url_fetch(self):
|
def test_retry_url_fetch(self):
|
||||||
httpretty.register_uri(httpretty.GET,
|
httpretty.register_uri(httpretty.GET,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user