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
15251ae3
authored
Apr 18, 2014
by
Őry Máté
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
dashboard: test destroy VmOperationView
parent
e2a771fd
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
2 deletions
+30
-2
circle/dashboard/tests/test_mockedviews.py
+30
-2
No files found.
circle/dashboard/tests/test_mockedviews.py
View file @
15251ae3
...
@@ -3,10 +3,11 @@ from factory import Factory, Sequence
...
@@ -3,10 +3,11 @@ from factory import Factory, Sequence
from
mock
import
patch
,
MagicMock
from
mock
import
patch
,
MagicMock
from
django.contrib.auth.models
import
User
from
django.contrib.auth.models
import
User
#
from django.core.exceptions import PermissionDenied
from
django.core.exceptions
import
PermissionDenied
from
django.http
import
HttpRequest
,
Http404
from
django.http
import
HttpRequest
,
Http404
from
dashboard.views
import
InstanceActivityDetail
,
InstanceActivity
from
..views
import
InstanceActivityDetail
,
InstanceActivity
from
..views
import
vm_ops
,
Instance
class
ViewUserTestCase
(
unittest
.
TestCase
):
class
ViewUserTestCase
(
unittest
.
TestCase
):
...
@@ -36,6 +37,33 @@ class ViewUserTestCase(unittest.TestCase):
...
@@ -36,6 +37,33 @@ class ViewUserTestCase(unittest.TestCase):
self
.
assertEquals
(
view
(
request
,
pk
=
1234
)
.
render
()
.
status_code
,
200
)
self
.
assertEquals
(
view
(
request
,
pk
=
1234
)
.
render
()
.
status_code
,
200
)
class
VmOperationViewTestCase
(
unittest
.
TestCase
):
def
test_available
(
self
):
request
=
FakeRequestFactory
(
superuser
=
True
)
view
=
vm_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
(
self
):
request
=
FakeRequestFactory
()
view
=
vm_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
FakeRequestFactory
(
*
args
,
**
kwargs
):
def
FakeRequestFactory
(
*
args
,
**
kwargs
):
''' FakeRequestFactory, FakeMessages and FakeRequestContext are good for
''' FakeRequestFactory, FakeMessages and FakeRequestContext are good for
mocking out django views; they are MUCH faster than the Django test client.
mocking out django views; they are MUCH faster than the Django test 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