Commit 69057f65 by Őry Máté

vm: add tests

parent 6fde18eb
......@@ -82,12 +82,13 @@ class Node(TimeStampedModel):
True: {False: ('MISSING', _('missing')),
True: ('ONLINE', _('online'))}}
@property
def state(self):
def get_state(self):
"""The state combined of online and enabled attributes.
"""
return self.STATES[self.enabled][self.online][0]
state = property(get_state)
def get_status_display(self):
return self.STATES[self.enabled][self.online][1]
......
from datetime import datetime
from django.test import TestCase
from mock import Mock
from django.utils.translation import ugettext_lazy as _
from mock import Mock, MagicMock, patch
from ..models.common import (
Lease
)
from ..models.instance import (
find_unused_port, InstanceTemplate, Instance
)
from ..models.network import (
Interface
from ..models import (
Lease, Node, Interface, Instance, InstanceTemplate,
)
from ..models.instance import find_unused_port
class PortFinderTestCase(TestCase):
......@@ -39,6 +36,26 @@ class InstanceTestCase(TestCase):
inst = Mock(state='RUNNING')
assert Instance.is_running.getter(inst)
def deploy_destroyed(self):
inst = Mock(destroyed_at=datetime.now())
with self.assertRaises(Instance.InstanceDestroyedError):
Instance.deploy(inst)
def destroy_destroyed(self):
inst = Mock(destroyed_at=datetime.now())
Instance.destroy(inst)
self.assertFalse(inst.save.called)
def destroy_sets_destroyed(self):
inst = MagicMock(destroyed_at=None, spec=Instance)
inst.node = MagicMock(spec=Node)
inst.disks.all.return_value = []
with patch('vm.models.instance.instance_activity') as ia:
ia.return_value = MagicMock()
Instance.destroy(inst)
self.assertTrue(inst.destroyed_at)
inst.save.assert_called()
class InterfaceTestCase(TestCase):
......@@ -78,3 +95,14 @@ class LeaseTestCase(TestCase):
l.suspend_interval = None
assert "never" in unicode(l)
class NodeTestCase(TestCase):
def test_state(self):
node = Mock(spec=Node)
node.online = True
node.enabled = True
node.STATES = Node.STATES
self.assertEqual(Node.get_state(node), "ONLINE")
assert isinstance(Node.get_status_display(node), _("").__class__)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment