Skip to content

Commit

Permalink
Fix bug where FilterGroups were required, when technically they are n…
Browse files Browse the repository at this point in the history
…ot (#1424)

Fixes a bug introduced here #1372

Basically while FilterGroups aren't required, the validate() function
was effectively making them required.  This makes it so validate only
validates FilterGroups if they're actually set.
  • Loading branch information
phobologic authored and markpeek committed Jun 12, 2019
1 parent 86435bf commit cd0d621
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 17 deletions.
6 changes: 3 additions & 3 deletions tests/test_codebuild.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ def test_filter(self):
]).validate()

def test_filter_no_filtergroup(self):
match = "'FilterGroups is required when creating triggers'"
with self.assertRaisesRegexp(KeyError, match):
codebuild.ProjectTriggers().validate()
codebuild.ProjectTriggers(Webhook=True).validate()
# Technically this is valid, not sure why you would want this though?
codebuild.ProjectTriggers().validate()

def test_filter_not_list(self):
match = "<type 'int'>, expected <type 'list'>"
Expand Down
32 changes: 18 additions & 14 deletions troposphere/codebuild.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,22 +241,26 @@ class ProjectTriggers(AWSProperty):
}

def validate(self):
if 'FilterGroups' not in self.properties:
raise KeyError('FilterGroups is required when creating triggers')
if not isinstance(self.FilterGroups, list):
self._raise_type('FilterGroups', self.FilterGroups, list)
for counti, elem in enumerate(self.properties.get('FilterGroups')):
if not isinstance(elem, list):
self._raise_type(
'FilterGroups[{}]'.format(counti),
self.FilterGroups[counti], list
)
for countj, hook in enumerate(self.FilterGroups[counti]):
if not isinstance(hook, WebhookFilter):
""" FilterGroups, if set, needs to be a list of a list of
WebhookFilters
"""
filter_groups = self.properties.get('FilterGroups')
if filter_groups is not None:
if not isinstance(filter_groups, list):
self._raise_type('FilterGroups', filter_groups, list)

for counti, elem in enumerate(filter_groups):
if not isinstance(elem, list):
self._raise_type(
'FilterGroups[{}][{}]'.format(counti, countj),
hook, WebhookFilter
'FilterGroups[{}]'.format(counti),
filter_groups[counti], list
)
for countj, hook in enumerate(filter_groups[counti]):
if not isinstance(hook, WebhookFilter):
self._raise_type(
'FilterGroups[{}][{}]'.format(counti, countj),
hook, WebhookFilter
)


def validate_status(status):
Expand Down

0 comments on commit cd0d621

Please sign in to comment.