-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9011f9b
commit 00bf81c
Showing
8 changed files
with
116 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import json | ||
|
||
import boto3 | ||
|
||
from logger import logger | ||
|
||
|
||
class States: | ||
def __init__(self, boto3_session=None): | ||
self.boto3_session = boto3_session or boto3.Session() | ||
self.client = self.boto3_session.client('stepfunctions') | ||
|
||
def fail(self, task_token, error, cause): | ||
params = dict(taskToken=task_token, error=error, cause=cause) | ||
logger.info('SEND TASK FAILURE %s', json.dumps(params)) | ||
return self.client.send_task_failure(**params) | ||
|
||
def heartbeat(self, task_token): | ||
params = dict(taskToken=task_token) | ||
logger.info('SEND TASK HEARTBEAT %s', json.dumps(params)) | ||
return self.client.send_task_heartbeat(**params) | ||
|
||
def succeed(self, task_token, output): | ||
params = dict(taskToken=task_token, output=output) | ||
logger.info('SEND TASK SUCCESS %s', json.dumps(params)) | ||
return self.client.send_task_success(**params) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
from unittest.mock import MagicMock | ||
|
||
from src.states import States | ||
|
||
|
||
class TestStates: | ||
def setup(self): | ||
self.boto3_session = MagicMock() | ||
self.subject = States(boto3_session=self.boto3_session) | ||
|
||
def test_fail(self): | ||
self.subject.fail('<token>', 'error', '{}') | ||
self.subject.client.send_task_failure.assert_called_once_with( | ||
taskToken='<token>', | ||
error='error', | ||
cause='{}', | ||
) | ||
|
||
def test_heartbeat(self): | ||
self.subject.heartbeat('<token>') | ||
self.subject.client.send_task_heartbeat.assert_called_once_with( | ||
taskToken='<token>', | ||
) | ||
|
||
def test_succeed(self): | ||
self.subject.succeed('<token>', {'fizz': 'buzz'}) | ||
self.subject.client.send_task_success.assert_called_once_with( | ||
taskToken='<token>', | ||
output={'fizz': 'buzz'}, | ||
) |