Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Fukász Rómeó Ervin
/
cloud
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
f9fa1c96
authored
Mar 14, 2014
by
Bach Dániel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
dashboard: add new tests
parent
22cdcf0e
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
94 additions
and
1 deletions
+94
-1
circle/dashboard/tests/test_views.py
+92
-0
circle/dashboard/views.py
+2
-1
No files found.
circle/dashboard/tests/test_views.py
View file @
f9fa1c96
...
@@ -360,6 +360,98 @@ class VmDetailTest(LoginMixin, TestCase):
...
@@ -360,6 +360,98 @@ class VmDetailTest(LoginMixin, TestCase):
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
)
def
test_unpermitted_add_tag
(
self
):
c
=
Client
()
self
.
login
(
c
,
"user2"
)
inst
=
Instance
.
objects
.
get
(
pk
=
1
)
inst
.
set_level
(
self
.
u2
,
'user'
)
response
=
c
.
post
(
"/dashboard/vm/1/"
,
{
'new_tag'
:
'test1'
})
self
.
assertEqual
(
response
.
status_code
,
403
)
def
test_permitted_add_tag
(
self
):
c
=
Client
()
self
.
login
(
c
,
"user2"
)
inst
=
Instance
.
objects
.
get
(
pk
=
1
)
inst
.
set_level
(
self
.
u2
,
'owner'
)
tag_count
=
inst
.
tags
.
count
()
response
=
c
.
post
(
"/dashboard/vm/1/"
,
{
'new_tag'
:
'test2'
})
self
.
assertEqual
(
response
.
status_code
,
302
)
self
.
assertEqual
(
inst
.
tags
.
count
(),
tag_count
+
1
)
def
test_permitted_add_tag_w_too_long_or_empty_tag
(
self
):
c
=
Client
()
self
.
login
(
c
,
"user2"
)
inst
=
Instance
.
objects
.
get
(
pk
=
1
)
inst
.
set_level
(
self
.
u2
,
'owner'
)
tag_count
=
inst
.
tags
.
count
()
response
=
c
.
post
(
"/dashboard/vm/1/"
,
{
'new_tag'
:
't'
*
30
})
self
.
assertEqual
(
response
.
status_code
,
302
)
response
=
c
.
post
(
"/dashboard/vm/1/"
,
{
'new_tag'
:
''
})
self
.
assertEqual
(
response
.
status_code
,
302
)
self
.
assertEqual
(
inst
.
tags
.
count
(),
tag_count
)
def
test_unpermitted_remove_tag
(
self
):
c
=
Client
()
self
.
login
(
c
,
"user2"
)
inst
=
Instance
.
objects
.
get
(
pk
=
1
)
inst
.
set_level
(
self
.
u2
,
'user'
)
tag_count
=
inst
.
tags
.
count
()
response
=
c
.
post
(
"/dashboard/vm/1/"
,
{
'to_remove'
:
'test1'
})
self
.
assertEqual
(
response
.
status_code
,
302
)
self
.
assertEqual
(
inst
.
tags
.
count
(),
tag_count
)
def
test_permitted_remove_tag
(
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_tag'
:
'test1'
})
tag_count
=
inst
.
tags
.
count
()
response
=
c
.
post
(
"/dashboard/vm/1/"
,
{
'to_remove'
:
'test1'
})
self
.
assertEqual
(
response
.
status_code
,
302
)
self
.
assertEqual
(
inst
.
tags
.
count
(),
tag_count
-
1
)
def
test_permitted_remove_tag_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_tag'
:
'test1'
})
tag_count
=
inst
.
tags
.
count
()
response
=
c
.
post
(
"/dashboard/vm/1/"
,
{
'to_remove'
:
'test1'
},
HTTP_X_REQUESTED_WITH
=
'XMLHttpRequest'
)
self
.
assertEqual
(
response
.
status_code
,
200
)
self
.
assertEqual
(
inst
.
tags
.
count
(),
tag_count
-
1
)
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
)
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'
)
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'
)
class
VmDetailVncTest
(
LoginMixin
,
TestCase
):
class
VmDetailVncTest
(
LoginMixin
,
TestCase
):
fixtures
=
[
'test-vm-fixture.json'
,
'node.json'
]
fixtures
=
[
'test-vm-fixture.json'
,
'node.json'
]
...
...
circle/dashboard/views.py
View file @
f9fa1c96
...
@@ -364,7 +364,8 @@ class VmDetailView(CheckedDetailView):
...
@@ -364,7 +364,8 @@ class VmDetailView(CheckedDetailView):
except
ValueError
:
except
ValueError
:
error
=
_
(
"There is a problem with your input!"
)
error
=
_
(
"There is a problem with your input!"
)
except
Exception
as
e
:
except
Exception
as
e
:
error
=
u', '
.
join
(
e
.
messages
)
error
=
_
(
"Unknown error."
)
logger
.
error
(
e
)
if
request
.
is_ajax
():
if
request
.
is_ajax
():
pass
pass
...
...
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