Skip to content

Commit

Permalink
fix #172 naming conflict from troposphere BaseAWSObject.attributes pr…
Browse files Browse the repository at this point in the history
…eventing "attributes" property name from being used/rendered by packerlicious classes
  • Loading branch information
mayn committed Mar 29, 2019
1 parent 703ebe8 commit 0d031f5
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/thirdparty/troposphere/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def __init__(self, title, template=None, **kwargs):
self.template = template
# Cache the keys for validity checks
self.propnames = list(self.props.keys())
self.attributes = ['DependsOn', 'DeletionPolicy',
self.attributes_ = ['DependsOn', 'DeletionPolicy',
'Metadata', 'UpdatePolicy',
'Condition', 'CreationPolicy']

Expand Down Expand Up @@ -102,7 +102,7 @@ def __init__(self, title, template=None, **kwargs):

def __getattr__(self, name):
try:
if name in self.attributes:
if name in self.attributes_:
return self.resource[name]
else:
return self.properties.__getitem__(name)
Expand All @@ -118,7 +118,7 @@ def __setattr__(self, name, value):
if name in list(self.__dict__.keys()) \
or '_BaseAWSObject__initialized' not in self.__dict__:
return dict.__setattr__(self, name, value)
elif name in self.attributes:
elif name in self.attributes_:
self.resource[name] = value
return None
elif name in self.propnames:
Expand Down
28 changes: 27 additions & 1 deletion tests/packerlicious/test_provisioner_inspec.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import pytest

import packerlicious.provisioner as provisioner
from packerlicious import Template
import json


class TestInspecProvisioner(object):
Expand All @@ -11,3 +12,28 @@ def test_required_fields_missing(self):
with pytest.raises(ValueError) as excinfo:
b.to_dict()
assert 'required' in str(excinfo.value)

def test_property_attributes_renders(self):
expected_json = """
{
"provisioners": [
{
"attributes": ["examples/linux.yml"],
"profile": "a_profile",
"type": "inspec"
}
]
}
"""

t = Template()
p = provisioner.Inspec(
attributes=["examples/linux.yml"],
profile="a_profile"
)

t.add_provisioner(p)

to_json = t.to_json()
assert to_json == json.dumps(json.loads(expected_json), sort_keys=True, indent=2,
separators=(',', ': '))

0 comments on commit 0d031f5

Please sign in to comment.