Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
CIRCLE
/
cloud
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
94
Merge Requests
10
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
8c1e37eb
authored
Sep 23, 2014
by
Őry Máté
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
vm: fix tests
parent
1c990ba8
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
39 deletions
+14
-39
circle/vm/tests/test_models.py
+14
-39
No files found.
circle/vm/tests/test_models.py
View file @
8c1e37eb
...
...
@@ -351,51 +351,30 @@ class InstanceActivityTestCase(TestCase):
self
.
assertTrue
(
InstanceActivity
.
is_abortable_for
(
iaobj
,
su
))
def
test_disable_enabled
(
self
):
node
=
MagicMock
(
spec
=
Node
,
enabled
=
True
)
with
patch
(
'vm.models.node.node_activity'
)
as
nac
:
na
=
MagicMock
()
nac
.
return_value
=
na
na
.
__enter__
.
return_value
=
MagicMock
()
Node
.
disable
(
node
)
self
.
assertFalse
(
node
.
enabled
)
node
.
save
.
assert_called_once
()
na
.
assert_called
()
node
=
MagicMock
(
spec
=
Node
,
enabled
=
True
,
online
=
True
)
node
.
instance_set
.
exists
.
return_value
=
False
Node
.
_ops
[
'disable'
](
node
)
.
check_precond
()
def
test_disable_disabled
(
self
):
node
=
MagicMock
(
spec
=
Node
,
enabled
=
False
)
with
patch
(
'vm.models.node.node_activity'
)
as
nac
:
na
=
MagicMock
()
na
.
__enter__
.
side_effect
=
AssertionError
nac
.
return_value
=
na
Node
.
disable
(
node
)
self
.
assertFalse
(
node
.
enabled
)
def
test_disable_enabled_sub
(
self
):
node
=
MagicMock
(
spec
=
Node
,
enabled
=
True
)
act
=
MagicMock
()
subact
=
MagicMock
()
act
.
sub_activity
.
return_value
=
subact
Node
.
disable
(
node
,
base_activity
=
act
)
self
.
assertFalse
(
node
.
enabled
)
subact
.
__enter__
.
assert_called
()
with
self
.
assertRaises
(
Exception
):
Node
.
_ops
[
'disable'
](
node
)
.
check_precond
()
def
test_flush
(
self
):
insts
=
[
MagicMock
(
spec
=
Instance
,
migrate
=
MagicMock
()),
MagicMock
(
spec
=
Instance
,
migrate
=
MagicMock
())]
insts
[
0
]
.
name
=
insts
[
1
]
.
name
=
"x"
node
=
MagicMock
(
spec
=
Node
,
enabled
=
True
)
node
=
MagicMock
(
spec
=
Node
,
enabled
=
True
,
schedule_enabled
=
True
)
node
.
instance_set
.
all
.
return_value
=
insts
user
=
MagicMock
(
spec
=
User
)
user
.
is_superuser
=
MagicMock
(
return_value
=
True
)
flush_op
=
FlushOperation
(
node
)
with
patch
.
object
(
FlushOperation
,
'create_activity'
)
as
create_act
:
act
=
create_act
.
return_value
=
MagicMock
()
flush_op
(
user
=
user
)
with
patch
.
object
(
FlushOperation
,
'create_activity'
)
as
create_act
,
\
patch
.
object
(
Node
.
_ops
[
'passivate'
],
'create_activity'
)
as
create_act2
:
FlushOperation
(
node
)(
user
=
user
)
node
.
schedule_enabled
=
True
create_act
.
assert_called
()
node
.
disable
.
assert_called_with
(
user
,
act
)
create_act2
.
assert_called
(
)
for
i
in
insts
:
i
.
migrate
.
assert_called
()
user
.
is_superuser
.
assert_called
()
...
...
@@ -404,17 +383,13 @@ class InstanceActivityTestCase(TestCase):
insts
=
[
MagicMock
(
spec
=
Instance
,
migrate
=
MagicMock
()),
MagicMock
(
spec
=
Instance
,
migrate
=
MagicMock
())]
insts
[
0
]
.
name
=
insts
[
1
]
.
name
=
"x"
node
=
MagicMock
(
spec
=
Node
,
enabled
=
False
)
node
=
MagicMock
(
spec
=
Node
,
enabled
=
False
,
schedule_enabled
=
False
)
node
.
instance_set
.
all
.
return_value
=
insts
flush_op
=
FlushOperation
(
node
)
with
patch
.
object
(
FlushOperation
,
'create_activity'
)
as
create_act
:
act
=
create_act
.
return_value
=
MagicMock
()
create_act
.
return_value
=
MagicMock
()
flush_op
(
system
=
True
)
create_act
.
assert_called
()
node
.
disable
.
assert_called_with
(
None
,
act
)
# ^ should be called, but real method no-ops if disabled
for
i
in
insts
:
i
.
migrate
.
assert_called
()
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