test_operations.py 3.16 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
# Copyright 2014 Budapest University of Technology and Economics (BME IK)
#
# This file is part of CIRCLE Cloud.
#
# CIRCLE is free software: you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free
# Software Foundation, either version 3 of the License, or (at your option)
# any later version.
#
# CIRCLE is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along
# with CIRCLE.  If not, see <http://www.gnu.org/licenses/>.

18 19
from django.test import TestCase

20
from common.operations import operation_registry_name as op_reg_name
21
from vm.models import Instance, Node
22
from vm.operations import (
23
    DeployOperation, DestroyOperation, FlushOperation, MigrateOperation,
24 25
    RebootOperation, ResetOperation, SaveAsTemplateOperation,
    ShutdownOperation, ShutOffOperation, SleepOperation, WakeUpOperation,
26
)
27

28 29 30

class DeployOperationTestCase(TestCase):
    def test_operation_registered(self):
31
        assert DeployOperation.id in getattr(Instance, op_reg_name)
32 33 34 35


class DestroyOperationTestCase(TestCase):
    def test_operation_registered(self):
36
        assert DestroyOperation.id in getattr(Instance, op_reg_name)
37 38


39 40 41 42 43
class FlushOperationTestCase(TestCase):
    def test_operation_registered(self):
        assert FlushOperation.id in getattr(Node, op_reg_name)


44 45
class MigrateOperationTestCase(TestCase):
    def test_operation_registered(self):
46
        assert MigrateOperation.id in getattr(Instance, op_reg_name)
47 48 49 50


class RebootOperationTestCase(TestCase):
    def test_operation_registered(self):
51
        assert RebootOperation.id in getattr(Instance, op_reg_name)
52 53 54 55


class ResetOperationTestCase(TestCase):
    def test_operation_registered(self):
56
        assert ResetOperation.id in getattr(Instance, op_reg_name)
57 58 59 60


class SaveAsTemplateOperationTestCase(TestCase):
    def test_operation_registered(self):
61
        assert SaveAsTemplateOperation.id in getattr(Instance, op_reg_name)
62

63
    def test_rename(self):
64 65 66 67 68 69
        self.assertEqual(SaveAsTemplateOperation._rename("foo"), "foo v1")
        self.assertEqual(SaveAsTemplateOperation._rename("foo v2"), "foo v3")
        self.assertEqual(SaveAsTemplateOperation._rename("foo v"), "foo v v1")
        self.assertEqual(SaveAsTemplateOperation._rename("foo v9"), "foo v10")
        self.assertEqual(
            SaveAsTemplateOperation._rename("foo v111"), "foo v112")
70

71 72 73

class ShutdownOperationTestCase(TestCase):
    def test_operation_registered(self):
74
        assert ShutdownOperation.id in getattr(Instance, op_reg_name)
75 76 77 78


class ShutOffOperationTestCase(TestCase):
    def test_operation_registered(self):
79
        assert ShutOffOperation.id in getattr(Instance, op_reg_name)
80 81 82 83


class SleepOperationTestCase(TestCase):
    def test_operation_registered(self):
84
        assert SleepOperation.id in getattr(Instance, op_reg_name)
85 86 87 88


class WakeUpOperationTestCase(TestCase):
    def test_operation_registered(self):
89
        assert WakeUpOperation.id in getattr(Instance, op_reg_name)