Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Gutyán Gábor
/
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
64f5b452
authored
Apr 29, 2014
by
Dudás Ádám
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
vm: tests for InstanceActivity
parent
31e48a88
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
48 additions
and
0 deletions
+48
-0
circle/vm/tests/test_models.py
+48
-0
No files found.
circle/vm/tests/test_models.py
View file @
64f5b452
...
@@ -2,6 +2,7 @@ from datetime import datetime
...
@@ -2,6 +2,7 @@ from datetime import datetime
from
mock
import
Mock
,
MagicMock
,
patch
,
call
from
mock
import
Mock
,
MagicMock
,
patch
,
call
import
types
import
types
from
celery.contrib.abortable
import
AbortableAsyncResult
from
django.contrib.auth.models
import
User
from
django.contrib.auth.models
import
User
from
django.test
import
TestCase
from
django.test
import
TestCase
from
django.utils.translation
import
ugettext_lazy
as
_
from
django.utils.translation
import
ugettext_lazy
as
_
...
@@ -214,6 +215,53 @@ class InstanceActivityTestCase(TestCase):
...
@@ -214,6 +215,53 @@ class InstanceActivityTestCase(TestCase):
raise
AssertionError
(
"'create_sub' method checked for "
raise
AssertionError
(
"'create_sub' method checked for "
"concurrent activities."
)
"concurrent activities."
)
def
test_is_abortable
(
self
):
get_op
=
MagicMock
(
return_value
=
MagicMock
(
abortable
=
True
))
instance
=
MagicMock
(
get_operation_from_activity_code
=
get_op
)
iaobj
=
MagicMock
(
spec
=
InstanceActivity
,
activity_code
=
'test'
,
finished
=
False
,
instance
=
instance
,
task_uuid
=
'test'
)
self
.
assertTrue
(
InstanceActivity
.
is_abortable
.
fget
(
iaobj
))
def
test_not_abortable_when_not_associated_with_task
(
self
):
get_op
=
MagicMock
(
return_value
=
MagicMock
(
abortable
=
True
))
instance
=
MagicMock
(
get_operation_from_activity_code
=
get_op
)
iaobj
=
MagicMock
(
spec
=
InstanceActivity
,
activity_code
=
'test'
,
finished
=
False
,
instance
=
instance
,
task_uuid
=
None
)
self
.
assertFalse
(
InstanceActivity
.
is_abortable
.
fget
(
iaobj
))
def
test_not_abortable_when_finished
(
self
):
get_op
=
MagicMock
(
return_value
=
MagicMock
(
abortable
=
True
))
instance
=
MagicMock
(
get_operation_from_activity_code
=
get_op
)
iaobj
=
MagicMock
(
spec
=
InstanceActivity
,
activity_code
=
'test'
,
finished
=
True
,
instance
=
instance
,
task_uuid
=
'test'
)
self
.
assertFalse
(
InstanceActivity
.
is_abortable
.
fget
(
iaobj
))
def
test_not_abortable_when_operation_not_abortable
(
self
):
get_op
=
MagicMock
(
return_value
=
MagicMock
(
abortable
=
False
))
instance
=
MagicMock
(
get_operation_from_activity_code
=
get_op
)
iaobj
=
MagicMock
(
spec
=
InstanceActivity
,
activity_code
=
'test'
,
finished
=
False
,
instance
=
instance
,
task_uuid
=
'test'
)
self
.
assertFalse
(
InstanceActivity
.
is_abortable
.
fget
(
iaobj
))
def
test_not_abortable_when_no_matching_operation
(
self
):
get_op
=
MagicMock
(
return_value
=
None
)
instance
=
MagicMock
(
get_operation_from_activity_code
=
get_op
)
iaobj
=
MagicMock
(
spec
=
InstanceActivity
,
activity_code
=
'test'
,
finished
=
False
,
instance
=
instance
,
task_uuid
=
'test'
)
self
.
assertFalse
(
InstanceActivity
.
is_abortable
.
fget
(
iaobj
))
def
test_not_aborted_when_not_associated_with_task
(
self
):
iaobj
=
MagicMock
(
task_uuid
=
None
)
self
.
assertFalse
(
InstanceActivity
.
is_aborted
.
fget
(
iaobj
))
def
test_is_aborted_when_associated_task_is_aborted
(
self
):
expected
=
object
()
iaobj
=
MagicMock
(
task_uuid
=
'test'
)
with
patch
.
object
(
AbortableAsyncResult
,
'is_aborted'
,
return_value
=
expected
):
self
.
assertEquals
(
expected
,
InstanceActivity
.
is_aborted
.
fget
(
iaobj
))
def
test_disable_enabled
(
self
):
def
test_disable_enabled
(
self
):
node
=
MagicMock
(
spec
=
Node
,
enabled
=
True
)
node
=
MagicMock
(
spec
=
Node
,
enabled
=
True
)
with
patch
(
'vm.models.node.node_activity'
)
as
nac
:
with
patch
(
'vm.models.node.node_activity'
)
as
nac
:
...
...
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