Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
RECIRCLE
/
interface-openstack
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
2
Merge Requests
4
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
ee5a9df0
authored
Aug 02, 2019
by
Chif Gergő
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add basic tests
parent
b5a40679
Pipeline
#803
failed with stage
in 39 seconds
Changes
2
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
69 additions
and
1 deletions
+69
-1
.gitlab-ci.yml
+1
-0
test/interface/test_vm.py
+68
-1
No files found.
.gitlab-ci.yml
View file @
ee5a9df0
...
...
@@ -2,4 +2,5 @@ unittest:
image
:
python:3.7.3
script
:
-
pip install -r requirements.txt
-
cd ..
-
python -m unittest discover
test/interface/test_vm.py
View file @
ee5a9df0
...
...
@@ -33,10 +33,24 @@ fake_auth = {
class
InstanceCreateTestCase
(
unittest
.
TestCase
):
'''
Test openstack methods called with the right values or exceptions raised.
Signature of tests:
def test_my_feature_with(self):
# Mock
--- mocking openstack compute API ---
# Execute
--- execute the tested method ---
# Assert
--- check values, exceptions, calls etc. ---
'''
@patch
(
'openstack.connect'
)
def
setUp
(
self
,
mock_connect
):
self
.
compute
=
MagicMock
()
self
.
compute
.
get_server
=
MagicMock
(
return_value
=
servers
[
0
])
mock_connect
()
.
compute
=
self
.
compute
self
.
manager
=
OSVirtualMachineManager
(
auth
=
fake_auth
)
...
...
@@ -77,4 +91,57 @@ class InstanceCreateTestCase(unittest.TestCase):
)
def
test_suspend
(
self
):
self
.
manager
.
openstack
.
compute
.
suspend_server
()
# Mock
self
.
compute
.
suspend_server
=
MagicMock
(
return_value
=
True
)
# Execute
self
.
manager
.
suspend_vm
(
"test1"
)
# Assert
self
.
compute
.
get_server
.
assert_called
()
self
.
compute
.
suspend_server
.
assert_called_once
()
def
test_start
(
self
):
# Mock
self
.
compute
.
start_server
=
MagicMock
(
return_value
=
True
)
# Execute
self
.
manager
.
start_vm
(
"test1"
)
# Assert
self
.
compute
.
get_server
.
assert_called
()
self
.
compute
.
start_server
.
assert_called_once
()
def
test_stop
(
self
):
# Mock
self
.
compute
.
stop_server
=
MagicMock
(
return_value
=
True
)
# Execute
self
.
manager
.
stop_vm
(
"test1"
)
# Assert
self
.
compute
.
get_server
.
assert_called
()
self
.
compute
.
stop_server
.
assert_called_once
()
def
test_wake_up
(
self
):
# Mock
self
.
compute
.
resume_server
=
MagicMock
(
return_value
=
True
)
# Execute
self
.
manager
.
wake_up_vm
(
"test1"
)
# Assert
self
.
compute
.
get_server
.
assert_called
()
self
.
compute
.
resume_server
.
assert_called_once
()
def
test_reboot
(
self
):
# Mock
self
.
compute
.
reboot_server
=
MagicMock
(
return_value
=
True
)
# Execute
self
.
manager
.
reboot_vm
(
"test1"
)
# Assert
self
.
compute
.
get_server
.
assert_called
()
self
.
compute
.
reboot_server
.
assert_called_once
()
self
.
compute
.
reboot_server
.
assert_called_with
(
servers
[
0
],
reboot_type
=
"SOFT"
)
def
test_reset
(
self
):
# Mock
self
.
compute
.
reboot_server
=
MagicMock
(
return_value
=
True
)
# Execute
self
.
manager
.
reset_vm
(
"test1"
)
# Assert
self
.
compute
.
get_server
.
assert_called
()
self
.
compute
.
reboot_server
.
assert_called_once
()
self
.
compute
.
reboot_server
.
assert_called_with
(
servers
[
0
],
reboot_type
=
"HARD"
)
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