Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Gyuricska Milán
/
cloud
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
0261e9b2
authored
Jul 27, 2014
by
Bach Dániel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
dashboard: fix tests
parent
b663400a
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
10 deletions
+23
-10
circle/dashboard/tests/test_views.py
+23
-10
No files found.
circle/dashboard/tests/test_views.py
View file @
0261e9b2
...
@@ -24,8 +24,9 @@ from django.contrib.auth.models import User, Group
...
@@ -24,8 +24,9 @@ from django.contrib.auth.models import User, Group
from
django.contrib.auth.models
import
Permission
from
django.contrib.auth.models
import
Permission
from
django.contrib.auth
import
authenticate
from
django.contrib.auth
import
authenticate
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
from
vm.operations
import
WakeUpOperation
,
AddInterfaceOperation
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
...
@@ -168,7 +169,8 @@ class VmDetailTest(LoginMixin, TestCase):
...
@@ -168,7 +169,8 @@ class VmDetailTest(LoginMixin, TestCase):
def
test_unpermitted_network_add_wo_perm
(
self
):
def
test_unpermitted_network_add_wo_perm
(
self
):
c
=
Client
()
c
=
Client
()
self
.
login
(
c
,
"user2"
)
self
.
login
(
c
,
"user2"
)
response
=
c
.
post
(
"/dashboard/vm/1/"
,
{
'new_network_vlan'
:
1
})
response
=
c
.
post
(
"/dashboard/vm/1/op/add_interface/"
,
{
'vlan'
:
1
})
self
.
assertEqual
(
response
.
status_code
,
403
)
self
.
assertEqual
(
response
.
status_code
,
403
)
def
test_unpermitted_network_add_wo_vlan_perm
(
self
):
def
test_unpermitted_network_add_wo_vlan_perm
(
self
):
...
@@ -176,8 +178,18 @@ class VmDetailTest(LoginMixin, TestCase):
...
@@ -176,8 +178,18 @@ 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/"
,
{
'new_network_vlan'
:
1
})
interface_count
=
inst
.
interface_set
.
count
()
self
.
assertEqual
(
response
.
status_code
,
403
)
with
patch
.
object
(
AddInterfaceOperation
,
'async'
)
as
async
:
async
.
side_effect
=
inst
.
add_interface
.
call
with
patch
.
object
(
VmAddInterfaceView
,
'get_form_kwargs'
,
autospec
=
True
)
as
get_form_kwargs
:
get_form_kwargs
.
return_value
=
{
'choices'
:
Vlan
.
objects
.
all
()}
response
=
c
.
post
(
"/dashboard/vm/1/op/add_interface/"
,
{
'vlan'
:
1
})
self
.
assertEqual
(
response
.
status_code
,
302
)
assert
async
.
called
self
.
assertEqual
(
inst
.
interface_set
.
count
(),
interface_count
)
def
test_permitted_network_add
(
self
):
def
test_permitted_network_add
(
self
):
c
=
Client
()
c
=
Client
()
...
@@ -187,9 +199,12 @@ class VmDetailTest(LoginMixin, TestCase):
...
@@ -187,9 +199,12 @@ class VmDetailTest(LoginMixin, TestCase):
vlan
=
Vlan
.
objects
.
get
(
id
=
1
)
vlan
=
Vlan
.
objects
.
get
(
id
=
1
)
vlan
.
set_level
(
self
.
u1
,
'user'
)
vlan
.
set_level
(
self
.
u1
,
'user'
)
interface_count
=
inst
.
interface_set
.
count
()
interface_count
=
inst
.
interface_set
.
count
()
response
=
c
.
post
(
"/dashboard/vm/1/"
,
with
patch
.
object
(
AddInterfaceOperation
,
'async'
)
as
mock_method
:
{
'new_network_vlan'
:
1
})
mock_method
.
side_effect
=
inst
.
add_interface
response
=
c
.
post
(
"/dashboard/vm/1/op/add_interface/"
,
{
'vlan'
:
1
})
self
.
assertEqual
(
response
.
status_code
,
302
)
self
.
assertEqual
(
response
.
status_code
,
302
)
assert
mock_method
.
called
self
.
assertEqual
(
inst
.
interface_set
.
count
(),
interface_count
+
1
)
self
.
assertEqual
(
inst
.
interface_set
.
count
(),
interface_count
+
1
)
def
test_permitted_network_delete
(
self
):
def
test_permitted_network_delete
(
self
):
...
@@ -401,8 +416,7 @@ class VmDetailTest(LoginMixin, TestCase):
...
@@ -401,8 +416,7 @@ class VmDetailTest(LoginMixin, TestCase):
inst
.
set_level
(
self
.
u2
,
'owner'
)
inst
.
set_level
(
self
.
u2
,
'owner'
)
vlan
=
Vlan
.
objects
.
get
(
id
=
1
)
vlan
=
Vlan
.
objects
.
get
(
id
=
1
)
vlan
.
set_level
(
self
.
u2
,
'user'
)
vlan
.
set_level
(
self
.
u2
,
'user'
)
response
=
c
.
post
(
"/dashboard/vm/1/"
,
inst
.
add_interface
(
user
=
self
.
u2
,
vlan
=
vlan
)
{
'new_network_vlan'
:
1
})
host
=
Host
.
objects
.
get
(
host
=
Host
.
objects
.
get
(
interface__in
=
inst
.
interface_set
.
all
())
interface__in
=
inst
.
interface_set
.
all
())
self
.
u2
.
user_permissions
.
add
(
Permission
.
objects
.
get
(
self
.
u2
.
user_permissions
.
add
(
Permission
.
objects
.
get
(
...
@@ -421,8 +435,7 @@ class VmDetailTest(LoginMixin, TestCase):
...
@@ -421,8 +435,7 @@ class VmDetailTest(LoginMixin, TestCase):
inst
.
set_level
(
self
.
u2
,
'owner'
)
inst
.
set_level
(
self
.
u2
,
'owner'
)
vlan
=
Vlan
.
objects
.
get
(
id
=
1
)
vlan
=
Vlan
.
objects
.
get
(
id
=
1
)
vlan
.
set_level
(
self
.
u2
,
'user'
)
vlan
.
set_level
(
self
.
u2
,
'user'
)
response
=
c
.
post
(
"/dashboard/vm/1/"
,
inst
.
add_interface
(
user
=
self
.
u2
,
vlan
=
vlan
)
{
'new_network_vlan'
:
1
})
host
=
Host
.
objects
.
get
(
host
=
Host
.
objects
.
get
(
interface__in
=
inst
.
interface_set
.
all
())
interface__in
=
inst
.
interface_set
.
all
())
self
.
u2
.
user_permissions
.
add
(
Permission
.
objects
.
get
(
self
.
u2
.
user_permissions
.
add
(
Permission
.
objects
.
get
(
...
...
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