Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
CIRCLE
/
cloud
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
94
Merge Requests
10
Pipelines
Wiki
Snippets
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
Hide 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):
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
...
...
firewall/tests.py
View file @
676934d8
"""
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"
)
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