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
9211165c
authored
Aug 18, 2016
by
Czémán Arnold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
dashboard: fix 'set name' tests
parent
58375aa9
Pipeline
#179
passed with stage
in 0 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
29 additions
and
17 deletions
+29
-17
circle/dashboard/tests/test_views.py
+29
-17
No files found.
circle/dashboard/tests/test_views.py
View file @
9211165c
...
@@ -28,7 +28,7 @@ from dashboard.views import VmAddInterfaceView
...
@@ -28,7 +28,7 @@ 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
,
RemoveInterfaceOperation
,
AddPortOperation
,
RemoveInterfaceOperation
,
DeployOperation
)
DeployOperation
,
RenameOperation
)
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
...
@@ -433,31 +433,43 @@ class VmDetailTest(LoginMixin, MockCeleryMixin, TestCase):
...
@@ -433,31 +433,43 @@ class VmDetailTest(LoginMixin, MockCeleryMixin, TestCase):
def
test_unpermitted_set_name
(
self
):
def
test_unpermitted_set_name
(
self
):
c
=
Client
()
c
=
Client
()
self
.
login
(
c
,
"user2"
)
self
.
login
(
c
,
"user2"
)
inst
=
Instance
.
objects
.
get
(
pk
=
1
)
with
patch
.
object
(
RenameOperation
,
'async'
)
as
mock_method
:
inst
.
set_level
(
self
.
u2
,
'user'
)
inst
=
Instance
.
objects
.
get
(
pk
=
1
)
old_name
=
inst
.
name
mock_method
.
side_effect
=
inst
.
rename
response
=
c
.
post
(
"/dashboard/vm/1/"
,
{
'new_name'
:
'test1235'
})
inst
.
set_level
(
self
.
u2
,
'user'
)
self
.
assertEqual
(
response
.
status_code
,
403
)
old_name
=
inst
.
name
self
.
assertEqual
(
Instance
.
objects
.
get
(
pk
=
1
)
.
name
,
old_name
)
response
=
c
.
post
(
"/dashboard/vm/1/op/rename/"
,
{
'new_name'
:
'test1235'
})
self
.
assertEqual
(
response
.
status_code
,
403
)
assert
not
mock_method
.
called
self
.
assertEqual
(
Instance
.
objects
.
get
(
pk
=
1
)
.
name
,
old_name
)
def
test_permitted_set_name
(
self
):
def
test_permitted_set_name
(
self
):
c
=
Client
()
c
=
Client
()
self
.
login
(
c
,
"user2"
)
self
.
login
(
c
,
"user2"
)
inst
=
Instance
.
objects
.
get
(
pk
=
1
)
with
patch
.
object
(
RenameOperation
,
'async'
)
as
mock_method
:
inst
.
set_level
(
self
.
u2
,
'owner'
)
inst
=
Instance
.
objects
.
get
(
pk
=
1
)
response
=
c
.
post
(
"/dashboard/vm/1/"
,
{
'new_name'
:
'test1234'
})
mock_method
.
side_effect
=
inst
.
rename
self
.
assertEqual
(
response
.
status_code
,
302
)
inst
.
set_level
(
self
.
u2
,
'owner'
)
self
.
assertEqual
(
Instance
.
objects
.
get
(
pk
=
1
)
.
name
,
'test1234'
)
response
=
c
.
post
(
"/dashboard/vm/1/op/rename/"
,
{
'new_name'
:
'test1234'
})
self
.
assertEqual
(
response
.
status_code
,
302
)
assert
mock_method
.
called
self
.
assertEqual
(
Instance
.
objects
.
get
(
pk
=
1
)
.
name
,
'test1234'
)
def
test_permitted_set_name_w_ajax
(
self
):
def
test_permitted_set_name_w_ajax
(
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'
)
with
patch
.
object
(
RenameOperation
,
'async'
)
as
mock_method
:
response
=
c
.
post
(
"/dashboard/vm/1/"
,
{
'new_name'
:
'test123'
},
inst
.
set_level
(
self
.
u2
,
'owner'
)
HTTP_X_REQUESTED_WITH
=
'XMLHttpRequest'
)
mock_method
.
side_effect
=
inst
.
rename
self
.
assertEqual
(
response
.
status_code
,
200
)
response
=
c
.
post
(
"/dashboard/vm/1/op/rename/"
,
self
.
assertEqual
(
Instance
.
objects
.
get
(
pk
=
1
)
.
name
,
'test123'
)
{
'new_name'
:
'test123'
},
HTTP_X_REQUESTED_WITH
=
'XMLHttpRequest'
)
self
.
assertEqual
(
response
.
status_code
,
200
)
assert
mock_method
.
called
self
.
assertEqual
(
Instance
.
objects
.
get
(
pk
=
1
)
.
name
,
'test123'
)
def
test_permitted_wake_up_wrong_state
(
self
):
def
test_permitted_wake_up_wrong_state
(
self
):
c
=
Client
()
c
=
Client
()
...
...
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