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
98bc31aa
authored
Feb 28, 2014
by
Bach Dániel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
firewall: create test for firewall.models.Vlan.get_new_address
fixes #17
parent
af581ee6
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
47 additions
and
1 deletions
+47
-1
circle/firewall/tests/__init__.py
+0
-0
circle/firewall/tests/test_firewall.py
+47
-1
No files found.
circle/firewall/tests/__init__.py
0 → 100644
View file @
98bc31aa
circle/firewall/tests/test_firewall.py
View file @
98bc31aa
from
django.test
import
TestCase
from
admin
import
HostAdmin
from
django.contrib.auth.models
import
User
from
..admin
import
HostAdmin
from
firewall.models
import
Vlan
,
Domain
,
Host
from
django.forms
import
ValidationError
class
MockInstance
:
...
...
@@ -36,3 +39,46 @@ class HostAdminTestCase(TestCase):
MockGroup
(
"korte"
),
MockGroup
(
"szilva"
)])
l
=
HostAdmin
.
list_groups
(
instance
)
self
.
assertEqual
(
l
,
"alma, korte, szilva"
)
class
GetNewAddressTestCase
(
TestCase
):
def
setUp
(
self
):
self
.
u1
=
User
.
objects
.
create
(
username
=
'user1'
)
self
.
u1
.
save
()
d
=
Domain
(
name
=
'example.org'
,
owner
=
self
.
u1
)
d
.
save
()
# /29 = .1-.6 = 6 hosts/subnet + broadcast + network id
self
.
vlan
=
Vlan
(
vid
=
1
,
name
=
'test'
,
network4
=
'10.0.0.0/29'
,
network6
=
'2001:738:2001:4031::/80'
,
domain
=
d
,
owner
=
self
.
u1
)
self
.
vlan
.
save
()
self
.
vlan
.
host_set
.
all
()
.
delete
()
for
i
in
[
1
]
+
range
(
3
,
6
):
Host
(
hostname
=
'h-
%
d'
%
i
,
mac
=
'01:02:03:04:05:
%02
d'
%
i
,
ipv4
=
'10.0.0.
%
d'
%
i
,
vlan
=
self
.
vlan
,
owner
=
self
.
u1
)
.
save
()
def
test_new_addr_w_empty_vlan
(
self
):
self
.
vlan
.
host_set
.
all
()
.
delete
()
self
.
vlan
.
get_new_address
()
def
test_all_addr_in_use
(
self
):
for
i
in
(
2
,
6
):
Host
(
hostname
=
'h-
%
d'
%
i
,
mac
=
'01:02:03:04:05:
%02
d'
%
i
,
ipv4
=
'10.0.0.
%
d'
%
i
,
vlan
=
self
.
vlan
,
owner
=
self
.
u1
)
.
save
()
self
.
assertRaises
(
ValidationError
,
self
.
vlan
.
get_new_address
)
def
test_all_addr_in_use_w_ipv6
(
self
):
Host
(
hostname
=
'h-x'
,
mac
=
'01:02:03:04:05:06'
,
ipv4
=
'10.0.0.6'
,
ipv6
=
'2001:738:2001:4031:0:0:2:0'
,
vlan
=
self
.
vlan
,
owner
=
self
.
u1
)
.
save
()
self
.
assertRaises
(
ValidationError
,
self
.
vlan
.
get_new_address
)
def
test_new_addr_last
(
self
):
self
.
assertEqual
(
self
.
vlan
.
get_new_address
()[
'ipv4'
],
'10.0.0.6'
)
def
test_new_addr_w_overflow
(
self
):
Host
(
hostname
=
'h-6'
,
mac
=
'01:02:03:04:05:06'
,
ipv4
=
'10.0.0.6'
,
vlan
=
self
.
vlan
,
owner
=
self
.
u1
)
.
save
()
self
.
assertEqual
(
self
.
vlan
.
get_new_address
()[
'ipv4'
],
'10.0.0.2'
)
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