Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
José Ángel Fentánez
branchesv
Commits
eae43656
Commit
eae43656
authored
Jun 16, 2016
by
José Ángel Fentánez
Browse files
[ADD] branchesv: tests for utils.py
parent
89c970d0
Pipeline
#136
passed with stage
in 2 minutes and 6 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
branchesv/utils.py
View file @
eae43656
...
...
@@ -92,6 +92,16 @@ def name_from_url(url):
return
name
def
copy_list_dicts
(
lines
):
res
=
[]
for
line
in
lines
:
dict_t
=
{}
for
keys
in
line
.
keys
():
dict_t
.
update
({
keys
:
line
[
keys
]})
res
.
append
(
dict_t
.
copy
())
return
res
def
set_message
(
branch
,
str_msg
=
None
):
""" Sets the exit message for GitBranch actions like clone, pull
and update
...
...
tests/test_utils.py
View file @
eae43656
...
...
@@ -5,7 +5,7 @@ import shlex
import
logging
import
simplejson
as
json
from
unittest
import
TestCase
from
branchesv
import
utils
from
branchesv
import
utils
,
branches
logger
=
logging
.
getLogger
(
'deployv'
)
...
...
@@ -14,8 +14,11 @@ class TestUtils(TestCase):
@
classmethod
def
setUpClass
(
cls
):
cls
.
gitbranch
=
branches
.
GitBranch
()
cls
.
shell
=
spur
.
LocalShell
()
os
.
mkdir
(
'branch_test'
)
cls
.
shell
.
run
(
shlex
.
split
(
'git clone https://github.com/Vauxoo/deploy-templates.git'
' test_utils/deploy-templates'
))
cls
.
original_branches
=
cls
.
gitbranch
.
get_branches
(
'test_utils'
)
def
test_10_load_json
(
self
):
res
=
utils
.
load_json
(
'tests/files/branches.json'
)
...
...
@@ -28,8 +31,8 @@ class TestUtils(TestCase):
def
test_20_save_json
(
self
):
content
=
utils
.
load_json
(
'tests/files/branches.json'
)
res
=
utils
.
save_json
(
content
,
'
branch_test
/save_test.json'
)
new_json
=
utils
.
load_json
(
'
branch_test
/save_test.json'
)
res
=
utils
.
save_json
(
content
,
'
test_utils
/save_test.json'
)
new_json
=
utils
.
load_json
(
'
test_utils
/save_test.json'
)
self
.
assertTrue
(
os
.
path
.
exists
(
res
))
self
.
assertEquals
(
content
,
new_json
)
...
...
@@ -37,13 +40,33 @@ class TestUtils(TestCase):
with
self
.
assertRaises
(
IOError
):
res
=
utils
.
save_json
(
'info'
,
'testing/test.json'
)
def
test_90_clean_files
(
self
):
files
=
[
'/'
,
'branch_test/save_test.json'
,
'branch_test/'
]
utils
.
clean_files
(
files
)
self
.
assertFalse
(
os
.
path
.
exists
(
'branch_test/save_test.json'
))
self
.
assertFalse
(
os
.
path
.
exists
(
'branch_test/'
))
self
.
assertTrue
(
os
.
path
.
exists
(
'/'
))
def
test_30_simplify_path
(
self
):
copy_branches
=
utils
.
copy_list_dicts
(
self
.
original_branches
)
res
=
utils
.
simplify_path
(
copy_branches
)
full_path
=
'test_utils/{path}'
.
format
(
path
=
res
[
0
].
get
(
'path'
))
self
.
assertNotEqual
(
res
[
0
].
get
(
'path'
),
self
.
original_branches
[
0
].
get
(
'path'
))
self
.
assertEquals
(
full_path
,
self
.
original_branches
[
0
].
get
(
'path'
))
self
.
assertEquals
(
len
(
res
[
0
].
get
(
'path'
).
split
(
'/'
)),
1
)
def
test_
3
0_name_from_url
(
self
):
def
test_
4
0_name_from_url
(
self
):
res
=
utils
.
name_from_url
(
'https://github.com/odoo/odoo.git'
)
self
.
assertEqual
(
res
,
'odoo'
)
def
test_50_copy_list_dicts
(
self
):
copy
=
utils
.
copy_list_dicts
(
self
.
original_branches
)
self
.
assertEquals
(
copy
,
self
.
original_branches
)
copy
[
0
].
update
({
'name'
:
'new_name'
})
self
.
assertNotEqual
(
copy
,
self
.
original_branches
)
def
test_60_set_message
(
self
):
res_success
=
utils
.
set_message
(
self
.
original_branches
[
0
])
res_fatal
=
utils
.
set_message
(
self
.
original_branches
[
0
],
'fatal: no such branch'
)
self
.
assertEquals
(
res_success
.
get
(
'exit_code'
),
0
)
self
.
assertEquals
(
res_fatal
.
get
(
'exit_code'
),
1
)
def
test_90_clean_files
(
self
):
files
=
[
'/'
,
'test_utils/save_test.json'
,
'test_utils/'
]
utils
.
clean_files
(
files
)
self
.
assertFalse
(
os
.
path
.
exists
(
'test_utils/save_test.json'
))
self
.
assertFalse
(
os
.
path
.
exists
(
'test_utils/'
))
self
.
assertTrue
(
os
.
path
.
exists
(
'/'
))
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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