Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Gelencsér Szabolcs
/
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
69057f65
authored
Mar 15, 2014
by
Őry Máté
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
vm: add tests
parent
6fde18eb
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
40 additions
and
11 deletions
+40
-11
circle/vm/models/node.py
+3
-2
circle/vm/tests/test_models.py
+37
-9
No files found.
circle/vm/models/node.py
View file @
69057f65
...
@@ -82,12 +82,13 @@ class Node(TimeStampedModel):
...
@@ -82,12 +82,13 @@ class Node(TimeStampedModel):
True
:
{
False
:
(
'MISSING'
,
_
(
'missing'
)),
True
:
{
False
:
(
'MISSING'
,
_
(
'missing'
)),
True
:
(
'ONLINE'
,
_
(
'online'
))}}
True
:
(
'ONLINE'
,
_
(
'online'
))}}
@property
def
get_state
(
self
):
def
state
(
self
):
"""The state combined of online and enabled attributes.
"""The state combined of online and enabled attributes.
"""
"""
return
self
.
STATES
[
self
.
enabled
][
self
.
online
][
0
]
return
self
.
STATES
[
self
.
enabled
][
self
.
online
][
0
]
state
=
property
(
get_state
)
def
get_status_display
(
self
):
def
get_status_display
(
self
):
return
self
.
STATES
[
self
.
enabled
][
self
.
online
][
1
]
return
self
.
STATES
[
self
.
enabled
][
self
.
online
][
1
]
...
...
circle/vm/tests/test_models.py
View file @
69057f65
from
datetime
import
datetime
from
django.test
import
TestCase
from
django.test
import
TestCase
from
mock
import
Mock
from
django.utils.translation
import
ugettext_lazy
as
_
from
mock
import
Mock
,
MagicMock
,
patch
from
..models.common
import
(
from
..models
import
(
Lease
Lease
,
Node
,
Interface
,
Instance
,
InstanceTemplate
,
)
from
..models.instance
import
(
find_unused_port
,
InstanceTemplate
,
Instance
)
from
..models.network
import
(
Interface
)
)
from
..models.instance
import
find_unused_port
class
PortFinderTestCase
(
TestCase
):
class
PortFinderTestCase
(
TestCase
):
...
@@ -39,6 +36,26 @@ class InstanceTestCase(TestCase):
...
@@ -39,6 +36,26 @@ class InstanceTestCase(TestCase):
inst
=
Mock
(
state
=
'RUNNING'
)
inst
=
Mock
(
state
=
'RUNNING'
)
assert
Instance
.
is_running
.
getter
(
inst
)
assert
Instance
.
is_running
.
getter
(
inst
)
def
deploy_destroyed
(
self
):
inst
=
Mock
(
destroyed_at
=
datetime
.
now
())
with
self
.
assertRaises
(
Instance
.
InstanceDestroyedError
):
Instance
.
deploy
(
inst
)
def
destroy_destroyed
(
self
):
inst
=
Mock
(
destroyed_at
=
datetime
.
now
())
Instance
.
destroy
(
inst
)
self
.
assertFalse
(
inst
.
save
.
called
)
def
destroy_sets_destroyed
(
self
):
inst
=
MagicMock
(
destroyed_at
=
None
,
spec
=
Instance
)
inst
.
node
=
MagicMock
(
spec
=
Node
)
inst
.
disks
.
all
.
return_value
=
[]
with
patch
(
'vm.models.instance.instance_activity'
)
as
ia
:
ia
.
return_value
=
MagicMock
()
Instance
.
destroy
(
inst
)
self
.
assertTrue
(
inst
.
destroyed_at
)
inst
.
save
.
assert_called
()
class
InterfaceTestCase
(
TestCase
):
class
InterfaceTestCase
(
TestCase
):
...
@@ -78,3 +95,14 @@ class LeaseTestCase(TestCase):
...
@@ -78,3 +95,14 @@ class LeaseTestCase(TestCase):
l
.
suspend_interval
=
None
l
.
suspend_interval
=
None
assert
"never"
in
unicode
(
l
)
assert
"never"
in
unicode
(
l
)
class
NodeTestCase
(
TestCase
):
def
test_state
(
self
):
node
=
Mock
(
spec
=
Node
)
node
.
online
=
True
node
.
enabled
=
True
node
.
STATES
=
Node
.
STATES
self
.
assertEqual
(
Node
.
get_state
(
node
),
"ONLINE"
)
assert
isinstance
(
Node
.
get_status_display
(
node
),
_
(
""
)
.
__class__
)
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