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
6da29f4e
authored
Oct 20, 2014
by
Bach Dániel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
dashboard: fix tests
parent
6a9390f9
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
33 additions
and
33 deletions
+33
-33
circle/dashboard/tests/test_views.py
+33
-33
No files found.
circle/dashboard/tests/test_views.py
View file @
6da29f4e
...
@@ -26,7 +26,8 @@ from django.contrib.auth import authenticate
...
@@ -26,7 +26,8 @@ from django.contrib.auth import authenticate
from
dashboard.views
import
VmAddInterfaceView
from
dashboard.views
import
VmAddInterfaceView
from
vm.models
import
Instance
,
InstanceTemplate
,
Lease
,
Node
,
Trait
from
vm.models
import
Instance
,
InstanceTemplate
,
Lease
,
Node
,
Trait
from
vm.operations
import
WakeUpOperation
,
AddInterfaceOperation
from
vm.operations
import
(
WakeUpOperation
,
AddInterfaceOperation
,
AddPortOperation
)
from
..models
import
Profile
from
..models
import
Profile
from
firewall.models
import
Vlan
,
Host
,
VlanGroup
from
firewall.models
import
Vlan
,
Host
,
VlanGroup
from
mock
import
Mock
,
patch
from
mock
import
Mock
,
patch
...
@@ -335,51 +336,48 @@ class VmDetailTest(LoginMixin, TestCase):
...
@@ -335,51 +336,48 @@ class VmDetailTest(LoginMixin, TestCase):
self
.
login
(
c
,
"user2"
)
self
.
login
(
c
,
"user2"
)
inst
=
Instance
.
objects
.
get
(
pk
=
1
)
inst
=
Instance
.
objects
.
get
(
pk
=
1
)
inst
.
set_level
(
self
.
u2
,
'owner'
)
inst
.
set_level
(
self
.
u2
,
'owner'
)
response
=
c
.
post
(
"/dashboard/vm/1/"
,
{
'port'
:
True
,
vlan
=
Vlan
.
objects
.
get
(
id
=
1
)
'proto'
:
'tcp'
,
vlan
.
set_level
(
self
.
u2
,
'user'
)
'port'
:
'1337'
})
inst
.
add_interface
(
user
=
self
.
u2
,
vlan
=
vlan
)
host
=
Host
.
objects
.
get
(
interface__in
=
inst
.
interface_set
.
all
())
with
patch
.
object
(
AddPortOperation
,
'async'
)
as
mock_method
:
mock_method
.
side_effect
=
inst
.
add_port
response
=
c
.
post
(
"/dashboard/vm/1/op/add_port/"
,
{
'proto'
:
'tcp'
,
'host'
:
host
.
pk
,
'port'
:
'1337'
})
self
.
assertEqual
(
response
.
status_code
,
403
)
self
.
assertEqual
(
response
.
status_code
,
403
)
def
test_unpermitted_add_port_wo_obj_levels
(
self
):
def
test_unpermitted_add_port_wo_obj_levels
(
self
):
c
=
Client
()
c
=
Client
()
self
.
login
(
c
,
"user2"
)
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
=
Instance
.
objects
.
get
(
pk
=
1
)
inst
.
set_level
(
self
.
u2
,
'owner'
)
vlan
=
Vlan
.
objects
.
get
(
id
=
1
)
vlan
.
set_level
(
self
.
u2
,
'user'
)
inst
.
add_interface
(
user
=
self
.
u2
,
vlan
=
vlan
,
system
=
True
)
host
=
Host
.
objects
.
get
(
interface__in
=
inst
.
interface_set
.
all
())
self
.
u2
.
user_permissions
.
add
(
Permission
.
objects
.
get
(
self
.
u2
.
user_permissions
.
add
(
Permission
.
objects
.
get
(
name
=
'Can configure port forwards.'
))
name
=
'Can configure port forwards.'
))
response
=
c
.
post
(
"/dashboard/vm/1/"
,
{
'proto'
:
'tcp'
,
with
patch
.
object
(
AddPortOperation
,
'async'
)
as
mock_method
:
'host_pk'
:
'9999'
,
mock_method
.
side_effect
=
inst
.
add_port
'port'
:
'1337'
})
response
=
c
.
post
(
"/dashboard/vm/1/op/add_port/"
,
{
'proto'
:
'tcp'
,
'host'
:
host
.
pk
,
'port'
:
'1337'
})
assert
not
mock_method
.
called
self
.
assertEqual
(
response
.
status_code
,
403
)
self
.
assertEqual
(
response
.
status_code
,
403
)
def
test_
permitted_add_port_w_unhandled_exception
(
self
):
def
test_
unpermitted_add_port_w_bad_host
(
self
):
c
=
Client
()
c
=
Client
()
self
.
login
(
c
,
"user2"
)
self
.
login
(
c
,
"user2"
)
inst
=
Instance
.
objects
.
get
(
pk
=
1
)
inst
=
Instance
.
objects
.
get
(
pk
=
1
)
inst
.
set_level
(
self
.
u2
,
'owner'
)
inst
.
set_level
(
self
.
u2
,
'owner'
)
vlan
=
Vlan
.
objects
.
get
(
id
=
1
)
vlan
.
set_level
(
self
.
u2
,
'user'
)
inst
.
add_interface
(
user
=
self
.
u2
,
vlan
=
vlan
)
host
=
Host
.
objects
.
get
(
interface__in
=
inst
.
interface_set
.
all
())
self
.
u2
.
user_permissions
.
add
(
Permission
.
objects
.
get
(
self
.
u2
.
user_permissions
.
add
(
Permission
.
objects
.
get
(
name
=
'Can configure port forwards.'
))
name
=
'Can configure port forwards.'
))
port_count
=
len
(
host
.
list_ports
())
with
patch
.
object
(
AddPortOperation
,
'async'
)
as
mock_method
:
response
=
c
.
post
(
"/dashboard/vm/1/"
,
{
'proto'
:
'tcp'
,
mock_method
.
side_effect
=
inst
.
add_port
'host_pk'
:
host
.
pk
,
response
=
c
.
post
(
"/dashboard/vm/1/op/add_port/"
,
{
'port'
:
'invalid_port
'
})
'proto'
:
'tcp'
,
'host'
:
'9999'
,
'port'
:
'1337
'
})
self
.
assertEqual
(
response
.
status_code
,
302
)
assert
not
mock_method
.
called
self
.
assertEqual
(
len
(
host
.
list_ports
()),
port_count
)
self
.
assertEqual
(
response
.
status_code
,
200
)
def
test_permitted_add_port
(
self
):
def
test_permitted_add_port
(
self
):
c
=
Client
()
c
=
Client
()
...
@@ -394,9 +392,11 @@ class VmDetailTest(LoginMixin, TestCase):
...
@@ -394,9 +392,11 @@ class VmDetailTest(LoginMixin, TestCase):
self
.
u2
.
user_permissions
.
add
(
Permission
.
objects
.
get
(
self
.
u2
.
user_permissions
.
add
(
Permission
.
objects
.
get
(
name
=
'Can configure port forwards.'
))
name
=
'Can configure port forwards.'
))
port_count
=
len
(
host
.
list_ports
())
port_count
=
len
(
host
.
list_ports
())
response
=
c
.
post
(
"/dashboard/vm/1/"
,
{
'proto'
:
'tcp'
,
with
patch
.
object
(
AddPortOperation
,
'async'
)
as
mock_method
:
'host_pk'
:
host
.
pk
,
mock_method
.
side_effect
=
inst
.
add_port
'port'
:
'1337'
})
response
=
c
.
post
(
"/dashboard/vm/1/op/add_port/"
,
{
'proto'
:
'tcp'
,
'host'
:
host
.
pk
,
'port'
:
'1337'
})
assert
mock_method
.
called
self
.
assertEqual
(
response
.
status_code
,
302
)
self
.
assertEqual
(
response
.
status_code
,
302
)
self
.
assertEqual
(
len
(
host
.
list_ports
()),
port_count
+
1
)
self
.
assertEqual
(
len
(
host
.
list_ports
()),
port_count
+
1
)
...
...
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