test_models.py 1.56 KB
Newer Older
1
from django.test import TestCase
2 3 4

from mock import Mock

5
from ..models.instance import (
6 7 8
    InstanceTemplate, Instance,
    # post_state_changed
    pre_state_changed,
9
)
10 11 12
from ..models.network import (
    Interface
)
Őry Máté committed
13 14 15
from ..models.common import (
    Lease
)
16 17 18


class TemplateTestCase(TestCase):
19

20
    def test_template_creation(self):
21 22
        template = InstanceTemplate(name='My first template',
                                    access_method='ssh', )
Őry Máté committed
23
        template.clean()
24
        # TODO add images & net
25 26


27 28 29 30 31 32 33
class InterfaceTestCase(TestCase):

    def test_interface_create(self):
        from firewall.models import Vlan, Domain
        from django.contrib.auth.models import User
        owner = User()
        owner.save()
Bach Dániel committed
34
        i = Instance(id=10, owner=owner, access_method='rdp')
35 36 37 38 39 40
        d = Domain(owner=owner)
        d.save()
        v = Vlan(vid=55, network4='127.0.0.1/8',
                 network6='2001::1/32', domain=d)
        v.save()
        Interface.create(i, v, managed=True, owner=owner)
Őry Máté committed
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64


class LeaseTestCase(TestCase):

    fixtures = ['lease.json']

    def test_methods(self):
        from datetime import timedelta
        td = timedelta(seconds=1)
        l = Lease.objects.get(pk=1)

        assert "never" not in unicode(l)
        assert l.delete_interval > td
        assert l.suspend_interval > td

        l.delete_interval = None
        assert "never" in unicode(l)
        assert l.delete_interval is None

        l.delete_interval = td * 2
        assert "never" not in unicode(l)

        l.suspend_interval = None
        assert "never" in unicode(l)