Skip to content

Commit 0dfd181

Browse files
glasslionsysradium
authored andcommitted
The template.instantiate method should return the new vm id (python-oca#50)
* the template.instantiate method now returns the new id * add tests for template.instantiate's return value
1 parent 469abd8 commit 0dfd181

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

oca/template.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def instantiate(self, name='', pending=False, extra_template=''):
9090
``extra_template``
9191
A string containing an extra template to be merged with the one being instantiated
9292
"""
93-
self.client.call(VmTemplate.METHODS['instantiate'], self.id, name, pending, extra_template)
93+
return self.client.call(VmTemplate.METHODS['instantiate'], self.id, name, pending, extra_template)
9494

9595
def __repr__(self):
9696
return '<oca.VmTemplate("%s")>' % self.name

oca/tests/test_template.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,30 +52,30 @@ def test_chown(self):
5252
'1', 2, 3)
5353

5454
def test_instantiate_with_default_name(self):
55-
self.client.call = Mock()
55+
self.client.call = Mock(return_value=4)
5656
template = oca.VmTemplate(self.xml, self.client)
57-
template.instantiate()
57+
assert template.instantiate() == 4
5858
self.client.call.assert_called_once_with('template.instantiate',
5959
'1', '', False, '')
6060

6161
def test_instantiate_with_custom_name(self):
62-
self.client.call = Mock()
62+
self.client.call = Mock(return_value=5)
6363
template = oca.VmTemplate(self.xml, self.client)
64-
template.instantiate('asd')
64+
assert template.instantiate('asd') == 5
6565
self.client.call.assert_called_once_with('template.instantiate',
6666
'1', 'asd', False, '')
6767

6868
def test_instantiate_with_default_name_and_context(self):
69-
self.client.call = Mock()
69+
self.client.call = Mock(return_value=6)
7070
template = oca.VmTemplate(self.xml, self.client)
71-
template.instantiate('', False, 'VCPU=4')
71+
assert template.instantiate('', False, 'VCPU=4') == 6
7272
self.client.call.assert_called_once_with('template.instantiate',
7373
'1', '', False, 'VCPU=4')
7474

7575
def test_instantiate_with_custom_name_and_context(self):
76-
self.client.call = Mock()
76+
self.client.call = Mock(return_value=7)
7777
template = oca.VmTemplate(self.xml, self.client)
78-
template.instantiate('asd', False, 'VCPU=4')
78+
assert template.instantiate('asd', False, 'VCPU=4') == 7
7979
self.client.call.assert_called_once_with('template.instantiate',
8080
'1', 'asd', False, 'VCPU=4')
8181

0 commit comments

Comments
 (0)