Skip to content

Commit

Permalink
Expanded test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
Drew J. Sonne committed Jun 25, 2017
1 parent 03eb205 commit 78cfc67
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
2 changes: 2 additions & 0 deletions src/main/python/awslambdahelper/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ def handler(cls, event, context):
:param event: See `Event Attributes
<http://docs.aws.amazon.com/config/latest/developerguide/evaluate-config_develop-rules_example-events.html#w2ab1c13c33c27c15c15>`_
in the AWS Config Developer guide.
:type event: dict
:param context: See `Context Object <http://docs.aws.amazon.com/lambda/latest/dg/python-context-object.html#python-context-object-methods>`_
:type context: dict
:return:
"""
rule = cls(cls.APPLICABLE_RESOURCES)
Expand Down
22 changes: 14 additions & 8 deletions src/unittest/python/configrule_tests.py
Original file line number Diff line number Diff line change
@@ -1,37 +1,31 @@
import unittest
from awslambdahelper import AWSConfigRule
from mock import patch, MagicMock, call

class ConfigRuleTests(unittest.TestCase):

class ConfigRuleTests(unittest.TestCase):
def test_classinstantiation(self):

AWSConfigRule(
applicable_resources=["AWS::EC2::INSTANCE"]
)


def test_configcalltype(self):

rule = AWSConfigRule(
applicable_resources=["AWS::EC2::INSTANCE"]
)
rule.call_type = AWSConfigRule.CALL_TYPE_CONFIGURATION_CHANGE

self.assertTrue(rule.is_config_change_call)


def test_schedulecalltype(self):

rule = AWSConfigRule(
applicable_resources=["AWS::EC2::INSTANCE"]
)
rule.call_type = AWSConfigRule.CALL_TYPE_SCHEDULED

self.assertTrue(rule.is_scheduled_call)


def test_unimplemented_callbacks(self):

rule = AWSConfigRule(
applicable_resources=["AWS::EC2::INSTANCE"]
)
Expand All @@ -41,3 +35,15 @@ def test_unimplemented_callbacks(self):

with self.assertRaises(NotImplementedError):
rule.find_violation_scheduled(rule_parameters=None, accountid=None)

def test_statichandler(self):
class MockHandler(AWSConfigRule):
APPLICABLE_RESOURCES = ['a', 'b']

MockHandler.lambda_handler = MagicMock()

MockHandler.handler({'event': None}, {'context': None})

MockHandler.lambda_handler.assert_called_once_with(
{'event': None}, {'context': None}
)

0 comments on commit 78cfc67

Please sign in to comment.