From 6e443d3eec09512805ca944f34a5e14b4d98076f Mon Sep 17 00:00:00 2001 From: Dudás Ádám <dudas.adam@cloud.bme.hu> Date: Sun, 9 Mar 2014 19:04:37 +0100 Subject: [PATCH] vm: is_running property for Instances --- circle/vm/models/instance.py | 4 ++++ circle/vm/tests/test_models.py | 8 ++++++++ 2 files changed, 12 insertions(+) diff --git a/circle/vm/models/instance.py b/circle/vm/models/instance.py index bcf34a3..ac228f7 100644 --- a/circle/vm/models/instance.py +++ b/circle/vm/models/instance.py @@ -273,6 +273,10 @@ class Instance(AclBase, VirtualMachineDescModel, TimeStampedModel): return " ".join([s for s in parts if s != ""]) @property + def is_running(self): + return self.state == 'RUNNING' + + @property def state(self): """State of the virtual machine instance. """ diff --git a/circle/vm/tests/test_models.py b/circle/vm/tests/test_models.py index e561f80..25f9d1c 100644 --- a/circle/vm/tests/test_models.py +++ b/circle/vm/tests/test_models.py @@ -1,4 +1,5 @@ from django.test import TestCase +from mock import Mock from ..models.common import ( Lease @@ -32,6 +33,13 @@ class TemplateTestCase(TestCase): # TODO add images & net +class InstanceTestCase(TestCase): + + def test_is_running(self): + inst = Mock(state='RUNNING') + assert Instance.is_running.getter(inst) + + class InterfaceTestCase(TestCase): def test_interface_create(self): -- libgit2 0.26.0