Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Gutyán Gábor
/
circlestack
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
ce298394
authored
Mar 14, 2014
by
Bach Dániel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
dashboard: create tests for __add_port()
parent
af6220f5
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
68 additions
and
1 deletions
+68
-1
circle/dashboard/fixtures/test-vm-fixture.json
+9
-0
circle/dashboard/tests/test_views.py
+59
-1
No files found.
circle/dashboard/fixtures/test-vm-fixture.json
View file @
ce298394
...
...
@@ -1231,6 +1231,15 @@
}
},
{
"pk"
:
1366
,
"model"
:
"auth.permission"
,
"fields"
:
{
"codename"
:
"config_ports"
,
"name"
:
"Can configure port forwards."
,
"content_type"
:
28
}
},
{
"pk"
:
1
,
"model"
:
"auth.group"
,
"fields"
:
{
...
...
circle/dashboard/tests/test_views.py
View file @
ce298394
...
...
@@ -2,13 +2,17 @@ from django.test import TestCase
from
django.test.client
import
Client
from
django.contrib.auth.models
import
User
,
Group
from
django.core.exceptions
import
SuspiciousOperation
from
django.contrib.auth.models
import
Permission
from
vm.models
import
Instance
,
InstanceTemplate
,
Lease
,
Node
from
..models
import
Profile
from
storage.models
import
Disk
from
firewall.models
import
Vlan
from
firewall.models
import
Vlan
,
Host
,
VlanGroup
from
mock
import
Mock
import
django.conf
settings
=
django
.
conf
.
settings
.
FIREWALL_SETTINGS
class
LoginMixin
(
object
):
def
login
(
self
,
client
,
username
,
password
=
'password'
):
...
...
@@ -35,6 +39,8 @@ class VmDetailTest(LoginMixin, TestCase):
self
.
g1
.
user_set
.
add
(
self
.
u1
)
self
.
g1
.
user_set
.
add
(
self
.
u2
)
self
.
g1
.
save
()
settings
[
"default_vlangroup"
]
=
'public'
VlanGroup
.
objects
.
create
(
name
=
'public'
)
def
tearDown
(
self
):
super
(
VmDetailTest
,
self
)
.
tearDown
()
...
...
@@ -282,6 +288,58 @@ class VmDetailTest(LoginMixin, TestCase):
self
.
assertEqual
(
response
.
status_code
,
200
)
assert
self
.
u1
.
notification_set
.
get
()
.
status
==
'read'
def
test_unpermitted_add_port_wo_config_ports_perm
(
self
):
c
=
Client
()
self
.
login
(
c
,
"user2"
)
inst
=
Instance
.
objects
.
get
(
pk
=
1
)
inst
.
set_level
(
self
.
u2
,
'owner'
)
response
=
c
.
post
(
"/dashboard/vm/1/"
,
{
'port'
:
True
,
'proto'
:
'tcp'
,
'port'
:
'1337'
})
self
.
assertEqual
(
response
.
status_code
,
403
)
def
test_unpermitted_add_port_wo_obj_levels
(
self
):
c
=
Client
()
self
.
login
(
c
,
"user2"
)
self
.
u2
.
user_permissions
.
add
(
Permission
.
objects
.
get
(
name
=
'Can configure port forwards.'
))
response
=
c
.
post
(
"/dashboard/vm/1/"
,
{
'port'
:
True
,
'proto'
:
'tcp'
,
'port'
:
'1337'
})
self
.
assertEqual
(
response
.
status_code
,
403
)
def
test_unpermitted_add_port_w_bad_host
(
self
):
c
=
Client
()
self
.
login
(
c
,
"user2"
)
inst
=
Instance
.
objects
.
get
(
pk
=
1
)
inst
.
set_level
(
self
.
u2
,
'owner'
)
self
.
u2
.
user_permissions
.
add
(
Permission
.
objects
.
get
(
name
=
'Can configure port forwards.'
))
response
=
c
.
post
(
"/dashboard/vm/1/"
,
{
'proto'
:
'tcp'
,
'host_pk'
:
'9999'
,
'port'
:
'1337'
})
self
.
assertEqual
(
response
.
status_code
,
403
)
def
test_permitted_add_port
(
self
):
c
=
Client
()
self
.
login
(
c
,
"user2"
)
inst
=
Instance
.
objects
.
get
(
pk
=
1
)
inst
.
set_level
(
self
.
u2
,
'owner'
)
vlan
=
Vlan
.
objects
.
get
(
id
=
1
)
vlan
.
set_level
(
self
.
u2
,
'user'
)
response
=
c
.
post
(
"/dashboard/vm/1/"
,
{
'new_network_vlan'
:
1
})
host
=
Host
.
objects
.
get
(
interface__in
=
inst
.
interface_set
.
all
())
self
.
u2
.
user_permissions
.
add
(
Permission
.
objects
.
get
(
name
=
'Can configure port forwards.'
))
port_count
=
len
(
host
.
list_ports
())
response
=
c
.
post
(
"/dashboard/vm/1/"
,
{
'proto'
:
'tcp'
,
'host_pk'
:
host
.
pk
,
'port'
:
'1337'
})
self
.
assertEqual
(
response
.
status_code
,
302
)
self
.
assertEqual
(
len
(
host
.
list_ports
()),
port_count
+
1
)
class
VmDetailVncTest
(
LoginMixin
,
TestCase
):
fixtures
=
[
'test-vm-fixture.json'
,
'node.json'
]
...
...
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