Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
ansible
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenEdx
ansible
Commits
349ecf6e
Commit
349ecf6e
authored
Apr 03, 2015
by
Toshio Kuratomi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add a vault test to data_loader test and some additional yaml tests to parsing/yaml/test_loader
parent
c5fdabdb
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
64 additions
and
1 deletions
+64
-1
v2/test/parsing/test_data_loader.py
+21
-1
v2/test/parsing/yaml/test_loader.py
+43
-0
No files found.
v2/test/parsing/test_data_loader.py
View file @
349ecf6e
...
...
@@ -22,7 +22,7 @@ __metaclass__ = type
from
yaml.scanner
import
ScannerError
from
ansible.compat.tests
import
unittest
from
ansible.compat.tests.mock
import
patch
from
ansible.compat.tests.mock
import
patch
,
mock_open
from
ansible.errors
import
AnsibleParserError
from
ansible.parsing
import
DataLoader
...
...
@@ -62,3 +62,23 @@ class TestDataLoader(unittest.TestCase):
"""
,
True
)
self
.
assertRaises
(
AnsibleParserError
,
self
.
_loader
.
load_from_file
,
'dummy_yaml_bad.txt'
)
class
TestDataLoaderWithVault
(
unittest
.
TestCase
):
def
setUp
(
self
):
self
.
_loader
=
DataLoader
(
vault_password
=
'ansible'
)
def
tearDown
(
self
):
pass
@patch.multiple
(
DataLoader
,
path_exists
=
lambda
s
,
x
:
True
,
is_file
=
lambda
s
,
x
:
True
)
def
test_parse_from_vault_1_1_file
(
self
):
vaulted_data
=
"""$ANSIBLE_VAULT;1.1;AES256
33343734386261666161626433386662623039356366656637303939306563376130623138626165
6436333766346533353463636566313332623130383662340a393835656134633665333861393331
37666233346464636263636530626332623035633135363732623332313534306438393366323966
3135306561356164310a343937653834643433343734653137383339323330626437313562306630
3035
"""
with
patch
(
'__builtin__.open'
,
mock_open
(
read_data
=
vaulted_data
)):
output
=
self
.
_loader
.
load_from_file
(
'dummy_vault.txt'
)
self
.
assertEqual
(
output
,
dict
(
foo
=
'bar'
))
v2/test/parsing/yaml/test_loader.py
View file @
349ecf6e
...
...
@@ -101,6 +101,49 @@ class TestAnsibleLoaderBasic(unittest.TestCase):
self
.
assertEqual
(
data
[
0
]
.
ansible_pos
,
(
'myfile.yml'
,
2
,
19
))
self
.
assertEqual
(
data
[
1
]
.
ansible_pos
,
(
'myfile.yml'
,
3
,
19
))
def
test_parse_short_dict
(
self
):
stream
=
StringIO
(
"""{"foo": "bar"}"""
)
loader
=
AnsibleLoader
(
stream
,
'myfile.yml'
)
data
=
loader
.
get_single_data
()
self
.
assertEqual
(
data
,
dict
(
foo
=
u'bar'
))
self
.
assertEqual
(
data
.
ansible_pos
,
(
'myfile.yml'
,
1
,
1
))
self
.
assertEqual
(
data
[
u'foo'
]
.
ansible_pos
,
(
'myfile.yml'
,
1
,
9
))
stream
=
StringIO
(
"""foo: bar"""
)
loader
=
AnsibleLoader
(
stream
,
'myfile.yml'
)
data
=
loader
.
get_single_data
()
self
.
assertEqual
(
data
,
dict
(
foo
=
u'bar'
))
self
.
assertEqual
(
data
.
ansible_pos
,
(
'myfile.yml'
,
1
,
1
))
self
.
assertEqual
(
data
[
u'foo'
]
.
ansible_pos
,
(
'myfile.yml'
,
1
,
6
))
def
test_error_conditions
(
self
):
stream
=
StringIO
(
"""{"""
)
loader
=
AnsibleLoader
(
stream
,
'myfile.yml'
)
self
.
assertRaises
(
loader
.
get_single_data
)
def
test_front_matter
(
self
):
stream
=
StringIO
(
"""---
\n
foo: bar"""
)
loader
=
AnsibleLoader
(
stream
,
'myfile.yml'
)
data
=
loader
.
get_single_data
()
self
.
assertEqual
(
data
,
dict
(
foo
=
u'bar'
))
self
.
assertEqual
(
data
.
ansible_pos
,
(
'myfile.yml'
,
2
,
1
))
self
.
assertEqual
(
data
[
u'foo'
]
.
ansible_pos
,
(
'myfile.yml'
,
2
,
6
))
# Initial indent (See: #6348)
stream
=
StringIO
(
""" - foo: bar
\n
baz: qux"""
)
loader
=
AnsibleLoader
(
stream
,
'myfile.yml'
)
data
=
loader
.
get_single_data
()
self
.
assertEqual
(
data
,
[{
u'foo'
:
u'bar'
,
u'baz'
:
u'qux'
}])
self
.
assertEqual
(
data
.
ansible_pos
,
(
'myfile.yml'
,
1
,
2
))
self
.
assertEqual
(
data
[
0
]
.
ansible_pos
,
(
'myfile.yml'
,
1
,
4
))
self
.
assertEqual
(
data
[
0
][
u'foo'
]
.
ansible_pos
,
(
'myfile.yml'
,
1
,
9
))
self
.
assertEqual
(
data
[
0
][
u'baz'
]
.
ansible_pos
,
(
'myfile.yml'
,
2
,
9
))
class
TestAnsibleLoaderPlay
(
unittest
.
TestCase
):
def
setUp
(
self
):
...
...
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