Skip to content
This repository was archived by the owner on Sep 26, 2019. It is now read-only.

Commit e9f42d1

Browse files
Jenkinsopenstack-gerrit
authored andcommitted
Merge "improve test coverage"
2 parents 973ef45 + 303afb7 commit e9f42d1

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

cloudinit/tests/test_safeyaml.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
from cloudinit import safeyaml as yaml
77
from cloudinit import tests
88

9+
import tempfile
10+
911

1012
class TestSafeYaml(tests.TestCase):
1113
def test_simple(self):
@@ -27,3 +29,19 @@ def test_python_unicode_not_allowed(self):
2729
# in the past this type was allowed, but not now, so explicit test.
2830
blob = "{k1: !!python/unicode 'my unicode', k2: my string}"
2931
self.assertRaises(yaml.YAMLError, yaml.loads, blob)
32+
33+
def test_dumps_returns_string(self):
34+
self.assertTrue(
35+
isinstance(yaml.dumps(867 - 5309), (str,)))
36+
37+
def test_dumps_is_loadable(self):
38+
mydata = {'a': 'hey', 'b': ['bee', 'Bea']}
39+
self.assertEqual(yaml.loads(yaml.dumps(mydata)), mydata)
40+
41+
def test_load(self):
42+
valid_yaml = "foo: bar"
43+
expected = {'foo': 'bar'}
44+
with tempfile.NamedTemporaryFile(mode='w', delete=False) as tmpf:
45+
tmpf.write(valid_yaml)
46+
tmpf.close()
47+
self.assertEqual(yaml.load(tmpf.name), expected)

cloudinit/tests/test_url_helper.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,23 @@ def test_url_fetch(self):
8080
self.assertEqual(b"it worked!", resp.contents)
8181
self.assertEqual(url_helper.OK, resp.status_code)
8282

83+
@httpretty.activate
84+
def test_no_protocol_url(self):
85+
body = b'it worked!'
86+
no_proto = 'www.yahoo.com'
87+
httpretty.register_uri(httpretty.GET, "http://" + no_proto, body=body)
88+
resp = url_helper.read_url(no_proto)
89+
self.assertTrue(resp.url.startswith("http://"))
90+
91+
@httpretty.activate
92+
def test_response_has_url(self):
93+
body = b'it worked!'
94+
url = 'http://www.yahoo.com/'
95+
httpretty.register_uri(httpretty.GET, url, body=body)
96+
resp = url_helper.read_url(url)
97+
self.assertEqual(resp.url, url)
98+
self.assertEqual(body, resp.contents)
99+
83100
@httpretty.activate
84101
def test_retry_url_fetch(self):
85102
httpretty.register_uri(httpretty.GET,

0 commit comments

Comments
 (0)