Skip to content

Commit

Permalink
100% coverage, simplify deployment models
Browse files Browse the repository at this point in the history
  • Loading branch information
kapilt committed Jun 4, 2019
1 parent 87080f0 commit 52b993f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 28 deletions.
3 changes: 3 additions & 0 deletions chalice/awsclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -717,6 +717,9 @@ def get_or_create_rule_arn(
params['ScheduleExpression'] = schedule_expression
elif event_pattern:
params['EventPattern'] = event_pattern
else:
raise ValueError(
"schedule_expression or event_pattern required")
rule_arn = events.put_rule(**params)
return rule_arn['RuleArn']

Expand Down
40 changes: 12 additions & 28 deletions chalice/deploy/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,7 @@ def dependencies(self):


@attrs
class CloudWatchEvent(ManagedModel):
resource_type = 'cw_event'
rule_name = attrib() # type: str
event_pattern = attrib() # type: str
class FunctionEventSubscriber(ManagedModel):
lambda_function = attrib() # type: LambdaFunction

def dependencies(self):
Expand All @@ -177,15 +174,17 @@ def dependencies(self):


@attrs
class ScheduledEvent(ManagedModel):
class CloudWatchEvent(FunctionEventSubscriber):
resource_type = 'cw_event'
rule_name = attrib() # type: str
event_pattern = attrib() # type: str


@attrs
class ScheduledEvent(FunctionEventSubscriber):
resource_type = 'scheduled_event'
rule_name = attrib() # type: str
schedule_expression = attrib() # type: str
lambda_function = attrib() # type: LambdaFunction

def dependencies(self):
# type: () -> List[Model]
return [self.lambda_function]


@attrs
Expand All @@ -202,37 +201,22 @@ def dependencies(self):


@attrs
class S3BucketNotification(ManagedModel):
class S3BucketNotification(FunctionEventSubscriber):
resource_type = 's3_event'
bucket = attrib() # type: str
events = attrib() # type: List[str]
prefix = attrib() # type: Optional[str]
suffix = attrib() # type: Optional[str]
lambda_function = attrib() # type: LambdaFunction

def dependencies(self):
# type: () -> List[Model]
return [self.lambda_function]


@attrs
class SNSLambdaSubscription(ManagedModel):
class SNSLambdaSubscription(FunctionEventSubscriber):
resource_type = 'sns_event'
topic = attrib() # type: str
lambda_function = attrib() # type: LambdaFunction

def dependencies(self):
# type: () -> List[Model]
return [self.lambda_function]


@attrs
class SQSEventSource(ManagedModel):
class SQSEventSource(FunctionEventSubscriber):
resource_type = 'sqs_event'
queue = attrib() # type: str
batch_size = attrib() # type: int
lambda_function = attrib() # type: LambdaFunction

def dependencies(self):
# type: () -> List[Model]
return [self.lambda_function]
6 changes: 6 additions & 0 deletions tests/functional/test_awsclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,12 @@ def test_can_iterate_logs(stubbed_session):
stubbed_session.verify_stubs()


def test_rule_arn_requires_expression_or_pattern(stubbed_session):
client = TypedAWSClient(stubbed_session)
with pytest.raises(ValueError):
client.get_or_create_rule_arn("foo")


class TestLambdaFunctionExists(object):

def test_can_query_lambda_function_exists(self, stubbed_session):
Expand Down

0 comments on commit 52b993f

Please sign in to comment.