Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Gelencsér Szabolcs
/
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
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
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
from
vm.models
import
Instance
,
InstanceTemplate
,
Lease
,
Node
,
Trait
from
vm.operations
import
(
WakeUpOperation
,
AddInterfaceOperation
,
AddPortOperation
,
RemoveInterfaceOperation
,
DeployOperation
)
DeployOperation
,
RenameOperation
)
from
..models
import
Profile
from
firewall.models
import
Vlan
,
Host
,
VlanGroup
from
mock
import
Mock
,
patch
...
...
@@ -433,31 +433,43 @@ class VmDetailTest(LoginMixin, MockCeleryMixin, TestCase):
def
test_unpermitted_set_name
(
self
):
c
=
Client
()
self
.
login
(
c
,
"user2"
)
inst
=
Instance
.
objects
.
get
(
pk
=
1
)
inst
.
set_level
(
self
.
u2
,
'user'
)
old_name
=
inst
.
name
response
=
c
.
post
(
"/dashboard/vm/1/"
,
{
'new_name'
:
'test1235'
})
self
.
assertEqual
(
response
.
status_code
,
403
)
self
.
assertEqual
(
Instance
.
objects
.
get
(
pk
=
1
)
.
name
,
old_name
)
with
patch
.
object
(
RenameOperation
,
'async'
)
as
mock_method
:
inst
=
Instance
.
objects
.
get
(
pk
=
1
)
mock_method
.
side_effect
=
inst
.
rename
inst
.
set_level
(
self
.
u2
,
'user'
)
old_name
=
inst
.
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
):
c
=
Client
()
self
.
login
(
c
,
"user2"
)
inst
=
Instance
.
objects
.
get
(
pk
=
1
)
inst
.
set_level
(
self
.
u2
,
'owner'
)
response
=
c
.
post
(
"/dashboard/vm/1/"
,
{
'new_name'
:
'test1234'
})
self
.
assertEqual
(
response
.
status_code
,
302
)
self
.
assertEqual
(
Instance
.
objects
.
get
(
pk
=
1
)
.
name
,
'test1234'
)
with
patch
.
object
(
RenameOperation
,
'async'
)
as
mock_method
:
inst
=
Instance
.
objects
.
get
(
pk
=
1
)
mock_method
.
side_effect
=
inst
.
rename
inst
.
set_level
(
self
.
u2
,
'owner'
)
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
):
c
=
Client
()
self
.
login
(
c
,
"user2"
)
inst
=
Instance
.
objects
.
get
(
pk
=
1
)
inst
.
set_level
(
self
.
u2
,
'owner'
)
response
=
c
.
post
(
"/dashboard/vm/1/"
,
{
'new_name'
:
'test123'
},
HTTP_X_REQUESTED_WITH
=
'XMLHttpRequest'
)
self
.
assertEqual
(
response
.
status_code
,
200
)
self
.
assertEqual
(
Instance
.
objects
.
get
(
pk
=
1
)
.
name
,
'test123'
)
with
patch
.
object
(
RenameOperation
,
'async'
)
as
mock_method
:
inst
.
set_level
(
self
.
u2
,
'owner'
)
mock_method
.
side_effect
=
inst
.
rename
response
=
c
.
post
(
"/dashboard/vm/1/op/rename/"
,
{
'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
):
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