Skip to content

Commit d5ef4ec

Browse files
Felix Franzsysradium
authored andcommitted
Add tests for changes
1 parent b338ee8 commit d5ef4ec

4 files changed

Lines changed: 64 additions & 5 deletions

File tree

oca/tests/test_client.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,14 @@ def test_defaul_xmlrpc(self):
6565
c = oca.Client('test:test')
6666
assert c.one_address == oca.Client.DEFAULT_ONE_ADDRESS
6767

68+
def test_version(self):
69+
c = oca.Client('test:test')
70+
assert c.one_version is None
71+
c.call = Mock(return_value='1.0.0')
72+
assert c.version() == '1.0.0'
73+
c.call.assert_called_once_with('system.version')
74+
assert c.one_version == '1.0.0'
75+
6876
def test_return_two_values_call(self):
6977
c = oca.Client('test:test')
7078
c.server.one = Mock()

oca/tests/test_host.py

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,55 @@
33
import unittest
44

55
from mock import Mock
6+
from xml.etree import ElementTree as ET
7+
from parameterized import parameterized_class
68

79
import oca
810

911

12+
@parameterized_class([
13+
{'one_version': '4.10.0'},
14+
{'one_version': '5.0.0'},
15+
])
1016
class TestHost(unittest.TestCase):
1117
def setUp(self):
1218
self.client = oca.Client('test:test')
19+
self.client.call = Mock(return_value=self.one_version)
1320
self.xml = open(os.path.join(os.path.dirname(oca.__file__),
1421
'tests/fixtures/host.xml')).read()
1522

23+
if self.one_version == '5.0.0':
24+
xml_v5 = ET.fromstring(self.xml)
25+
[xml_v5.remove(vn_mad) for vn_mad in xml_v5.findall('VN_MAD')]
26+
self.xml = ET.tostring(xml_v5).decode('utf-8')
27+
28+
def tearDown(self):
29+
version = self.client.one_version
30+
if version is not None and version.startswith('5.'):
31+
xml_types = oca.Host.XML_TYPES
32+
xml_types['vn_mad'] = oca.pool.extractString
33+
34+
def test_instantiate(self):
35+
h = oca.Host(self.xml, self.client)
36+
self.client.call.assert_called_once_with('system.version')
37+
expected = 'vn_dummy' if self.one_version == '4.10.0' else None
38+
assert (getattr(h, 'vn_mad', None) == expected)
39+
1640
def test_allocate(self):
1741
self.client.call = Mock(return_value=7)
1842
host_id = oca.Host.allocate(self.client, 'host', 'im_xen',
1943
'vmm_xen', 'tm_nfs')
2044
assert host_id == 7
2145

2246
def test_enable(self):
23-
self.client.call = Mock(return_value='')
2447
h = oca.Host(self.xml, self.client)
48+
self.client.call = Mock(return_value='')
2549
h.enable()
2650
self.client.call.assert_called_once_with('host.enable', '7', True)
2751

2852
def test_disable(self):
29-
self.client.call = Mock(return_value='')
3053
h = oca.Host(self.xml, self.client)
54+
self.client.call = Mock(return_value='')
3155
h.disable()
3256
self.client.call.assert_called_once_with('host.enable', '7', False)
3357

oca/tests/test_virtual_network.py

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import unittest
44

55
from mock import Mock
6+
from xml.etree import ElementTree as ET
7+
from parameterized import parameterized_class
68

79
import oca
810

@@ -14,26 +16,50 @@
1416
NETWORK_ADDRESS = 192.168.0.0"""
1517

1618

19+
@parameterized_class([
20+
{'one_version': '4.10.0'},
21+
{'one_version': '5.0.0'},
22+
])
1723
class TestVirtualNetwork(unittest.TestCase):
1824
def setUp(self):
1925
self.client = oca.Client('test:test')
26+
self.client.call = Mock(return_value=self.one_version)
2027
self.xml = open(os.path.join(os.path.dirname(oca.__file__),
2128
'tests/fixtures/vnet.xml')).read()
2229

30+
if self.one_version == '5.0.0':
31+
xml_v5 = ET.fromstring(self.xml)
32+
vn_mad = ET.Element('VN_MAD')
33+
vn_mad.text = 'vn_dummy'
34+
xml_v5.append(vn_mad)
35+
self.xml = ET.tostring(xml_v5).decode('utf-8')
36+
37+
def tearDown(self):
38+
version = self.client.one_version
39+
if version is not None and version.startswith('5.'):
40+
xml_types = oca.VirtualNetwork.XML_TYPES
41+
del xml_types['vn_mad']
42+
43+
def test_instantiate(self):
44+
h = oca.VirtualNetwork(self.xml, self.client)
45+
self.client.call.assert_called_once_with('system.version')
46+
expected = None if self.one_version == '4.10.0' else 'vn_dummy'
47+
assert (getattr(h, 'vn_mad', None) == expected)
48+
2349
def test_allocate(self):
2450
self.client.call = Mock(return_value=2)
2551
assert oca.VirtualNetwork.allocate(self.client, VN_TEMPLATE) == 2
2652

2753
def test_publish(self):
28-
self.client.call = Mock(return_value='')
2954
h = oca.VirtualNetwork(self.xml, self.client)
55+
self.client.call = Mock(return_value='')
3056
h._convert_types()
3157
h.publish()
3258
self.client.call.assert_called_once_with('vn.publish', 3, True)
3359

3460
def test_unpublish(self):
35-
self.client.call = Mock(return_value='')
3661
h = oca.VirtualNetwork(self.xml, self.client)
62+
self.client.call = Mock(return_value='')
3763
h._convert_types()
3864
h.unpublish()
3965
self.client.call.assert_called_once_with('vn.publish', 3, False)
@@ -44,8 +70,8 @@ def test_repr(self):
4470
assert h.__repr__() == '<oca.VirtualNetwork("Red LAN")>'
4571

4672
def test_chown(self):
47-
self.client.call = Mock(return_value='')
4873
h = oca.VirtualNetwork(self.xml, self.client)
74+
self.client.call = Mock(return_value='')
4975
h._convert_types()
5076
h.chown(2, 2)
5177
self.client.call.assert_called_once_with('vn.chown', 3, 2, 2)

tox.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ envlist = py27, py35, py36
88
deps=nose
99
mock
1010
coverage
11+
parameterized
1112
commands=nosetests --with-coverage --cover-package=oca

0 commit comments

Comments
 (0)