Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Gelencsér Szabolcs
/
cloud
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
676934d8
authored
Feb 14, 2013
by
Dudás Ádám
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
firewall: tests for admin.HostAdmin
parent
2517c6f5
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
36 additions
and
17 deletions
+36
-17
firewall/admin.py
+4
-5
firewall/tests.py
+32
-12
No files found.
firewall/admin.py
View file @
676934d8
...
@@ -20,12 +20,11 @@ class HostAdmin(admin.ModelAdmin):
...
@@ -20,12 +20,11 @@ class HostAdmin(admin.ModelAdmin):
filter_horizontal
=
(
'groups'
,
)
filter_horizontal
=
(
'groups'
,
)
inlines
=
(
RuleInline
,
RecordInline
)
inlines
=
(
RuleInline
,
RecordInline
)
def
groups_l
(
self
,
instance
):
@staticmethod
def
groups_l
(
instance
):
"""Returns instance's groups' names as a comma-separated list."""
"""Returns instance's groups' names as a comma-separated list."""
retval
=
[]
names
=
[
group
.
name
for
group
in
instance
.
groups
.
all
()]
for
group
in
instance
.
groups
.
all
():
return
u', '
.
join
(
names
)
retval
.
append
(
group
.
name
)
return
u', '
.
join
(
retval
)
class
HostInline
(
contrib
.
admin
.
TabularInline
):
class
HostInline
(
contrib
.
admin
.
TabularInline
):
model
=
Host
model
=
Host
...
...
firewall/tests.py
View file @
676934d8
"""
from
django.test
import
TestCase
This file demonstrates writing tests using the unittest module. These will
from
admin
import
HostAdmin
pass when you run "manage.py test".
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
):
class
HostAdminMultipleGroupsTestCase
(
TestCase
):
def
test_basic_addition
(
self
):
def
runTest
(
self
):
"""
instance
=
MockInstance
([
MockGroup
(
"alma"
),
Tests that 1 + 1 always equals 2.
MockGroup
(
"korte"
),
MockGroup
(
"szilva"
)])
"""
l
=
HostAdmin
.
groups_l
(
instance
)
self
.
assertEqual
(
1
+
1
,
2
)
self
.
assertEqual
(
l
,
"alma, korte, szilva"
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment