tests.py 962 Bytes
Newer Older
1 2 3
from django.test import TestCase
from admin import HostAdmin

4

5 6 7 8
class MockInstance:
    def __init__(self, groups):
        self.groups = MockGroups(groups)

9

10 11 12 13
class MockGroup:
    def __init__(self, name):
        self.name = name

14

15 16 17 18 19 20 21
class MockGroups:
    def __init__(self, groups):
        self.groups = groups

    def all(self):
        return self.groups

22

23 24 25 26 27 28 29 30 31 32 33 34 35
class HostAdminTestCase(TestCase):
    def test_no_groups(self):
        instance = MockInstance([])
        l = HostAdmin.list_groups(instance)
        self.assertEqual(l, "")

    def test_sigle_group(self):
        instance = MockInstance([MockGroup("alma")])
        l = HostAdmin.list_groups(instance)
        self.assertEqual(l, "alma")

    def test_multiple_groups(self):
        instance = MockInstance([MockGroup("alma"),
36
                                 MockGroup("korte"), MockGroup("szilva")])
37 38
        l = HostAdmin.list_groups(instance)
        self.assertEqual(l, "alma, korte, szilva")