| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
import os.path |
| 16 |
import tempfile |
| 17 |
import yaml |
| 18 |
|
| 19 |
from mistralclient import utils |
| 20 |
from oslo_serialization import jsonutils |
| 21 |
from oslotest import base |
| 22 |
|
| 23 |
|
| 24 |
ENV_DICT = {'k1': 'abc', 'k2': 123, 'k3': True} |
| 25 |
ENV_STR = jsonutils.dumps(ENV_DICT) |
| 26 |
ENV_YAML = yaml.safe_dump(ENV_DICT, default_flow_style=False) |
| 27 |
|
| 28 |
|
| 29 |
class UtilityTest(base.BaseTestCase): |
| 30 |
|
| 31 |
def test_load_empty(self): |
| 32 |
self.assertDictEqual(dict(), utils.load_content(None)) |
| 33 |
self.assertDictEqual(dict(), utils.load_content('')) |
| 34 |
self.assertDictEqual(dict(), utils.load_content('{}')) |
| 35 |
self.assertListEqual(list(), utils.load_content('[]')) |
| 36 |
|
| 37 |
def test_load_json_content(self): |
| 38 |
self.assertDictEqual(ENV_DICT, utils.load_content(ENV_STR)) |
| 39 |
|
| 40 |
def test_load_json_file(self): |
| 41 |
with tempfile.NamedTemporaryFile() as f: |
| 42 |
f.write(ENV_STR.encode('utf-8')) |
| 43 |
f.flush() |
| 44 |
file_path = os.path.abspath(f.name) |
| 45 |
|
| 46 |
self.assertDictEqual(ENV_DICT, utils.load_file(file_path)) |
| 47 |
|
| 48 |
def test_load_yaml_content(self): |
| 49 |
self.assertDictEqual(ENV_DICT, utils.load_content(ENV_YAML)) |
| 50 |
|
| 51 |
def test_load_yaml_file(self): |
| 52 |
with tempfile.NamedTemporaryFile() as f: |
| 53 |
f.write(ENV_YAML.encode('utf-8')) |
| 54 |
f.flush() |
| 55 |
file_path = os.path.abspath(f.name) |
| 56 |
|
| 57 |
self.assertDictEqual(ENV_DICT, utils.load_file(file_path)) |
| 58 |
|
| 59 |
def test_load_json(self): |
| 60 |
with tempfile.NamedTemporaryFile() as f: |
| 61 |
f.write(ENV_STR.encode('utf-8')) |
| 62 |
f.flush() |
| 63 |
self.assertDictEqual(ENV_DICT, utils.load_json(f.name)) |
| 64 |
|
| 65 |
self.assertDictEqual(ENV_DICT, utils.load_json(ENV_STR)) |