feat: バッチ実行管理テーブルのユニットテスト実装完了
This commit is contained in:
parent
61ff9f1159
commit
a6b17b0c78
@ -1,4 +1,4 @@
|
|||||||
from datetime import datetime, timedelta, timezone
|
from datetime import UTC, datetime, timedelta
|
||||||
|
|
||||||
import boto3
|
import boto3
|
||||||
|
|
||||||
@ -28,7 +28,7 @@ class JskultBatchRunManager:
|
|||||||
batch_run_status (str): バッチ処理ステータス
|
batch_run_status (str): バッチ処理ステータス
|
||||||
"""
|
"""
|
||||||
# レコードの有効期限を現在時刻+24hのタイムスタンプで生成
|
# レコードの有効期限を現在時刻+24hのタイムスタンプで生成
|
||||||
now = datetime.now(timezone.utc)
|
now = datetime.now(UTC)
|
||||||
later = now + timedelta(hours=24)
|
later = now + timedelta(hours=24)
|
||||||
timestamp_24h = int(later.timestamp())
|
timestamp_24h = int(later.timestamp())
|
||||||
|
|
||||||
|
|||||||
@ -14,12 +14,19 @@ class TestJskultBatchRunManager:
|
|||||||
|
|
||||||
yield dynamodb
|
yield dynamodb
|
||||||
|
|
||||||
dynamodb.delete_item(Key={
|
dynamodb.delete_item(
|
||||||
'execution_id': UNITTEST_EXECUTION_ID
|
TableName=BATCH_MANAGE_DYNAMODB_TABLE_NAME,
|
||||||
})
|
Key={
|
||||||
|
'execution_id': {'S': UNITTEST_EXECUTION_ID}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
def test_batch_success(self, dynamodb_client):
|
def test_batch_success(self, dynamodb_client):
|
||||||
|
"""バッチ実行管理テーブルに成功のステータスが書き込まれること
|
||||||
|
|
||||||
|
Args:
|
||||||
|
dynamodb_client (boto3.Client): DynamoDB クライアント
|
||||||
|
"""
|
||||||
# Arrange
|
# Arrange
|
||||||
# Act
|
# Act
|
||||||
sut = JskultBatchRunManager(BATCH_MANAGE_DYNAMODB_TABLE_NAME, UNITTEST_EXECUTION_ID)
|
sut = JskultBatchRunManager(BATCH_MANAGE_DYNAMODB_TABLE_NAME, UNITTEST_EXECUTION_ID)
|
||||||
@ -34,3 +41,45 @@ class TestJskultBatchRunManager:
|
|||||||
}
|
}
|
||||||
actual = dynamodb_client.get_item(**options)
|
actual = dynamodb_client.get_item(**options)
|
||||||
assert actual['Item']['batch_run_status']['S'] == 'success'
|
assert actual['Item']['batch_run_status']['S'] == 'success'
|
||||||
|
|
||||||
|
def test_batch_failed(self, dynamodb_client):
|
||||||
|
"""バッチ実行管理テーブルに失敗のステータスが書き込まれること
|
||||||
|
|
||||||
|
Args:
|
||||||
|
dynamodb_client (boto3.Client): DynamoDB クライアント
|
||||||
|
"""
|
||||||
|
# Arrange
|
||||||
|
# Act
|
||||||
|
sut = JskultBatchRunManager(BATCH_MANAGE_DYNAMODB_TABLE_NAME, UNITTEST_EXECUTION_ID)
|
||||||
|
sut.batch_failed()
|
||||||
|
|
||||||
|
# Assert
|
||||||
|
options = {
|
||||||
|
'TableName': BATCH_MANAGE_DYNAMODB_TABLE_NAME,
|
||||||
|
'Key': {
|
||||||
|
'execution_id': {'S': UNITTEST_EXECUTION_ID},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
actual = dynamodb_client.get_item(**options)
|
||||||
|
assert actual['Item']['batch_run_status']['S'] == 'failed'
|
||||||
|
|
||||||
|
def test_batch_retry(self, dynamodb_client):
|
||||||
|
"""バッチ実行管理テーブルにリトライのステータスが書き込まれること
|
||||||
|
|
||||||
|
Args:
|
||||||
|
dynamodb_client (boto3.Client): DynamoDB クライアント
|
||||||
|
"""
|
||||||
|
# Arrange
|
||||||
|
# Act
|
||||||
|
sut = JskultBatchRunManager(BATCH_MANAGE_DYNAMODB_TABLE_NAME, UNITTEST_EXECUTION_ID)
|
||||||
|
sut.batch_retry()
|
||||||
|
|
||||||
|
# Assert
|
||||||
|
options = {
|
||||||
|
'TableName': BATCH_MANAGE_DYNAMODB_TABLE_NAME,
|
||||||
|
'Key': {
|
||||||
|
'execution_id': {'S': UNITTEST_EXECUTION_ID},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
actual = dynamodb_client.get_item(**options)
|
||||||
|
assert actual['Item']['batch_run_status']['S'] == 'retry'
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user