Merge "Change destination of snmp mibs files from /usr/share/mibs/ietf to /usr/share...
[apex.git] / apex / tests / test_apex_common_utils.py
1 ##############################################################################
2 # Copyright (c) 2016 Dan Radez (Red Hat)
3 #
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
9
10 import ipaddress
11 import nose.tools
12 import os
13
14 from apex.common import utils
15 from apex.settings.network_settings import NetworkSettings
16 from apex.tests.constants import (
17     TEST_CONFIG_DIR,
18     TEST_PLAYBOOK_DIR)
19
20 NET_SETS = os.path.join(TEST_CONFIG_DIR, 'network', 'network_settings.yaml')
21
22
23 class TestCommonUtils(object):
24     @classmethod
25     def setup_class(klass):
26         """This method is run once for each class before any tests are run"""
27
28     @classmethod
29     def teardown_class(klass):
30         """This method is run once for each class _after_ all tests are run"""
31
32     def setUp(self):
33         """This method is run once before _each_ test method is executed"""
34
35     def teardown(self):
36         """This method is run once after _each_ test method is executed"""
37
38     def test_str2bool(self):
39         nose.tools.assert_equal(utils.str2bool(True), True)
40         nose.tools.assert_equal(utils.str2bool(False), False)
41         nose.tools.assert_equal(utils.str2bool("True"), True)
42         nose.tools.assert_equal(utils.str2bool("YES"), True)
43
44     def test_parse_yaml(self):
45         nose.tools.assert_is_instance(utils.parse_yaml(NET_SETS), dict)
46
47     def test_dict_to_string(self):
48         net_settings = NetworkSettings(NET_SETS)
49         output = utils.dict_objects_to_str(net_settings)
50         nose.tools.assert_is_instance(output, dict)
51         for k, v in output.items():
52             nose.tools.assert_is_instance(k, str)
53             nose.tools.assert_not_is_instance(v, ipaddress.IPv4Address)
54
55     def test_run_ansible(self):
56         playbook = 'apex/tests/playbooks/test_playbook.yaml'
57         nose.tools.assert_equal(
58             utils.run_ansible(None, os.path.join(playbook),
59                               dry_run=True), None)