Commit 676934d8 by Dudás Ádám

firewall: tests for admin.HostAdmin

parent 2517c6f5
......@@ -20,12 +20,11 @@ class HostAdmin(admin.ModelAdmin):
filter_horizontal = ('groups', )
inlines = (RuleInline, RecordInline)
def groups_l(self, instance):
@staticmethod
def groups_l(instance):
"""Returns instance's groups' names as a comma-separated list."""
retval = []
for group in instance.groups.all():
retval.append(group.name)
return u', '.join(retval)
names = [group.name for group in instance.groups.all()]
return u', '.join(names)
class HostInline(contrib.admin.TabularInline):
model = Host
......
"""
This file demonstrates writing tests using the unittest module. These will
pass when you run "manage.py test".
from django.test import TestCase
from admin import HostAdmin
Replace this with more appropriate tests for your application.
"""
class MockInstance:
def __init__(self, groups):
self.groups = MockGroups(groups)
from django.test import TestCase
class MockGroup:
def __init__(self, name):
self.name = name
class MockGroups:
def __init__(self, groups):
self.groups = groups
def all(self):
return self.groups
class HostAdminNoGroupTestCase(TestCase):
def runTest(self):
instance = MockInstance([])
l = HostAdmin.groups_l(instance)
self.assertEqual(l, "")
class HostAdminSingleGroupTestCase(TestCase):
def runTest(self):
instance = MockInstance([MockGroup("alma")])
l = HostAdmin.groups_l(instance)
self.assertEqual(l, "alma")
class SimpleTest(TestCase):
def test_basic_addition(self):
"""
Tests that 1 + 1 always equals 2.
"""
self.assertEqual(1 + 1, 2)
class HostAdminMultipleGroupsTestCase(TestCase):
def runTest(self):
instance = MockInstance([MockGroup("alma"),
MockGroup("korte"), MockGroup("szilva")])
l = HostAdmin.groups_l(instance)
self.assertEqual(l, "alma, korte, szilva")
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