Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Gelencsér Szabolcs
/
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
68e773fe
authored
Aug 29, 2014
by
Őry Máté
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
dashboard: add tests
parent
6d848036
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
122 additions
and
1 deletions
+122
-1
circle/common/models.py
+13
-0
circle/dashboard/tests/test_mockedviews.py
+109
-1
No files found.
circle/common/models.py
View file @
68e773fe
...
...
@@ -497,6 +497,19 @@ class HumanReadableException(HumanReadableObject, Exception):
def
fetch_human_exception
(
exception
,
user
=
None
):
"""Fetch user readable message from exception.
>>> r = humanize_exception("foo", Exception())
>>> fetch_human_exception(r, User())
u'foo'
>>> fetch_human_exception(r).get_text(User())
u'foo'
>>> fetch_human_exception(Exception(), User())
u'Unknown error'
>>> fetch_human_exception(PermissionDenied(), User())
u'Permission Denied'
"""
if
not
isinstance
(
exception
,
HumanReadableException
):
if
isinstance
(
exception
,
PermissionDenied
):
exception
=
create_readable
(
ugettext_noop
(
"Permission Denied"
))
...
...
circle/dashboard/tests/test_mockedviews.py
View file @
68e773fe
...
...
@@ -29,7 +29,7 @@ from django.utils import baseconv
from
..models
import
Profile
from
..views
import
InstanceActivityDetail
,
InstanceActivity
from
..views
import
vm_ops
,
Instance
,
UnsubscribeFormView
from
..views
import
vm_ops
,
vm_mass_ops
,
Instance
,
UnsubscribeFormView
from
..views
import
AclUpdateView
from
..
import
views
...
...
@@ -259,6 +259,114 @@ class VmOperationViewTestCase(unittest.TestCase):
self
.
assertEquals
(
rend
.
status_code
,
200
)
class
VmMassOperationViewTestCase
(
unittest
.
TestCase
):
def
test_available
(
self
):
request
=
FakeRequestFactory
(
superuser
=
True
)
view
=
vm_mass_ops
[
'destroy'
]
with
patch
.
object
(
view
,
'get_object'
)
as
go
:
inst
=
MagicMock
(
spec
=
Instance
)
inst
.
_meta
.
object_name
=
"Instance"
inst
.
destroy
=
Instance
.
_ops
[
'destroy'
](
inst
)
go
.
return_value
=
[
inst
]
self
.
assertEquals
(
view
.
as_view
()(
request
,
pk
=
1234
)
.
render
()
.
status_code
,
200
)
def
test_unpermitted_choice
(
self
):
"User has user level, but not the needed ownership."
request
=
FakeRequestFactory
()
view
=
vm_mass_ops
[
'destroy'
]
with
patch
.
object
(
view
,
'get_object'
)
as
go
:
inst
=
MagicMock
(
spec
=
Instance
)
inst
.
_meta
.
object_name
=
"Instance"
inst
.
has_level
=
lambda
self
,
l
:
{
"user"
:
True
,
"owner"
:
False
}[
l
]
inst
.
destroy
=
Instance
.
_ops
[
'destroy'
](
inst
)
inst
.
destroy
.
_operate
=
MagicMock
()
go
.
return_value
=
[
inst
]
view
.
as_view
()(
request
,
pk
=
1234
)
.
render
()
assert
not
inst
.
destroy
.
_operate
.
called
def
test_unpermitted
(
self
):
request
=
FakeRequestFactory
()
view
=
vm_mass_ops
[
'destroy'
]
with
patch
.
object
(
view
,
'get_object'
)
as
go
:
inst
=
MagicMock
(
spec
=
Instance
)
inst
.
_meta
.
object_name
=
"Instance"
inst
.
destroy
=
Instance
.
_ops
[
'destroy'
](
inst
)
inst
.
has_level
.
return_value
=
False
go
.
return_value
=
[
inst
]
with
self
.
assertRaises
(
PermissionDenied
):
view
.
as_view
()(
request
,
pk
=
1234
)
.
render
()
def
test_migrate
(
self
):
request
=
FakeRequestFactory
(
POST
=
{
'node'
:
1
},
superuser
=
True
)
view
=
vm_mass_ops
[
'migrate'
]
with
patch
.
object
(
view
,
'get_object'
)
as
go
,
\
patch
(
'dashboard.views.messages'
)
as
msg
,
\
patch
(
'dashboard.views.get_object_or_404'
)
as
go4
:
inst
=
MagicMock
(
spec
=
Instance
)
inst
.
_meta
.
object_name
=
"Instance"
inst
.
migrate
=
Instance
.
_ops
[
'migrate'
](
inst
)
inst
.
migrate
.
async
=
MagicMock
()
inst
.
has_level
.
return_value
=
True
go
.
return_value
=
[
inst
]
go4
.
return_value
=
MagicMock
()
assert
view
.
as_view
()(
request
,
pk
=
1234
)[
'location'
]
assert
not
msg
.
error
.
called
def
test_migrate_failed
(
self
):
request
=
FakeRequestFactory
(
POST
=
{
'node'
:
1
},
superuser
=
True
)
view
=
vm_mass_ops
[
'migrate'
]
with
patch
.
object
(
view
,
'get_object'
)
as
go
,
\
patch
(
'dashboard.views.messages'
)
as
msg
,
\
patch
(
'dashboard.views.get_object_or_404'
)
as
go4
:
inst
=
MagicMock
(
spec
=
Instance
)
inst
.
_meta
.
object_name
=
"Instance"
inst
.
migrate
=
Instance
.
_ops
[
'migrate'
](
inst
)
inst
.
migrate
.
async
=
MagicMock
()
inst
.
migrate
.
async
.
side_effect
=
Exception
inst
.
has_level
.
return_value
=
True
go
.
return_value
=
[
inst
]
go4
.
return_value
=
MagicMock
()
assert
view
.
as_view
()(
request
,
pk
=
1234
)[
'location'
]
assert
msg
.
error
.
called
def
test_migrate_wo_permission
(
self
):
request
=
FakeRequestFactory
(
POST
=
{
'node'
:
1
},
superuser
=
False
)
view
=
vm_mass_ops
[
'migrate'
]
with
patch
.
object
(
view
,
'get_object'
)
as
go
,
\
patch
(
'dashboard.views.get_object_or_404'
)
as
go4
:
inst
=
MagicMock
(
spec
=
Instance
)
inst
.
_meta
.
object_name
=
"Instance"
inst
.
migrate
=
Instance
.
_ops
[
'migrate'
](
inst
)
inst
.
migrate
.
async
=
MagicMock
()
inst
.
has_level
.
return_value
=
True
go
.
return_value
=
[
inst
]
go4
.
return_value
=
MagicMock
()
with
self
.
assertRaises
(
PermissionDenied
):
assert
view
.
as_view
()(
request
,
pk
=
1234
)[
'location'
]
def
test_migrate_template
(
self
):
"""check if GET dialog's template can be rendered"""
request
=
FakeRequestFactory
(
superuser
=
True
)
view
=
vm_mass_ops
[
'migrate'
]
with
patch
.
object
(
view
,
'get_object'
)
as
go
:
inst
=
MagicMock
(
spec
=
Instance
)
inst
.
_meta
.
object_name
=
"Instance"
inst
.
migrate
=
Instance
.
_ops
[
'migrate'
](
inst
)
inst
.
has_level
.
return_value
=
True
go
.
return_value
=
[
inst
]
self
.
assertEquals
(
view
.
as_view
()(
request
,
pk
=
1234
)
.
render
()
.
status_code
,
200
)
class
RenewViewTest
(
unittest
.
TestCase
):
def
test_renew_template
(
self
):
...
...
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