Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
slapos.toolbox
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Eric Zheng
slapos.toolbox
Commits
958f77c3
Commit
958f77c3
authored
Aug 09, 2016
by
Nicolas Wavrant
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
test / runner: tests getCurrentSoftwareReleaseProfile by introducing mocks
parent
5b34159b
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
36 additions
and
0 deletions
+36
-0
setup.py
setup.py
+3
-0
slapos/test/test_runner.py
slapos/test/test_runner.py
+33
-0
No files found.
setup.py
View file @
958f77c3
...
@@ -56,6 +56,9 @@ setup(name=name,
...
@@ -56,6 +56,9 @@ setup(name=name,
'networkbench'
:
[
'pycurl'
],
'networkbench'
:
[
'pycurl'
],
'check_web_page_http_cache_hit'
:
[
'pycurl'
],
# needed for check_web_page_http_cache_hit module
'check_web_page_http_cache_hit'
:
[
'pycurl'
],
# needed for check_web_page_http_cache_hit module
},
},
tests_require
=
[
'mock'
,
],
zip_safe
=
False
,
# proxy depends on Flask, which has issues with
zip_safe
=
False
,
# proxy depends on Flask, which has issues with
# accessing templates
# accessing templates
entry_points
=
{
entry_points
=
{
...
...
slapos/test/test_runner.py
View file @
958f77c3
import
mock
import
os
import
os
import
string
import
string
import
random
import
random
...
@@ -35,6 +36,38 @@ class TestRunner(unittest.TestCase):
...
@@ -35,6 +36,38 @@ class TestRunner(unittest.TestCase):
runner_utils
.
updateUserCredential
(
config
,
login
,
new_password
)
runner_utils
.
updateUserCredential
(
config
,
login
,
new_password
)
self
.
assertTrue
(
runner_utils
.
checkUserCredential
(
config
,
login
,
new_password
))
self
.
assertTrue
(
runner_utils
.
checkUserCredential
(
config
,
login
,
new_password
))
@
mock
.
patch
(
'slapos.runner.utils.open'
)
@
mock
.
patch
(
'os.path.exists'
)
def
test_getCurrentSoftwareReleaseProfile
(
self
,
mock_path_exists
,
mock_open
):
"""
* Mock a .project file
* Tests that getCurrentSoftwareReleaseProfile returns an absolute path
"""
cwd
=
os
.
getcwd
()
# If .project file doesn't exist, then getCurrentSoftwareReleaseProfile
# returns an empty string
config
=
{
'etc_dir'
:
os
.
path
.
join
(
cwd
,
'etc'
),
'workspace'
:
os
.
path
.
join
(
cwd
,
'srv'
,
'runner'
),
'software_profile'
:
'software.cfg'
}
profile
=
runner_utils
.
getCurrentSoftwareReleaseProfile
(
config
)
self
.
assertEqual
(
profile
,
""
)
# If .project points to a SR that doesn't exist, returns empty string
mock_open
.
return_value
.
read
.
return_value
=
"workspace/fake/path/"
mock_path_exists
.
return_value
=
False
profile
=
runner_utils
.
getCurrentSoftwareReleaseProfile
(
config
)
self
.
assertEqual
(
profile
,
""
)
# If software_profile exists, getCurrentSoftwareReleaseProfile should
# return its absolute path
mock_open
.
return_value
.
read
.
return_value
=
"workspace/project/software/"
mock_path_exists
.
return_value
=
True
profile
=
runner_utils
.
getCurrentSoftwareReleaseProfile
(
config
)
self
.
assertEqual
(
profile
,
os
.
path
.
join
(
config
[
'workspace'
],
'project'
,
'software'
,
config
[
'software_profile'
]))
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
random
.
seed
()
random
.
seed
()
unittest
.
main
()
unittest
.
main
()
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